Skip to content

Commit bca74b3

Browse files
author
ABaldwinHunter
committed
Use actual mass, instead of flay score
In classic: https://github.com/codeclimate/analyzer/blob/master/lib/quality/worker/jobs/smel l_duplication.rb#L30 Here, we have been using the flay score instead of actual mass: mass * num_occurrences // similar code mass * num_occurrences * num_occurrences // identical code
1 parent 9983a77 commit bca74b3

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

lib/cc/engine/analyzers/analyzer_base.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ def mass_threshold
3636
engine_config.mass_threshold_for(self.class::LANGUAGE) || self.class::DEFAULT_MASS_THRESHOLD
3737
end
3838

39-
def calculate_points(issue)
40-
self.class::BASE_POINTS * issue.mass
39+
def calculate_points(mass)
40+
self.class::BASE_POINTS * mass
4141
end
4242

4343
private

lib/cc/engine/analyzers/python/main.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ class Main < CC::Engine::Analyzers::Base
1414
DEFAULT_PATHS = ["**/*.py"]
1515
DEFAULT_MASS_THRESHOLD = 32
1616
BASE_POINTS = 1_500_000
17-
POINTS_PER_OVERAGE = 30_000
17+
POINTS_PER_OVERAGE = 50_000
1818

19-
def calculate_points(issue)
20-
BASE_POINTS + (overage(issue) * POINTS_PER_OVERAGE)
19+
def calculate_points(mass)
20+
BASE_POINTS + (overage(mass) * POINTS_PER_OVERAGE)
2121
end
2222

2323
private
2424

25-
def overage(issue)
26-
issue.mass - mass_threshold
25+
def overage(mass)
26+
mass - mass_threshold
2727
end
2828

2929
def process_file(path)

lib/cc/engine/analyzers/ruby/main.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ class Main < CC::Engine::Analyzers::Base
2222
POINTS_PER_OVERAGE = 100_000
2323
TIMEOUT = 300
2424

25-
def calculate_points(issue)
26-
BASE_POINTS + (overage(issue) * POINTS_PER_OVERAGE)
25+
def calculate_points(mass)
26+
BASE_POINTS + (overage(mass) * POINTS_PER_OVERAGE)
2727
end
2828

2929
private
3030

31-
def overage(issue)
32-
issue.mass - mass_threshold
31+
def overage(mass)
32+
mass - mass_threshold
3333
end
3434

3535
def process_file(file)

lib/cc/engine/analyzers/violation.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,18 @@ def report_name
3232
"#{current_sexp.file}-#{current_sexp.line}"
3333
end
3434

35+
def mass
36+
flay_score / occurrences # ABH Reverse engineer the actual mass.
37+
end
38+
3539
private
3640

3741
attr_reader :language_strategy, :hashes
3842

43+
def flay_score
44+
issue.mass
45+
end
46+
3947
def current_sexp
4048
@location ||= sorted_hashes.first
4149
end
@@ -57,7 +65,7 @@ def check_name
5765
end
5866

5967
def calculate_points
60-
language_strategy.calculate_points(issue)
68+
language_strategy.calculate_points(mass)
6169
end
6270

6371
def format_location
@@ -96,13 +104,13 @@ def fingerprint
96104
end
97105

98106
def description
99-
description = "#{check_name} found in #{occurrences} other location"
100-
description += "s" if occurrences > 1
107+
description = "#{check_name} found in #{occurrences - 1} other location"
108+
description += "s" if occurrences > 2
101109
description
102110
end
103111

104112
def occurrences
105-
other_sexps.count
113+
other_sexps.count + 1
106114
end
107115
end
108116
end

0 commit comments

Comments
 (0)