Skip to content

Commit

Permalink
Correct redundant disable cop duplicated by department
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Eres committed Jun 13, 2021
1 parent cdd70b7 commit 0599621
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rubocop/cop/lint/redundant_cop_disable_directive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ def ignore_offense?(line_range)
end

def department_disabled?(cop, comment)
DirectiveComment.new(comment).in_directive_department?(cop)
directive = DirectiveComment.new(comment)
directive.in_directive_department?(cop) && !directive.overridden_by_department?(cop)
end

def directive_count(comment)
Expand Down
34 changes: 34 additions & 0 deletions spec/rubocop/cop/lint/redundant_cop_disable_directive_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,40 @@ def bar
RUBY
end

it 'removes cop duplicated by department' do
expect_offense(<<~RUBY)
# rubocop:disable Metrics, Metrics/ClassLength
^^^^^^^^^^^^^^^^^^^ Unnecessary disabling of `Metrics/ClassLength`.
def bar
do_something
end
RUBY

expect_correction(<<~RUBY)
# rubocop:disable Metrics
def bar
do_something
end
RUBY
end

it 'removes cop duplicated by department on previous line' do
expect_offense(<<~RUBY)
# rubocop:disable Metrics
def bar
do_something # rubocop:disable Metrics/ClassLength
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Unnecessary disabling of `Metrics/ClassLength`.
end
RUBY

expect_correction(<<~RUBY)
# rubocop:disable Metrics
def bar
do_something
end
RUBY
end

it 'does not remove correct department' do
expect_no_offenses(<<~RUBY)
# rubocop:disable Metrics
Expand Down

0 comments on commit 0599621

Please sign in to comment.