Closed dazza-codes closed 5 years ago
Related issue on rubocop - https://github.com/bbatsov/rubocop/issues/3409
.editorconfig
to a .rubocop.yml
fileRelated style guide project
Related style formatter that works with editorconfig for javascript
Most of the .editorconfig files seem to contain a very limited set of properties, that may not support all of the features that are checked by rubocop. Looking at some examples for ruby projects, I've got the following:
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# http://editorconfig.org/
root = true
[*]
# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.rb]
# Change these settings to your own preference
indent_style = space
indent_size = 2
[*.md]
trim_trailing_whitespace = false
Note, for example, that this doesn't get specific about subsections of a ruby file; we want the private
or protected
sections of a ruby file to have methods indented by 4 spaces.
I also want it to specify style for indentations on blocks of code and how wrapping occurs for multi-line hashes, arrays, class initialization, etc. For example, RubyMine formatter creates this:
FactoryGirl.create(:author_identity,
author: author
)
But rubocop wants this (fortunately rubocop -a
can fix this, but not while I'm coding it):
FactoryGirl.create(:author_identity,
author: author
)
The purpose of this issue is to identify a way that we can auto-format code in our IDEs so that it's consistent with rubocop style checks. The question is, how do we translate the rubop style settings from the
dlss_baseline.yml
into an.editorconfig
file?Rubocop is a style checker that enforces style after the fact. It does not facilitate the creation or autoformatting of consistent code in an IDE. There are some rubocop plugins that enable warnings in IDEs that code is inconsistent with rubocop, but they have to constantly run rubocop in the background to check code (performance hit). Some IDEs do not provide enough configuration options to support developing code in a style that is consistent with rubocop settings. This is where http://editorconfig.org/ comes in. It can help to configure an IDE in a way that auto-formats code in a consistent way, across IDEs.
Initial suggestion from slack...
@mjgiarlo - investigating a possible connection, if any, between rubocop ruby style stuff and http://editorconfig.org/
.editorconfig
file that the RubyMine-EditorConfig plugin can read. Then, presto, my IDE auto-formatting will conform to rubocop settings and I won’t always have to think about it or always check and correct withrubocop -a
.Curious to see if there is a way to create an .editorconfig that is consistent with https://github.com/sul-dlss/dlss_cops - would be great if rubocop can auto-gen an .editorconfig file, but manual creation might not be too tedious.