Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit dbd3a3f

Browse files
committed
Don't report same line in other_locations
This follows up on the PR for not reporting multiple duplications for the same line and applied the same logic to `other_locations`.
1 parent 8df8109 commit dbd3a3f

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

lib/cc/engine/analyzers/reporter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def mass_threshold
6666

6767
def new_violation(issue)
6868
hashes = flay.hashes[issue.structural_hash]
69-
Violation.new(language_strategy.base_points, issue, hashes)
69+
Violation.new(language_strategy.base_points, issue, hashes, reports)
7070
end
7171

7272
def flay_options

lib/cc/engine/analyzers/violation.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ module Analyzers
66
class Violation
77
attr_reader :issue
88

9-
def initialize(base_points, issue, hashes)
9+
def initialize(base_points, issue, hashes, reports)
1010
@base_points = base_points
1111
@issue = issue
1212
@hashes = hashes
13+
@reports = reports
1314
end
1415

1516
def format
@@ -32,7 +33,7 @@ def report_name
3233

3334
private
3435

35-
attr_reader :base_points, :hashes
36+
attr_reader :base_points, :hashes, :reports
3637

3738
def current_sexp
3839
@location ||= sorted_hashes.first
@@ -43,7 +44,12 @@ def sorted_hashes
4344
end
4445

4546
def other_sexps
46-
@other_locations ||= hashes.drop(1)
47+
@_other_sexps ||= hashes.drop(1).reject do |hash|
48+
report_name = "#{hash.file}-#{hash.line}"
49+
reports.include?(report_name).tap do
50+
reports.add(report_name)
51+
end
52+
end
4753
end
4854

4955
def name

spec/cc/engine/analyzers/javascript/main_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@
6565

6666
result = run_engine(engine_conf).strip
6767
issues = result.split("\0")
68+
69+
first_issue = issues.first
70+
json = JSON.parse(first_issue)
71+
72+
expect(json["other_locations"].length).to eq(0)
6873
expect(issues.length).to eq 1
6974
end
7075

0 commit comments

Comments
 (0)