Skip to content

Commit

Permalink
Add disabled_all to DirectiveComment
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Eres committed May 10, 2021
1 parent 2f1ad5f commit 58002f7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/rubocop/directive_comment.rb
Expand Up @@ -64,6 +64,11 @@ def enabled_all?
!disabled? && all_cops?
end

# Checks if this directive disables all cops
def disabled_all?
disabled? && all_cops?
end

# Checks if all cops specified in this directive
def all_cops?
cops == 'all'
Expand Down
28 changes: 28 additions & 0 deletions spec/rubocop/directive_comment_spec.rb
Expand Up @@ -214,4 +214,32 @@
end
end
end

describe '#disabled_all?' do
subject { directive_comment.disabled_all? }

context 'when enabled all cops' do
let(:text) { 'def foo # rubocop:enable all' }

it { is_expected.to eq false }
end

context 'when enabled specific cops' do
let(:text) { '# rubocop:enable Foo/Bar' }

it { is_expected.to eq false }
end

context 'when disabled all cops' do
let(:text) { '# rubocop:disable all' }

it { is_expected.to eq true }
end

context 'when disabled specific cops' do
let(:text) { '# rubocop:disable Foo/Bar' }

it { is_expected.to eq false }
end
end
end

0 comments on commit 58002f7

Please sign in to comment.