-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sensible configuration for rubocop #560
Conversation
This comment was marked as off-topic.
This comment was marked as off-topic.
This is now ready for review. I added a Style Guide Page in the wiki. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments.
Thanks for the Wiki entry. I changed the link there to point to the webpage that shows the rendered markdown files (and not just the GitHub Markdown which does not support many things they are using, e.g. colors for headers, nice code formatting and so on).
.rubocop.yml
Outdated
Layout/LineLength: | ||
Max: 80 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of course, this limit is highly controversial.
I strongly recommend 80
characters as a soft limit and we should include that in our style guide, e.g. in the Wiki. In VSCode you can also display a grey border at 80 chars.
However, in my past dev experience, I remember lines that were slightly longer than 80 chars and I was really upset that a linter forced me to break a statement to two lines. Sometimes this can actually make a statement less readable (given that the line was just a bit above 80 chars and not something like 120 chars or even more).
This is probably why they even got rid of the 80-column warning in the Linux kernel here. Instead, they raised the limit to 100
chars which I think is more reasonable as a hard limit.
For a future PR that aims to align all Ruby files in our entire codebase (715 Ruby files) to the new RuboCop style guides, this could be a very useful comment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about Style/ClassMethodsDefinitions
, do we really want that?
It will enforce this affecting us 132 times in our codebase. I'd rather go with EnforcedStyle: def_self
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree and done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also updated the wiki page correspondingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok thanks. I wonder: if we add more custom things to the .rubocop.yml
file, maybe it's a bit tedious to keep it synced with the Wiki? Except for the link to the style guide, I do not see the benefit of listing every change we make in the Wiki.
One could just open the .rubocop.yml
file (maybe link to that in the Wiki?) or even run rubocop on the local code changes to directly see where one violates our styles. In the best case, the plugin for VSCode also adds blue squiggly lines to indicate style violations. In my setup, it even autocorrects these (if the autocorrections are safe) whenever I save the file.
If you argue that the Wiki is a place where we could add additional comments for why we chose to do something, we could also have that in the Details
section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shopify also sets CountKeywordArgs
to false
which enforces this behavior. I prefer to set it to true
as is the RuboCop default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shopify disabled Lint/UnreachableLoop. I vote for having it enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/CaseLikeIf
is disabled in Shopify. What do you think about adding a Severity: refactor
to it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's your opinion on Style/GuardClause
which is disabled in Shopify. I don't have a strong opinion on this but remember you once suggested to use unless
, so you probably want it enabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I strongly vote to enable the Style/DoubleNegation
cop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of disabling Style/EmptyMethod
, we should enforce our preferred style, which is EnforcedStyle: expanded
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I strongly suggest enabling Style/NegatedUnless
, otherwise you have to write down your own truth table to find out when the if
statement is true
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I strongly suggest enabling Style/NegatedIfElseCondition
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest enabling the cop Style/YodaCondition
with the default EnforcedStyle
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I strongly suggest enabling the cop Style/TrailingMethodEndStatement
. Why would one disable that? I see no scenario where that could be a useful thing to do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I strongly suggest enabling the cop Style/TrailingMethodEndStatement
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to have Style/SwapValues
enabled as this makes the intention of what is really done in the code clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest not disabling any security-related RuboCop cop like Shopify does. This is since I don't feel like I'm in the expert position to judge if we don't need this, so I'd prefer having this as an error that signifies to me I really have to watch out and should probably use a different way to do things (since smart people already figured this could be a potential security issue).
I even suggest writing the following to enable all security-related Rubocop cops.
Security:
Enabled: true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a use-case for self-assignment, so I'd suggest to enable the cop Lint/SelfAssignment
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest enabling the cop Lint/EmptyBlock
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest enabling the cop Lint/DuplicateRequire
.
To be honest: meanwhile I feel that for almost every cop they disabled at Shopify, I want to enable it again and disable it only if we encounter a use-case to opt-out of it in our own code base. Maybe a better strategy would be to go with the Rubocop defaults; it has many cops (which I suggested to enable in this PR) enabled by default. I mean we could still disable some things such as metric-related stuff (e.g. too long methods etc.). In the end, Rubocop should serve us and not vice-versa. When starting fresh, it might be very helpful to run the Rubocop autocorrect locally, see what things it proposes to change. One can then skim through the changes and if we don't like a change, we can deactivate it. The command I use is: bundle exec rubocop --autocorrect --disable-uncorrectable Then take a look at the changes and also search for Very useful for us is also this section. Note I've reduced our existing |
@fosterfarrell9 I've tried to reduce our existing |
You are certainly right. There are even more things where shopify deviates from Robocop's default settings that I do not like. We should not use the shopify settings as a basis. I am therefore closing this in favor of #564. |
The aim of this PR is to figure out a sensible configuration for rubocop in our project. Until now, we just used the rubocop config file of Rails. Looking at the details of what happens there, you see that many of these settings do not make sense for us.
In a first attempt to improve this, I incorporated Shopify's rubocop settings which are well documented and made some minor twists for settings where we have (until now) used different defaults. Note that in the shopify settings all
Metrics/
methods of rubocop are disabled.I put this first attempt up for discussion. If the general approach is considered okay, we might discuss where we deviate from shopify's config.