Skip to content
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

Merged
merged 1 commit into from Mar 19, 2019

Conversation

koic
Copy link
Member

@koic koic commented Mar 19, 2019

Summary

This PR warns for Performance Cops.

The following warning is displayed when the next released rubocop gem is installed.

# 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.

% 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.

% 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.

% 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 #5977.


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

@koic
Copy link
Member Author

koic commented Mar 19, 2019

@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?

@bbatsov
Copy link
Collaborator

bbatsov commented Mar 19, 2019

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.

@koic koic force-pushed the warn_for_performance_cops branch from b08613b to f9a3fd9 Compare March 19, 2019 09:41
@koic
Copy link
Member Author

koic commented Mar 19, 2019

What will happen if someone is using the new gem together with a RuboCop release that still bundles them?

Does new cop mean rubocop-performance?

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.

  • 0.66 ... Current version
  • Next release ... Display a warning and prepare a transition period for users
  • 0.68 ... Remove old cops from RuboCop Core

### 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.
@koic koic force-pushed the warn_for_performance_cops branch from f9a3fd9 to 60b5a5f Compare March 19, 2019 10:19
parser = Bundler::LockfileParser.new(gemfile_lock)

unless parser.dependencies['rubocop-performance']
warn Rainbow(<<-MESSAGE.strip_indent).yellow.to_s
Copy link
Member Author

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

https://circleci.com/gh/rubocop-hq/rubocop/42485

@bbatsov
Copy link
Collaborator

bbatsov commented Mar 19, 2019

Does new cop mean rubocop-performance?

My bad. I meant to write new gem.

I'm worried that if the old performance cops are removed with this PR, users won't get the migration period.

Yeah, I completely agree. I like the proposed timeline.

@volmer
Copy link
Contributor

volmer commented Apr 10, 2019

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

koic added a commit to koic/rubocop that referenced this pull request Apr 17, 2019
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
@koic
Copy link
Member Author

koic commented Apr 17, 2019

@volmer I opened a PR #6939. Thanks!

@AlexWayfer
Copy link
Contributor

@volmer I opened a PR #6939. Thanks!

#6944 *

bbatsov pushed a commit that referenced this pull request Apr 17, 2019
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
@volmer
Copy link
Contributor

volmer commented Apr 17, 2019

Thank you! ❤️

@koic koic mentioned this pull request May 21, 2019
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants