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

Allow extensions to disable cop obsoletions #9206

Merged
merged 1 commit into from
Dec 11, 2020

Conversation

dvandersluis
Copy link
Member

@dvandersluis dvandersluis commented Dec 10, 2020

Noticed this change made to rubocop-rails. There needs to be a way for an extension to disable an obsoletion (ie. rubocop-rails should not have Rails/* raise an error)

extracted:
  Rails/*: ~

Follows #9143.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • 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.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@dvandersluis
Copy link
Member Author

/cc @koic

@koic
Copy link
Member

koic commented Dec 11, 2020

Thank you for catching up!

I tried applying the following to RuboCop Rails.

% git diff
diff --git a/Gemfile b/Gemfile
index 103582220..7daa29aee 100644
--- a/Gemfile
+++ b/Gemfile
diff --git a/Gemfile b/Gemfile
index 103582220..7daa29aee 100644
--- a/Gemfile
+++ b/Gemfile
@@ -9,7 +9,7 @@ gemspec
 gem 'bump', require: false
 gem 'rake'
 gem 'rspec'
-gem 'rubocop', github: 'rubocop-hq/rubocop'
+gem 'rubocop', github: 'dvandersluis/rubocop', branch: 'obsoletion-disable'
 gem 'rubocop-performance', '~> 1.9.0'
 gem 'rubocop-rspec', '~> 1.29.0'
 gem 'simplecov'
diff --git a/config/default.yml b/config/default.yml
index 7d2fe4fd5..17e7a9374 100644
--- a/config/default.yml
+++ b/config/default.yml
@@ -1,5 +1,8 @@
 # Common configuration.

+extracted:
+  Rails/*: ~
+
 inherit_mode:
   merge:
     - Exclude
diff --git a/spec/project_spec.rb b/spec/project_spec.rb
index e53a18da6..f0e2b10bd 100644
--- a/spec/project_spec.rb
+++ b/spec/project_spec.rb
@@ -4,10 +4,6 @@ RSpec.describe 'RuboCop Rails Project', type: :feature do
   describe 'default configuration file' do
     subject(:config) { RuboCop::ConfigLoader.load_file('config/default.yml') }

-    before do
-      allow_any_instance_of(RuboCop::Config).to receive(:loaded_features).and_return('rubocop-rails') # rubocop:disable RSpec/AnyInstance
-    end

But the following test failed.

% bundle exec rspec spec/project_spec.rb
(snip)

Failures:

  1) RuboCop Rails Project default configuration file sorts configuration keys alphabetically
     Failure/Error: subject(:config) { RuboCop::ConfigLoader.load_file('config/default.yml') }

     RuboCop::ValidationError:
       `Rails` cops have been extracted to the `rubocop-rails` gem.
       (obsolete configuration found in config/default.yml, please update it)
     # ./spec/project_spec.rb:5:in `block (3 levels) in <top (required)>'
     # ./spec/project_spec.rb:13:in `block (3 levels) in <top (required)>'
     # ./spec/project_spec.rb:43:in `block (3 levels) in <top (required)>'
(snip)

Am I using it incorrectly?

@dvandersluis
Copy link
Member Author

Yeah sorry @koic, I should have explained better. In #9143 I added a way for extensions to define their own obsoletion file. You need to create a yaml file somewhere and then call RuboCop::ConfigObsoletion.files << path_to_file. That should solve it but let me know if something's not working.

@koic
Copy link
Member

koic commented Dec 11, 2020

Ah, I get it!  Perfect! I will be introducing that to RuboCop Performance and RuboCop Rails after this PR change will be released (Because they need to adjust the supported version of the core). Thank you for the kindness explanation!

@koic koic merged commit fcc2d8a into rubocop:master Dec 11, 2020
@dvandersluis dvandersluis deleted the obsoletion-disable branch January 18, 2021 20:42
koic added a commit to koic/rubocop-rails that referenced this pull request Apr 21, 2021
Follow rubocop/rubocop#9206 and
rubocop/rubocop#9143.

This PR requires RuboCop 1.7 or higher due to support obsoletion configuration
and reverts rubocop@151b8a6.
koic added a commit to koic/rubocop-performance that referenced this pull request Apr 21, 2021
Follow rubocop/rubocop#9206 and
rubocop/rubocop#9143.

This PR requires RuboCop 1.7 or higher due to support obsoletion configuration
and reverts rubocop@0e59891.
renawatson68 added a commit to renawatson68/performance-develop-rubyonrails that referenced this pull request Sep 23, 2022
Follow rubocop/rubocop#9206 and
rubocop/rubocop#9143.

This PR requires RuboCop 1.7 or higher due to support obsoletion configuration
and reverts rubocop/rubocop-performance@0e59891.
richardstewart0213 added a commit to richardstewart0213/performance-build-Performance-optimization-analysis- that referenced this pull request Nov 4, 2022
Follow rubocop/rubocop#9206 and
rubocop/rubocop#9143.

This PR requires RuboCop 1.7 or higher due to support obsoletion configuration
and reverts rubocop/rubocop-performance@0e59891.
MarttiCheng added a commit to MarttiCheng/Rubocop-Performance that referenced this pull request Sep 28, 2023
Follow rubocop/rubocop#9206 and
rubocop/rubocop#9143.

This PR requires RuboCop 1.7 or higher due to support obsoletion configuration
and reverts rubocop/rubocop-performance@0e59891.
SerhiiMisiura added a commit to SerhiiMisiura/Rubocop-Performance that referenced this pull request Oct 5, 2023
Follow rubocop/rubocop#9206 and
rubocop/rubocop#9143.

This PR requires RuboCop 1.7 or higher due to support obsoletion configuration
and reverts rubocop/rubocop-performance@0e59891.
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

2 participants