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

Commit 6688279

Browse files
author
ABaldwinHunter
committed
Tune RUBY remediation points to match Classic
Changes include: - Refactor `calculate_points` method to be purview of language, not `Violation` - to permit independent calculation formulas - Increase ruby `BASE_POINTS` - Change calculation formula from - `base_points * issue.mass_threshold` to - `base_points + overage * points_per` Rubric in classic for Ruby: https://github.com/codeclimate/analyzer/blob/master/lib/quality/rubric.rb#L12c Updates for other languages to come post additional language-specific tuning
1 parent e2e8034 commit 6688279

File tree

5 files changed

+62
-14
lines changed

5 files changed

+62
-14
lines changed

lib/cc/engine/analyzers/analyzer_base.rb

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

38-
def base_points
39-
self.class::BASE_POINTS
38+
def calculate_points(issue)
39+
self.class::BASE_POINTS * issue.mass
4040
end
4141

4242
private

lib/cc/engine/analyzers/reporter.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,15 @@ def flay
6060

6161
attr_reader :engine_config, :language_strategy, :io
6262

63-
def mass_threshold
64-
@mass_threshold ||= language_strategy.mass_threshold
65-
end
66-
6763
def new_violation(issue)
6864
hashes = flay.hashes[issue.structural_hash]
69-
Violation.new(language_strategy.base_points, issue, hashes)
65+
Violation.new(language_strategy, issue, hashes)
7066
end
7167

7268
def flay_options
7369
{
7470
diff: false,
75-
mass: mass_threshold,
71+
mass: language_strategy.mass_threshold,
7672
summary: false,
7773
verbose: false,
7874
number: true,

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,20 @@ class Main < CC::Engine::Analyzers::Base
1818

1919
]
2020
DEFAULT_MASS_THRESHOLD = 18
21-
BASE_POINTS = 10_000
21+
BASE_POINTS = 1_500_000
22+
POINTS_PER_OVERAGE = 100_000
2223
TIMEOUT = 300
2324

25+
def calculate_points(issue)
26+
BASE_POINTS + (overage(issue) * POINTS_PER_OVERAGE)
27+
end
28+
2429
private
2530

31+
def overage(issue)
32+
issue.mass - mass_threshold
33+
end
34+
2635
def process_file(file)
2736
RubyParser.new.process(File.binread(file), file, TIMEOUT)
2837
end

lib/cc/engine/analyzers/violation.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ module Analyzers
88
class Violation
99
attr_reader :issue
1010

11-
def initialize(base_points, issue, hashes)
12-
@base_points = base_points
11+
def initialize(language, issue, hashes)
12+
@language = language
1313
@issue = issue
1414
@hashes = hashes
1515
end
@@ -34,7 +34,7 @@ def report_name
3434

3535
private
3636

37-
attr_reader :base_points, :hashes
37+
attr_reader :language, :hashes
3838

3939
def current_sexp
4040
@location ||= sorted_hashes.first
@@ -57,7 +57,7 @@ def name
5757
end
5858

5959
def calculate_points
60-
base_points * issue.mass
60+
language.calculate_points(issue)
6161
end
6262

6363
def format_location

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

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"path" => "foo.rb",
3939
"lines" => { "begin" => 1, "end" => 5 },
4040
})
41-
expect(json["remediation_points"]).to eq(360000)
41+
expect(json["remediation_points"]).to eq(3300000)
4242
expect(json["other_locations"]).to eq([
4343
{"path" => "foo.rb", "lines" => { "begin" => 9, "end" => 13} },
4444
])
@@ -57,6 +57,49 @@
5757
end
5858
end
5959

60+
describe "#calculate_points(issue)" do
61+
let(:ruby) { CC::Engine::Analyzers::Ruby::Main.new(engine_config: engine_conf) }
62+
let(:base_points) { CC::Engine::Analyzers::Ruby::Main::BASE_POINTS }
63+
let(:points_per) { CC::Engine::Analyzers::Ruby::Main::POINTS_PER_OVERAGE }
64+
let(:threshold) { CC::Engine::Analyzers::Ruby::Main::DEFAULT_MASS_THRESHOLD }
65+
66+
context "when issue mass exceeds threshold" do
67+
it "calculates mass overage points" do
68+
issue = double(:issue, mass: threshold + 10)
69+
overage = issue.mass - threshold
70+
71+
expected_points = base_points + overage * points_per
72+
points = ruby.calculate_points(issue)
73+
74+
expect(points).to eq(expected_points)
75+
end
76+
end
77+
78+
context "when issue mass is less than threshold" do
79+
it "calculates mass overage points" do
80+
issue = double(:issue, mass: threshold - 5)
81+
overage = issue.mass - threshold
82+
83+
expected_points = base_points + overage * points_per
84+
points = ruby.calculate_points(issue)
85+
86+
expect(points).to eq(expected_points)
87+
end
88+
end
89+
90+
context "when issue mass equals threshold" do
91+
it "calculates mass overage points" do
92+
issue = double(:issue, mass: threshold)
93+
overage = issue.mass - threshold
94+
95+
expected_points = base_points + overage * points_per
96+
points = ruby.calculate_points(issue)
97+
98+
expect(points).to eq(expected_points)
99+
end
100+
end
101+
end
102+
60103
def engine_conf
61104
CC::Engine::Analyzers::EngineConfig.new({})
62105
end

0 commit comments

Comments
 (0)