From 03ac1bdf44486c66318305da19746404fe9a74d1 Mon Sep 17 00:00:00 2001 From: GordonDiggs Date: Tue, 10 Nov 2015 10:54:01 -0500 Subject: [PATCH 1/2] Revert "Don't report same line in other_locations" This reverts commit dbd3a3f0e2ed8b38b730dac2d4b2548266bc26ca. --- lib/cc/engine/analyzers/reporter.rb | 2 +- lib/cc/engine/analyzers/violation.rb | 12 +++--------- spec/cc/engine/analyzers/javascript/main_spec.rb | 5 ----- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/lib/cc/engine/analyzers/reporter.rb b/lib/cc/engine/analyzers/reporter.rb index 88af32fe..a21a4604 100644 --- a/lib/cc/engine/analyzers/reporter.rb +++ b/lib/cc/engine/analyzers/reporter.rb @@ -66,7 +66,7 @@ def mass_threshold def new_violation(issue) hashes = flay.hashes[issue.structural_hash] - Violation.new(language_strategy.base_points, issue, hashes, reports) + Violation.new(language_strategy.base_points, issue, hashes) end def flay_options diff --git a/lib/cc/engine/analyzers/violation.rb b/lib/cc/engine/analyzers/violation.rb index f4e2dbd3..17b0baa6 100644 --- a/lib/cc/engine/analyzers/violation.rb +++ b/lib/cc/engine/analyzers/violation.rb @@ -6,11 +6,10 @@ module Analyzers class Violation attr_reader :issue - def initialize(base_points, issue, hashes, reports) + def initialize(base_points, issue, hashes) @base_points = base_points @issue = issue @hashes = hashes - @reports = reports end def format @@ -33,7 +32,7 @@ def report_name private - attr_reader :base_points, :hashes, :reports + attr_reader :base_points, :hashes def current_sexp @location ||= sorted_hashes.first @@ -44,12 +43,7 @@ def sorted_hashes end def other_sexps - @_other_sexps ||= hashes.drop(1).reject do |hash| - report_name = "#{hash.file}-#{hash.line}" - reports.include?(report_name).tap do - reports.add(report_name) - end - end + @other_locations ||= hashes.drop(1) end def name diff --git a/spec/cc/engine/analyzers/javascript/main_spec.rb b/spec/cc/engine/analyzers/javascript/main_spec.rb index 649eafb2..5cb46b8a 100644 --- a/spec/cc/engine/analyzers/javascript/main_spec.rb +++ b/spec/cc/engine/analyzers/javascript/main_spec.rb @@ -65,11 +65,6 @@ result = run_engine(engine_conf).strip issues = result.split("\0") - - first_issue = issues.first - json = JSON.parse(first_issue) - - expect(json["other_locations"].length).to eq(0) expect(issues.length).to eq 1 end From 8b66e4c4dea8b143938faf68ac448c19c5987213 Mon Sep 17 00:00:00 2001 From: GordonDiggs Date: Tue, 10 Nov 2015 11:26:13 -0500 Subject: [PATCH 2/2] Be sure to drop current_sexp from the hashes It's not always the first in `hashes`, but `current_sexp` uses the first of the sorted array, so dropping that one is safe. Covered by tests here: https://github.com/codeclimate/codeclimate-duplication/blob/master/spec/cc/engine/analyzers/javascript/main_spec.rb#L41-42 --- lib/cc/engine/analyzers/violation.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cc/engine/analyzers/violation.rb b/lib/cc/engine/analyzers/violation.rb index 17b0baa6..ae68eac3 100644 --- a/lib/cc/engine/analyzers/violation.rb +++ b/lib/cc/engine/analyzers/violation.rb @@ -43,7 +43,7 @@ def sorted_hashes end def other_sexps - @other_locations ||= hashes.drop(1) + @other_locations ||= sorted_hashes.drop(1) end def name