Skip to content

Commit 8f1867e

Browse files
committed
Add configurable remediation points from yaml
This sets the default remediation points value to 200,000 and adds the `config/cops.yml` file where remediation points for an individual cop can be overridden.
1 parent de69f3a commit 8f1867e

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

config/cops.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Metrics/ClassLength: 400_000

lib/cc/engine/rubocop.rb

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
module CC
1212
module Engine
1313
class Rubocop
14+
DEFAULT_REMEDIATION_POINTS = 200_000
15+
1416
def initialize(code, engine_config, io)
1517
@code = code
1618
@engine_config = engine_config || {}
@@ -101,7 +103,7 @@ def violation_json(violation, local_path)
101103
check_name: "Rubocop/#{violation.cop_name}",
102104
description: violation.message,
103105
categories: [category(violation.cop_name)],
104-
remediation_points: 50_000,
106+
remediation_points: remediation_points_for(violation.cop_name),
105107
location: {
106108
path: local_path,
107109
positions: violation_positions(violation.location),
@@ -128,6 +130,22 @@ def cops
128130
RuboCop::Cop::Cop.non_rails
129131
end
130132
end
133+
134+
def remediation_points_for(cop_name)
135+
cop_list.fetch(cop_name, DEFAULT_REMEDIATION_POINTS)
136+
end
137+
138+
def cop_list
139+
return @cop_list if @cop_list
140+
141+
cops_path = File.expand_path(
142+
File.join(File.dirname(__FILE__), "../../../config/cops.yml")
143+
)
144+
145+
File.open(cops_path, "r") do |file|
146+
@cop_list = YAML.load(file.read)
147+
end
148+
end
131149
end
132150
end
133151
end

0 commit comments

Comments
 (0)