From 58002f7412356fb51f41ab1c2983ae195dd1e7c6 Mon Sep 17 00:00:00 2001 From: Andrei Eres Date: Thu, 6 May 2021 16:58:50 +0300 Subject: [PATCH] Add disabled_all to DirectiveComment --- lib/rubocop/directive_comment.rb | 5 +++++ spec/rubocop/directive_comment_spec.rb | 28 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/lib/rubocop/directive_comment.rb b/lib/rubocop/directive_comment.rb index 024dfbf76774..64b80fd77066 100644 --- a/lib/rubocop/directive_comment.rb +++ b/lib/rubocop/directive_comment.rb @@ -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' diff --git a/spec/rubocop/directive_comment_spec.rb b/spec/rubocop/directive_comment_spec.rb index 56a66638a980..f6377997cfa9 100644 --- a/spec/rubocop/directive_comment_spec.rb +++ b/spec/rubocop/directive_comment_spec.rb @@ -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