-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Replace rubocop with standard #3951
Conversation
@@ -83,4 +81,4 @@ gem 'rspec_junit_formatter', require: false, group: :ci | |||
gem 'yard', require: false, group: :docs | |||
|
|||
custom_gemfile = File.expand_path('Gemfile-custom', __dir__) | |||
eval File.read(custom_gemfile), nil, custom_gemfile, 0 if File.exist?(custom_gemfile) | |||
eval File.read(custom_gemfile), nil, custom_gemfile, 0 if File.exist?(custom_gemfile) # rubocop:disable Security/Eval |
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.
Lint/UnneededCopDisableDirective: Unnecessary disabling of Security/Eval.
"" | ||
end | ||
end | ||
|
||
if params[:q][:created_at_lt].present? | ||
params[:q][:created_at_lt] = begin | ||
Time.zone.parse(params[:q][:created_at_lt]).end_of_day | ||
rescue StandardError | ||
rescue |
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/RescueStandardError: Avoid rescuing without specifying an error class.
@@ -28,15 +28,15 @@ def index | |||
if params[:q][:created_at_gt].present? | |||
params[:q][:created_at_gt] = begin | |||
Time.zone.parse(params[:q][:created_at_gt]).beginning_of_day | |||
rescue StandardError | |||
rescue |
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/RescueStandardError: Avoid rescuing without specifying an error class.
@@ -100,7 +100,7 @@ def taxons_tree(root_taxon, current_taxon, max_level = 1) | |||
return '' if max_level < 1 || root_taxon.children.empty? | |||
content_tag :ul, class: 'taxons-list' do | |||
taxons = root_taxon.children.map do |taxon| | |||
css_class = (current_taxon && current_taxon.self_and_ancestors.include?(taxon)) ? 'current' : nil | |||
css_class = current_taxon && current_taxon.self_and_ancestors.include?(taxon) ? 'current' : nil |
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/SafeNavigation: Use safe navigation (&.) instead of checking if an object exists before calling the method.
@@ -87,7 +87,7 @@ def to_s | |||
# @note This compares the addresses based on only the fields that make up | |||
# the logical "address" and excludes the database specific fields (id, created_at, updated_at). | |||
# @return [Boolean] true if the two addresses have the same address fields | |||
def ==(other_address) | |||
def ==(other_address) # rubocop:disable Naming/BinaryOperatorParameterName |
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.
Lint/UnneededCopDisableDirective: Unnecessary disabling of Naming/BinaryOperatorParameterName.
@@ -37,7 +37,7 @@ def self.deprecate_cherry_picking | |||
Spree::Deprecation.warn( | |||
"Please do not cherry-pick factories, this is not well supported by FactoryBot, " \ | |||
'follow the changelog instructions on how to migrate your current setup.', | |||
callsites[index..-1] | |||
callsites[index..] |
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.
Lint/Syntax: unexpected token tRBRACK
@@ -48,6 +48,6 @@ def weighted_line_item_amount(line_item) | |||
end | |||
|
|||
def quantity_of_line_item(line_item) | |||
BigDecimal(line_item.inventory_units.not_canceled.reject(&:original_return_item).size) | |||
BigDecimal(line_item.inventory_units.not_canceled.reject(&:original_return_item).size) # rubocop:disable Performance/Count |
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.
Lint/UnneededCopDisableDirective: Unnecessary disabling of Performance/Count.
@@ -246,9 +246,11 @@ | |||
let(:usd_30) { Spree::Money.new(30, currency: "USD") } | |||
|
|||
it "compares the two amounts" do | |||
# rubocop:disable Lint/BinaryOperatorWithIdenticalOperands |
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.
Lint/UnneededCopDisableDirective: Unnecessary disabling of Lint/BinaryOperatorWithIdenticalOperands (unknown cop).
@@ -452,7 +453,7 @@ def empty! | |||
def coupon_code=(code) | |||
@coupon_code = begin | |||
code.strip.downcase | |||
rescue StandardError | |||
rescue |
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/RescueStandardError: Avoid rescuing without specifying an error class.
@@ -7,7 +7,7 @@ class CustomMarkdownRenderer < Redcarpet::Render::HTML | |||
|
|||
def block_code(code, language) | |||
path = code.lines.first[/^#\s(\S*)$/, 1] | |||
code = code.lines[1..-1].join if path | |||
code = code.lines[1..].join if path |
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.
Lint/Syntax: unexpected token tRBRACK
e833ab7
to
dff7bce
Compare
While I don't want to be the one pushing for a ton of formatting churn, I'm also concerned we're not going to get a huge amount of value from using the tool if it's configured such that so much of its functionality is disabled. Might need further consideration with @solidusio/core-team. |
I agree and I realized this after completing the task. The whole point of using standard is to not have to configure anything. This more or less defeats the purpose. |
I agree. If we move to Standard, we should probably just fix all the offenses. We're basically going to touch every single file in the codebase, but at least we'll only have to do it once. What does the rest of @solidusio/core-team think? |
I like the idea of opinionated, non-config code formatters like rufo or standard. The thing is that every contributor would need to use it and we would still need to lint the code with rubocop, otherwise the rules wouldnt be enforced. Its a tricky situation. Unfortunately the code formatting is not build into the language. |
you mean lint with
One issue I see though is that configuration is not standardized across all users of the language - hence some contributors might find themselves manually fixing some weird issues (in case autocorrect does not work in those cases). |
Standard uses rubocop, so yes. If we go with the default rubocop rules of standard (what I encourage us to do, otherwise it would not make sense to use it at all), we would use standard to lint as well. 👍🏻
Unfortuantely its not. The people would still need to install it and configure their editor to "format on safe" with the tool that we force on them. They might have it disabled or even worse configured differently. The idea of automatic code formatters is great, but unless build into the language from the beginning, you are screwed. |
Take the double-quotes rule as example. Prettierrb has it changed from the Prettierjs default to The idea was to not fight over code formatting rules anymore, and use a tool for that. Now people fight over the rules. Its ridiculous. Imagine the following situation: A dev has configured their editor to use The only unobtrusive thing I could imagine is to automatically run |
On our projects we usually use our autoformatters with a tool like |
It is lovely to see how we use rubocop in rails.
One example of how rubocop gives a hand while improving the codebase: We noticed that we dropped support for < Ruby 2.7 so that we could use P. S.There are more interesting samples https://github.com/rails/rails/pulls?q=is%3Apr+rubocop+is%3Aclosed+author%3Akamipo |
@bogdanvlviv I really like the approach proposed. We can gradually introduce rules based on the feedback we provide in PR reviews and use Rubocop as a tool to refactor code over time. 👍 |
I more in favour of the set it and forget approach of Standard. Continuing to maintain a rubocop configuration, especially across the extension ecosystem (though I know we could rely on solidus_dev_support) doesn't seem like a good use of maintenance effort to me. That said, if there were some rules we wanted to enable on top of the Standard defaults, like ones that deter people from doing insecure things, I'm open it. |
I'm not really in favor of basically touching every single file in the codebase for cosmetic reasons (or at least debatable reasons). While I personally like standard more than rubocop (but in general I'm not a fan of code linters, at least in the ruby ecosystem), I think the change would be pretty invasive and pollute the git history. And there's no guarantee it would be final, in a few years we may be still here evaluating the new best linter and debating if we should change all the files again. |
The concern about touching every file is fair; it's not ideal, but I don't consider it a dealbreaker if what we get in exchange for a one-off formatting commit is to stop worrying about this style formatting stuff. I don't agree with your concern about further churn down the road. The problem with maintaining a Rubocop config (across the whole Solidus ecosystem) is that Rubocop continues to add, remove and change rules, which requires us to evaluate them and decide whether to integrate with (and at least keep up with changes to rules we use.) Using Rubocop is like agreeing to debate style forever. The whole point of Standard (especially now that it has hit v1.0) is that they've done the work to debate the preferences of the Ruby community and have adopted a reasonably conservative set of sensible defaults. If we adopt it, we agree to basically never do this again barring some kind of catastrophe, otherwise I agree it's not worth changing. While I don't like formatting churn standard'll cause, only one of these tools purports to offer the opportunity to just use the tool's default settings and never worry about this again. |
And to be clear, I'm still not 100% sure we should do this, I just really don't want to maintain a Rubocop config. It just seems like a waste of time when there's a "set it and forget it" alternative. |
@jarednorman 💯 agree. Well said. |
I also agree with @jarednorman. Going with Standard is not just another coding style change - it means not having to worry about coding style ever again, which is a very alluring idea. As for touching every file and polluting the Git history, I don't see much of a problem with that, as long as it's a one-off thing. |
@tejasbubane Thanks for your patience with our back and forth on this issue. After a Core Team discussion we've decided that for now this change would be a bit too disruptive. It would mean everyone would have to rebase all their open PRs, we'd have to update the whole extension ecosystem to match, and it would generate a lot of noise in the history of all the files in the project. I think we'd all prefer to be using Standard (and without a bunch of rules disabled), but the benefits don't outweigh the disruption. We think there might be a moment down the road where some other large, disruptive change gets made where we'd sneak this one in too just to get it all over with, so we'll cross that bridge when we come to it. |
Closes #3872
Checklist: