-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…WithinSourceCodeDirective`.
- Loading branch information
1 parent
1de3a9f
commit 052eb8a
Showing
4 changed files
with
115 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* [#9399](https://github.com/rubocop-hq/rubocop/issues/9399): Added `AllowedCops` configuration to `Style/DisableCopsWithinSourceCodeDirective`. ([@dvandersluis][]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 63 additions & 9 deletions
72
spec/rubocop/cop/style/disable_cops_within_source_code_directive_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,85 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe RuboCop::Cop::Style::DisableCopsWithinSourceCodeDirective do | ||
subject(:cop) { described_class.new } | ||
|
||
RSpec.describe RuboCop::Cop::Style::DisableCopsWithinSourceCodeDirective, :config do | ||
it 'registers an offense for disabled cop within source code' do | ||
expect_offense(<<~RUBY) | ||
def choose_move(who_to_move)# rubocop:disable Metrics/CyclomaticComplexity | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Comment to disable/enable RuboCop. | ||
def foo # rubocop:disable Metrics/CyclomaticComplexity | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Rubocop disable/enable directives are not permitted. | ||
end | ||
RUBY | ||
|
||
expect_correction(<<~RUBY) | ||
def choose_move(who_to_move) | ||
def foo#{trailing_whitespace} | ||
end | ||
RUBY | ||
end | ||
|
||
it 'registers an offense for enabled cop within source code' do | ||
expect_offense(<<~RUBY) | ||
def choose_move(who_to_move)# rubocop:enable Metrics/CyclomaticComplexity | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Comment to disable/enable RuboCop. | ||
def foo # rubocop:enable Metrics/CyclomaticComplexity | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Rubocop disable/enable directives are not permitted. | ||
end | ||
RUBY | ||
|
||
expect_correction(<<~RUBY) | ||
def foo#{trailing_whitespace} | ||
end | ||
RUBY | ||
end | ||
|
||
it 'registers an offense for disabling all cops' do | ||
expect_offense(<<~RUBY) | ||
def foo # rubocop:enable all | ||
^^^^^^^^^^^^^^^^^^^^ Rubocop disable/enable directives are not permitted. | ||
end | ||
RUBY | ||
|
||
expect_correction(<<~RUBY) | ||
def choose_move(who_to_move) | ||
def foo#{trailing_whitespace} | ||
end | ||
RUBY | ||
end | ||
|
||
context 'with AllowedCops' do | ||
let(:cop_config) { { 'AllowedCops' => ['Metrics/CyclomaticComplexity', 'Metrics/AbcSize'] } } | ||
|
||
context 'when an allowed cop is disabled' do | ||
it 'does not register an offense' do | ||
expect_no_offenses(<<~RUBY) | ||
def foo # rubocop:disable Metrics/CyclomaticComplexity | ||
end | ||
RUBY | ||
end | ||
end | ||
|
||
context 'when an non-allowed cop is disabled' do | ||
it 'registers an offense and corrects' do | ||
expect_offense(<<~RUBY) | ||
def foo # rubocop:disable Layout/LineLength | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Rubocop disable/enable directives for `Layout/LineLength` are not permitted. | ||
end | ||
RUBY | ||
|
||
expect_correction(<<~RUBY) | ||
def foo#{trailing_whitespace} | ||
end | ||
RUBY | ||
end | ||
end | ||
|
||
context 'when an mix of cops are disabled' do | ||
it 'registers an offense and corrects' do | ||
expect_offense(<<~RUBY) | ||
def foo # rubocop:disable Metrics/AbcSize, Layout/LineLength, Metrics/CyclomaticComplexity, Style/AndOr | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Rubocop disable/enable directives for `Layout/LineLength`, `Style/AndOr` are not permitted. | ||
end | ||
RUBY | ||
|
||
expect_correction(<<~RUBY) | ||
def foo # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity | ||
end | ||
RUBY | ||
end | ||
end | ||
end | ||
end |