Skip to content

Commit 485cc0c

Browse files
committed
Skip locally disabled cops
When a line is skipped locally using Rubocops local disable we don't want to report it. Rubocop offenses give us the `disabled?` method to check if a violation was skipped locally.
1 parent df201d7 commit 485cc0c

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/cc/engine/rubocop.rb

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def category(cop_name)
4343
def inspect_file(path)
4444
parsed = RuboCop::ProcessedSource.from_file(path)
4545
rubocop_team_for_path(path).inspect_file(parsed).each do |violation|
46+
next if violation.disabled?
4647
decorated_violation = ViolationDecorator.new(violation)
4748
json = violation_json(decorated_violation, local_path(path))
4849
@io.print "#{json}\0"

spec/cc/engine/rubocop_spec.rb

+13
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,19 @@ def method
270270
assert includes_check?(output, "Lint/UselessAssignment")
271271
end
272272

273+
it "skips local disables" do
274+
create_source_file("test.rb", <<-EORUBY)
275+
def method
276+
# rubocop:disable UselessAssignment
277+
unused = "x"
278+
279+
return false
280+
end
281+
EORUBY
282+
output = run_engine
283+
refute includes_check?(output, "Lint/UselessAssignment")
284+
end
285+
273286
def includes_check?(output, cop_name)
274287
issues(output).any? { |i| i["check_name"] =~ /#{cop_name}$/ }
275288
end

0 commit comments

Comments
 (0)