Skip to content

Commit 771cf09

Browse files
author
ABaldwinHunter
committed
Tune remediation points to match Classic
Changes include: - Update PHP, Python, and JavaScript thresholds to match Classic - Increase base_points for all four languages - Add `points_per` value to each language - change calculation formula from - `base_points * issue.mass_threshold` to - `base_points + overage * points_per` Reference to rubric in classic for PHP, Ruby and JavaScript: https://github.com/codeclimate/analyzer/blob/master/lib/quality/rubric.rb#L12c And python: https://github.com/codeclimate/analyzer/blob/master/lib/quality/profile.rb#L41
1 parent 371a7cf commit 771cf09

File tree

11 files changed

+44
-16
lines changed

11 files changed

+44
-16
lines changed

lib/cc/engine/analyzers/analyzer_base.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ def base_points
3737
self.class::BASE_POINTS
3838
end
3939

40+
def points_per
41+
self.class::POINTS_PER
42+
end
43+
4044
private
4145

4246
attr_reader :engine_config

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ class Main < CC::Engine::Analyzers::Base
1515
"**/*.jsx"
1616
]
1717
LANGUAGE = "javascript"
18-
DEFAULT_MASS_THRESHOLD = 40
19-
BASE_POINTS = 3000
18+
DEFAULT_MASS_THRESHOLD = 28
19+
BASE_POINTS = 1_500_000
20+
POINTS_PER = 50_000
2021

2122
private
2223

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ class Main < CC::Engine::Analyzers::Base
1414
"**/*.inc",
1515
"**/*.module"
1616
]
17-
DEFAULT_MASS_THRESHOLD = 10
18-
BASE_POINTS = 4_000
17+
DEFAULT_MASS_THRESHOLD = 28
18+
BASE_POINTS = 1_500_000
19+
POINTS_PER = 50_000
1920

2021
private
2122

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ module Python
1212
class Main < CC::Engine::Analyzers::Base
1313
LANGUAGE = "python"
1414
DEFAULT_PATHS = ["**/*.py"]
15-
DEFAULT_MASS_THRESHOLD = 40
16-
BASE_POINTS = 1000
15+
DEFAULT_MASS_THRESHOLD = 28
16+
BASE_POINTS = 1_500_000
17+
POINTS_PER = 50_000
1718

1819
private
1920

lib/cc/engine/analyzers/reporter.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,17 @@ def mass_threshold
6464
@mass_threshold ||= language_strategy.mass_threshold
6565
end
6666

67+
def base_points
68+
@base_points ||= language_strategy.base_points
69+
end
70+
71+
def points_per
72+
@points_per ||= language_strategy.points_per
73+
end
74+
6775
def new_violation(issue)
6876
hashes = flay.hashes[issue.structural_hash]
69-
Violation.new(language_strategy.base_points, issue, hashes)
77+
Violation.new(base_points, points_per, mass_threshold, issue, hashes)
7078
end
7179

7280
def flay_options

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ 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 = 100_000
2223
TIMEOUT = 300
2324

2425
private

lib/cc/engine/analyzers/violation.rb

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

11-
def initialize(base_points, issue, hashes)
11+
DEFAULT_POINTS = 1_500_000
12+
13+
def initialize(base_points, points_per, threshold, issue, hashes)
1214
@base_points = base_points
15+
@points_per = points_per
16+
@threshold = threshold
1317
@issue = issue
1418
@hashes = hashes
1519
end
@@ -34,7 +38,7 @@ def report_name
3438

3539
private
3640

37-
attr_reader :base_points, :hashes
41+
attr_reader :base_points, :points_per, :threshold, :hashes
3842

3943
def current_sexp
4044
@location ||= sorted_hashes.first
@@ -57,7 +61,15 @@ def name
5761
end
5862

5963
def calculate_points
60-
base_points * issue.mass
64+
if issue.mass > threshold
65+
base_points + overage * points_per
66+
else
67+
DEFAULT_POINTS
68+
end
69+
end
70+
71+
def overage
72+
issue.mass - threshold
6173
end
6274

6375
def format_location

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"path" => "foo.js",
2929
"lines" => { "begin" => 1, "end" => 1 },
3030
})
31-
expect(json["remediation_points"]).to eq(297000)
31+
expect(json["remediation_points"]).to eq(6400000)
3232
expect(json["other_locations"]).to eq([
3333
{"path" => "foo.js", "lines" => { "begin" => 2, "end" => 2} },
3434
{"path" => "foo.js", "lines" => { "begin" => 3, "end" => 3} }

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"path" => "foo.php",
4242
"lines" => { "begin" => 2, "end" => 6 },
4343
})
44-
expect(json["remediation_points"]).to eq(176000)
44+
expect(json["remediation_points"]).to eq(3450000)
4545
expect(json["other_locations"]).to eq([
4646
{"path" => "foo.php", "lines" => { "begin" => 10, "end" => 14} },
4747
])
@@ -61,7 +61,7 @@
6161
end
6262

6363
def printed_issue
64-
issue = {"type":"issue","check_name":"Identical code","description":"Similar code found in 1 other location","categories":["Duplication"],"location":{"path":"foo.php","lines":{"begin":2,"end":6}},"remediation_points":176000,"other_locations":[{"path":"foo.php","lines":{"begin":10,"end":14}}],"content":{"body": read_up}}
64+
issue = {"type":"issue","check_name":"Identical code","description":"Similar code found in 1 other location","categories":["Duplication"],"location":{"path":"foo.php","lines":{"begin":2,"end":6}},"remediation_points":3450000,"other_locations":[{"path":"foo.php","lines":{"begin":10,"end":14}}],"content":{"body": read_up}}
6565
issue.to_json + "\0\n"
6666
end
6767

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"path" => "foo.py",
2929
"lines" => { "begin" => 1, "end" => 1 },
3030
})
31-
expect(json["remediation_points"]).to eq(54000)
31+
expect(json["remediation_points"]).to eq(4000000)
3232
expect(json["other_locations"]).to eq([
3333
{"path" => "foo.py", "lines" => { "begin" => 2, "end" => 2} },
3434
{"path" => "foo.py", "lines" => { "begin" => 3, "end" => 3} }

0 commit comments

Comments
 (0)