From bb9d2d9c133b7b612b2e1381c2d02f09bb1efeb7 Mon Sep 17 00:00:00 2001 From: ydah <13041216+ydah@users.noreply.github.com> Date: Tue, 26 Jul 2022 10:03:06 +0900 Subject: [PATCH] Deprecate `IgnoredPatterns` option Follow up https://github.com/rubocop/rubocop/pull/10555 This PR obsoletes the `IgnoredPatterns` option and replaces it with the `AllowedPatterns` option. --- CHANGELOG.md | 1 + config/default.yml | 3 ++- config/obsoletion.yml | 14 +++++++++++++ docs/modules/ROOT/pages/cops_rspec.adoc | 14 ++++++++----- lib/rubocop-rspec.rb | 1 + lib/rubocop/cop/rspec/variable_name.rb | 12 +++++------ lib/rubocop/rspec.rb | 14 +++++++++++++ lib/rubocop/rspec/inject.rb | 4 +--- spec/rubocop/cop/rspec/variable_name_spec.rb | 22 +++++++++++++++++++- 9 files changed, 69 insertions(+), 16 deletions(-) create mode 100644 config/obsoletion.yml create mode 100644 lib/rubocop/rspec.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c5d3e8ac..2be47afff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * Fix a false positive for `RSpec/Capybara/SpecificMatcher`. ([@ydah][]) * Fix a false negative for `RSpec/Capybara/SpecificMatcher` for `have_field`. ([@ydah][]) * Fix a false positive for `RSpec/Capybara/SpecificMatcher` when may not have a `href` by `have_link`. ([@ydah][]) +* Deprecate `IgnoredPatterns` option. ([@ydah][]) ## 2.12.1 (2022-07-03) diff --git a/config/default.yml b/config/default.yml index 926673a08..dcbf154e1 100644 --- a/config/default.yml +++ b/config/default.yml @@ -790,9 +790,10 @@ RSpec/VariableName: SupportedStyles: - snake_case - camelCase + AllowedPatterns: [] IgnoredPatterns: [] VersionAdded: '1.40' - VersionChanged: '1.43' + VersionChanged: '2.13' Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/VariableName RSpec/VerifiedDoubleReference: diff --git a/config/obsoletion.yml b/config/obsoletion.yml new file mode 100644 index 000000000..38f27529a --- /dev/null +++ b/config/obsoletion.yml @@ -0,0 +1,14 @@ +# +# Configuration of obsolete/deprecated cops used by `ConfigObsoletion`. +# +# See: https://docs.rubocop.org/rubocop/extensions.html#config-obsoletions +# + +# Cop parameters that have been changed +# Can be treated as a warning instead of a failure with `severity: warning` +changed_parameters: + - cops: + - RSpec/VariableName + parameters: IgnoredPatterns + alternative: AllowedPatterns + severity: warning diff --git a/docs/modules/ROOT/pages/cops_rspec.adoc b/docs/modules/ROOT/pages/cops_rspec.adoc index 6f461b0ba..8dea6a4f5 100644 --- a/docs/modules/ROOT/pages/cops_rspec.adoc +++ b/docs/modules/ROOT/pages/cops_rspec.adoc @@ -4465,12 +4465,12 @@ let('user_name') { 'Adam' } | Yes | No | 1.40 -| 1.43 +| 2.13 |=== Checks that memoized helper names use the configured style. -Variables can be excluded from checking using the `IgnoredPatterns` +Variables can be excluded from checking using the `AllowedPatterns` option. === Examples @@ -4501,20 +4501,20 @@ subject(:userName1) { 'Adam' } let(:userName2) { 'Adam' } ---- -==== IgnoredPatterns configuration +==== AllowedPatterns configuration [source,ruby] ---- # rubocop.yml # RSpec/VariableName: # EnforcedStyle: snake_case -# IgnoredPatterns: +# AllowedPatterns: # - ^userFood ---- [source,ruby] ---- -# okay because it matches the `^userFood` regex in `IgnoredPatterns` +# okay because it matches the `^userFood` regex in `AllowedPatterns` subject(:userFood_1) { 'spaghetti' } let(:userFood_2) { 'fettuccine' } ---- @@ -4528,6 +4528,10 @@ let(:userFood_2) { 'fettuccine' } | `snake_case` | `snake_case`, `camelCase` +| AllowedPatterns +| `[]` +| Array + | IgnoredPatterns | `[]` | Array diff --git a/lib/rubocop-rspec.rb b/lib/rubocop-rspec.rb index ffc3c0fc4..3af0f8714 100644 --- a/lib/rubocop-rspec.rb +++ b/lib/rubocop-rspec.rb @@ -5,6 +5,7 @@ require 'rubocop' +require_relative 'rubocop/rspec' require_relative 'rubocop/rspec/version' require_relative 'rubocop/rspec/inject' require_relative 'rubocop/rspec/node' diff --git a/lib/rubocop/cop/rspec/variable_name.rb b/lib/rubocop/cop/rspec/variable_name.rb index ed93a6e28..11b9d56e0 100644 --- a/lib/rubocop/cop/rspec/variable_name.rb +++ b/lib/rubocop/cop/rspec/variable_name.rb @@ -5,7 +5,7 @@ module Cop module RSpec # Checks that memoized helper names use the configured style. # - # Variables can be excluded from checking using the `IgnoredPatterns` + # Variables can be excluded from checking using the `AllowedPatterns` # option. # # @example EnforcedStyle: snake_case (default) @@ -26,22 +26,22 @@ module RSpec # subject(:userName1) { 'Adam' } # let(:userName2) { 'Adam' } # - # @example IgnoredPatterns configuration + # @example AllowedPatterns configuration # # # rubocop.yml # # RSpec/VariableName: # # EnforcedStyle: snake_case - # # IgnoredPatterns: + # # AllowedPatterns: # # - ^userFood # # @example - # # okay because it matches the `^userFood` regex in `IgnoredPatterns` + # # okay because it matches the `^userFood` regex in `AllowedPatterns` # subject(:userFood_1) { 'spaghetti' } # let(:userFood_2) { 'fettuccine' } # class VariableName < Base include ConfigurableNaming - include IgnoredPattern + include AllowedPattern include Variable MSG = 'Use %