diff --git a/CHANGELOG.md b/CHANGELOG.md index ce2d2afb71e6..01fbbf882cad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ ### Bug fixes * [#8913](https://github.com/rubocop-hq/rubocop/pull/8913): Fix an incorrect auto-correct for `Style/RedundantRegexpCharacterClass` due to quantifier. ([@ysakasin][]) +* [#8917](https://github.com/rubocop-hq/rubocop/issues/8917): Fix rubocop comment directives handling of cops with multiple levels in department name. ([@fatkodima][]) ## 1.0.0 (2020-10-21) diff --git a/lib/rubocop/comment_config.rb b/lib/rubocop/comment_config.rb index 7c285f7a746d..6401af432418 100644 --- a/lib/rubocop/comment_config.rb +++ b/lib/rubocop/comment_config.rb @@ -8,7 +8,7 @@ class CommentConfig REDUNDANT_DISABLE = 'Lint/RedundantCopDisableDirective' # @api private - COP_NAME_PATTERN = '([A-Z]\w+/)?(?:[A-Z]\w+)' + COP_NAME_PATTERN = '([A-Z]\w+/)*(?:[A-Z]\w+)' # @api private COP_NAMES_PATTERN = "(?:#{COP_NAME_PATTERN} , )*#{COP_NAME_PATTERN}" # @api private diff --git a/spec/rubocop/comment_config_spec.rb b/spec/rubocop/comment_config_spec.rb index feeaaae748f2..0d055968c831 100644 --- a/spec/rubocop/comment_config_spec.rb +++ b/spec/rubocop/comment_config_spec.rb @@ -56,7 +56,10 @@ '# rubocop:disable RSpec/Example', '# rubocop:disable Custom2/Number9', # 48 '', - '#=SomeDslDirective # rubocop:disable Layout/LeadingCommentSpace' + '#=SomeDslDirective # rubocop:disable Layout/LeadingCommentSpace', + '# rubocop:disable RSpec/Rails/HttpStatus', + 'it { is_expected.to have_http_status 200 }', # 52 + '# rubocop:enable RSpec/Rails/HttpStatus' ].join("\n") end @@ -94,6 +97,12 @@ def disabled_lines_of_cop(cop) end end + it 'supports disabling cops with multiple levels in department name' do + disabled_lines = disabled_lines_of_cop('RSpec/Rails/HttpStatus') + expected_part = (51..53).to_a + expect(disabled_lines & expected_part).to eq(expected_part) + end + it 'supports enabling/disabling cops without a prefix' do empty_interpolation_disabled_lines = disabled_lines_of_cop('Lint/EmptyInterpolation')