Skip to content

Commit 5a3fad4

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 5a3fad4

File tree

12 files changed

+92
-23
lines changed

12 files changed

+92
-23
lines changed

lib/cc/engine/analyzers/analyzer_base.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ class Base
1111
::RubyParser::SyntaxError,
1212
]
1313

14+
DEFAULT_MASS_THRESHOLD = 28
15+
BASE_POINTS = 1_500_000
16+
POINTS_PER = 50_000
17+
1418
def initialize(engine_config:)
1519
@engine_config = engine_config
1620
end
@@ -37,6 +41,10 @@ def base_points
3741
self.class::BASE_POINTS
3842
end
3943

44+
def points_per
45+
self.class::POINTS_PER
46+
end
47+
4048
private
4149

4250
attr_reader :engine_config

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ class Main < CC::Engine::Analyzers::Base
1515
"**/*.jsx"
1616
]
1717
LANGUAGE = "javascript"
18-
DEFAULT_MASS_THRESHOLD = 40
19-
BASE_POINTS = 3000
2018

2119
private
2220

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ class Main < CC::Engine::Analyzers::Base
1414
"**/*.inc",
1515
"**/*.module"
1616
]
17-
DEFAULT_MASS_THRESHOLD = 10
18-
BASE_POINTS = 4_000
1917

2018
private
2119

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ 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
1715

1816
private
1917

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Main < CC::Engine::Analyzers::Base
1818

1919
]
2020
DEFAULT_MASS_THRESHOLD = 18
21-
BASE_POINTS = 10_000
21+
POINTS_PER = 100_000
2222
TIMEOUT = 300
2323

2424
private

lib/cc/engine/analyzers/violation.rb

Lines changed: 17 additions & 5 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)
12-
@base_points = base_points
11+
DEFAULT_POINTS = 1_500_000
12+
13+
def initialize(language, issue, hashes)
14+
@base_points = language.base_points
15+
@points_per = language.points_per
16+
@threshold = language.mass_threshold
1317
@issue = issue
1418
@hashes = hashes
1519
end
@@ -32,9 +36,17 @@ def report_name
3236
"#{current_sexp.file}-#{current_sexp.line}"
3337
end
3438

39+
def calculate_points
40+
if issue.mass >= threshold
41+
base_points + (overage * points_per)
42+
else
43+
DEFAULT_POINTS
44+
end
45+
end
46+
3547
private
3648

37-
attr_reader :base_points, :hashes
49+
attr_reader :base_points, :points_per, :threshold, :hashes
3850

3951
def current_sexp
4052
@location ||= sorted_hashes.first
@@ -56,8 +68,8 @@ def name
5668
end
5769
end
5870

59-
def calculate_points
60-
base_points * issue.mass
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)