-
Notifications
You must be signed in to change notification settings - Fork 47
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
Match rubocop-shopify with style guide recommendations #422
Conversation
Signed-off-by: Nick Schwaderer <[email protected]>
Signed-off-by: Nick Schwaderer <[email protected]>
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.
This seems fine, given it doesn't actually enable the cop (which would be a bigger discussion, due to the impact), and just configures the cop so that if enabled it would enforce the style consistent with our recommendation.
Nit about the gem name in the description though 😅
-shopify-rubocop
+rubocop-shopify
First-time contributor 🙈 I'll get the name right some day! thanks |
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.
Could you please change the config to Enabled: true
?
The rule has been added to the Style Guide for years now, so everyone should be writing code that follows it by now, even if RuboCop wasn't able to catch those offences so far. Besides it wouldn't make sense to tweak a cop's config if it's not enabled by default.
Is there a way to enforce this style only when there's more than one class method? |
For the sake of consistency, I don't think that makes sense, personally. I actually prefer |
Signed-off-by: Nick Schwaderer <[email protected]>
Me too. My concern is the problem that, for shopify, we have thousands of rubyists and if we do something unusual/different in our style guide and don't back it up with a cop, it's easily missed. I agree with @volmer - let's enforce it.
I don't know what I'm allowed to say since this is a public repository. But after a quick search at this org it appears both approaches are equally used. Many thousands of times. Background I'm only here because it was flagged up on my PR that I was going against the Shopify Ruby Style Guide 😅 - I was surprised my linter didn't catch the Shopify rule. So here we are. |
test/test_helper.rb:7:3: C: Style/ClassMethodsDefinitions: Use class << self to define a class method.
def self.warn(message) ...
^^^^^^^^^^^^^^^^^^^^^^ Even the style guide is in violation... I'll update that now. |
Signed-off-by: Nick Schwaderer <[email protected]>
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.
❤️
Should we set this to ignore migrations? https://buildkite.com/shopify/shopify-graphiql-app/builds/2155#0183c3f3-710f-424a-9fbb-7c6f30ca2979 |
(the migration generator from older version of Rails used |
That isn't true since Rails 3.1. I don't think we should care about very old Rails versions. |
Background
There is a discrepancy between shopify-rubocop and the Shopify Ruby Styleguide.
The Ruby Styleguide says:
( pr for background )
There is an option to enable this in rubocop under
Style/ClassMethodsDefinitions
forself_class
. Our current default does the opposite, with theEnforcedStyle
beingdef_self
.This corrects the default.
For Reviewers
This cop is currently set to
Enabled: false
. If we care enough about this to have an opinion in the styleguide should it be changed toEnabled: true
? Thedef self
vsclass << self
is a long-running question of preference so it might be nice to give clarity on this.Signed-off-by: Nick Schwaderer [email protected]