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
[#5977] Warn for Performance Cops #6845
Conversation
@bbatsov I'm not sure whether it's good to remove from RuboCop version 0.68, but I'd like to start with a warning first for users. What do you think about this? |
What will happen if someone is using the new gem together with a RuboCop release that still bundles them? I was thinking that I can cut a quick release now just with the warning and we could cut 0.68 quickly as well, only to remove the old cops. |
b08613b
to
f9a3fd9
Compare
Does If so, rubocop-performance is used in preference than old performance cops. I'm worried that if the old performance cops are removed with this PR, users won't get the migration period. I was missing my explanation 💦I consider the following milestones.
|
### Summary This PR warns for Performance Cops. The following warning is displayed when the next released rubocop gem is installed. ```console # The following is an example for operation check. % rake build % gem install pkg/rubocop-0.66.0.gem Performance Cops will be removed from RuboCop 0.68. Use rubocop-performance gem instead. Put this in your Gemfile. gem 'rubocop-performance' And then execute: $ bundle install Put this into your .rubocop.yml. require: rubocop-performance More information: https://github.com/rubocop-hq/rubocop-performance Successfully installed rubocop-0.66.0 1 gem installed ``` The following warning is displayed if RuboCop is used with Bundler. ```consle % bundle exec rubocop [Warn] Performance Cops will be removed from RuboCop 0.68. Use rubocop-performance gem instead. https://github.com/rubocop-hq/rubocop/tree/master/manual/migrate_performance_cops.md ``` The above warning will disappear when rubocop-performance gem is written to Gemfile. The rubocop-performance implementation takes precedence when rubocop-performance is written in Gemfile. And I prepared a simple migration manual (migrate_performance_cops.md) because I think that long warning sentences are not preferred. I think that referring to the link is good when runnning rubocop command. ### Other Infromation At first I tried to remove performance cops from RuboCop Core and add rubocop-performance gem as a dependency because of fallback. ```diff % git diff diff --git a/rubocop.gemspec b/rubocop.gemspec index bbbcca33f..09882b063 100644 --- a/rubocop.gemspec +++ b/rubocop.gemspec @@ -38,6 +38,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency('parser', '>= 2.5', '!= 2.5.1.1') s.add_runtime_dependency('psych', '>= 3.1.0') s.add_runtime_dependency('rainbow', '>= 2.2.2', '< 4.0') + s.add_runtime_dependency('rubocop-performance') s.add_runtime_dependency('ruby-progressbar', '~> 1.7') s.add_runtime_dependency('unicode-display_width', '>= 1.4.0', '< 1.6') ``` However, this cannot be resolved because it is cyclic. ```console % bundle install Fetching gem metadata from https://rubygems.org/........ Fetching gem metadata from https://rubygems.org/. Resolving dependencies... Your bundle requires gems that depend on each other, creating an infinite loop. Please remove either gem 'rubocop' or gem 'rubocop-performance' and try again. ``` So I'd like to display a warning before removing performance cops. I'd like to mitigate the impact on users this way. The next step is to remove performance cops and done rubocop#5977.
f9a3fd9
to
60b5a5f
Compare
parser = Bundler::LockfileParser.new(gemfile_lock) | ||
|
||
unless parser.dependencies['rubocop-performance'] | ||
warn Rainbow(<<-MESSAGE.strip_indent).yellow.to_s |
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.
📝 The above .to_s
method is used to prevent the following errors for JRuby 9.2.
% bundle exec rspec ./spec/rubocop/cli/cli_options_spec.rb:210
Run options: include {:focus=>true, :locations=>{"./spec/rubocop/cli/cli_options_spec.rb"=>[210]}}
Randomized with seed 11663
TypeError: wrong argument type Rainbow::NullPresenter (expected String)
warn at org/jruby/common/RubyWarnings.java:224
warn at org/jruby/RubyKernel.java:1247
warn at org/jruby/RubyKernel.java:1234
<main> at /Users/koic/src/github.com/rubocop-hq/rubocop/exe/rubocop:17
F
Failures:
1) RuboCop::CLI --only when one cop is given accepts cop names from plugins
Got 2 failures from failure aggregation block.
# ./spec/support/cli_spec_behavior.rb:27:in `block in <main>'
# ./lib/rubocop/rspec/shared_contexts.rb:27:in `block in <main>'
# ./lib/rubocop/path_util.rb:67:in `chdir'
# ./lib/rubocop/rspec/shared_contexts.rb:26:in `block in <main>'
# ./lib/rubocop/rspec/shared_contexts.rb:8:in `block in <main>'
1.1) Failure/Error: expect($CHILD_STATUS.success?).to be_truthy
expected: truthy value
got: false
# ./spec/rubocop/cli/cli_options_spec.rb:210:in `block in <main>'
1.2) Failure/Error:
expect(output)
.to eq(<<-RESULT.strip_indent)
Inspecting 2 files
..
2 files inspected, no offenses detected
RESULT
My bad. I meant to write new gem.
Yeah, I completely agree. I like the proposed timeline. |
I updated to the latest version of the gem but I don't want to use performance cops. How can I suppress the warning without having to install the RuboCop Performance gem? cc @koic |
Fixes rubocop#6939. Fixes rubocop#6917. This warning should not be displayed if users don't use Performance cops as follows: - rubocop#6845 (comment) - rubocop#6919 (comment) In the future, it will be better to replace it with a mechanism that displays a warning only when the user need Performance cops. This PR removes a warning for rubocop-performance when runinng `rubocop` command. It just leave a warning just to `gem install rubocop`. https://github.com/rubocop-hq/rubocop/blob/v0.67.2/rubocop.gemspec#L47
Fixes #6939. Fixes #6917. This warning should not be displayed if users don't use Performance cops as follows: - #6845 (comment) - #6919 (comment) In the future, it will be better to replace it with a mechanism that displays a warning only when the user need Performance cops. This PR removes a warning for rubocop-performance when running `rubocop` command. It leaves a warning just for `gem install rubocop`. https://github.com/rubocop-hq/rubocop/blob/v0.67.2/rubocop.gemspec#L47
Thank you! ❤️ |
Summary
This PR warns for Performance Cops.
The following warning is displayed when the next released rubocop gem is installed.
The following warning is displayed if RuboCop is used with Bundler.
The above warning will disappear when rubocop-performance gem is written to Gemfile.
The rubocop-performance implementation takes precedence when rubocop-performance is written in Gemfile.
And I prepared a simple migration manual (migrate_performance_cops.md) because I think that long warning sentences are not preferred. I think that referring to the link is good when runnning rubocop command.
Other Infromation
At first I tried to remove performance cops from RuboCop Core and add rubocop-performance gem as a dependency because of fallback.
However, this cannot be resolved because it is cyclic.
So I'd like to display a warning before removing performance cops.
I'd like to mitigate the impact on users this way.
The next step is to remove performance cops and done #5977.
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).and description in grammatically correct, complete sentences.
bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.