EditorConfig
EditorConfig helps maintain consistent coding styles for multiple developers working on the same project across various editors and IDEs.
Used 140 times
V
Viktor Schmidt
Usage
Docs: https://editorconfig.org and https://github.com/editorconfig/editorconfig/wiki/EditorConfig-Properties.
In VS Code you can add vertical rulers in `settings.json` by adding:
In VS Code you can add vertical rulers in `settings.json` by adding:
"editor.rulers": [ {"column": 120, "color": "#5a5a5a"}, // Code {"column": 80, "color": "#5a5a5a"} // CHANGELOG ]
Run this command in your Rails app directory in the terminal:
rails app:template LOCATION="https://railsbytes.com/script/V2Gsv6"
Template Source
Review the code before running this template on your machine.
def print_green(heredoc)
puts set_color heredoc, :green
end
def do_commit
git :init
git add: "."
Bundler.with_unbundled_env { git commit: " -m 'Add EditorConfig to maintain consistent coding styles' " }
end
say "\nApplying EditorConfig to maintain consistent coding styles..."
create_file ".editorconfig" do
<<~EOF
# Editor Config
# You might need a plugin for your editor: https://editorconfig.org/#download
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
max_line_length = 120
[*.{rb,rake,gemspec,yml,yaml,feature,js,js.erb,css,html}]
indent_style = space
indent_size = 2
[*.{erb,slim,coffee,jbuilder,css,sass,scss,html}]
indent_style = space
indent_size = 2
[*.{tf,tf.json,tfvars}]
indent_style = space
indent_size = 2
# JSON files
[*.json]
indent_style = space
indent_size = 2
# Docker files
[Dockerfile]
indent_style = space
indent_size = 2
# Ensure Makefile uses tabs, as required
[Makefile]
indent_style = tab
# XML
[*.xml]
indent_style = space
indent_size = 2
# Markdown files (Markdown does not strictly require line wrapping, but it's often considered good practice)
[*.md]
indent_style = space
indent_size = 2
max_line_length = off
trim_trailing_whitespace = false
EOF
end
say "\nAdding documentation for developers..."
create_file "docs/quality_assurance.md", "# Source code quality assurance and best praxis\n" unless File.exist? "docs/quality_assurance.md"
append_file "docs/quality_assurance.md" do
<<~EOF
## EditorConfig
[EditorConfig](https://editorconfig.org) helps maintain consistent coding styles for multiple developers working on the
same project across various editors and IDEs.
Also check out Microsoft Visual Studio Code Extension:
[EditorConfig for VS Code](https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig)
In VS Code you can add vertical rulers in `settings.json` by adding:
```json
"editor.rulers": [
{"column": 120, "color": "#5a5a5a"}, // Code
{"column": 80, "color": "#5a5a5a"} // CHANGELOG
]
```
EOF
end
do_commit
print_green "\nAdded EditorConfig successfully!"
Comments
Viktor Schmidt
See https://marketplace.visualstudio.com/items?itemName=Shopify.ruby-extensions-pack and https://railsbytes.com/public/templates/x9QsmG