Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit 637b1da

Browse files
committed
Change reported check name to match QM formatting
The config for QM uses dasherized lowercase (`identical-code`), whereas the reported check names here were more spoken language (`Identical code`). The change here changes reported check names to match what QM says & is configured via moving forward. Note this was intentionally written to *NOT* change fingerprints. The old style check names are still calculated and used for those. This also keeps compatability with an older style of configuring checks. e.g. ``` engines: duplication: checks: Similar code: enabled: false ``` That style of config is deprecated, for QM checks/engines, but the implementation here will still use that config if present, unless it's overridden by the newer QM style.
1 parent b7226a2 commit 637b1da

File tree

11 files changed

+79
-67
lines changed

11 files changed

+79
-67
lines changed

‎lib/cc/engine/analyzers/analyzer_base.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def count_threshold
7171
end
7272

7373
def calculate_points(violation)
74-
overage = violation.mass - check_mass_threshold(violation.inner_check_name)
74+
overage = violation.mass - check_mass_threshold(violation.check_name)
7575
base_points + (overage * points_per_overage)
7676
end
7777

‎lib/cc/engine/analyzers/engine_config.rb‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@ def filters_for(language)
3636
end
3737
end
3838

39-
def identical_code_check_enabled?
40-
enabled?(IDENTICAL_CODE_CHECK)
41-
end
42-
43-
def similar_code_check_enabled?
44-
enabled?(SIMILAR_CODE_CHECK)
45-
end
46-
4739
def minimum_mass_threshold_for(language)
4840
[
4941
mass_threshold_for(language, IDENTICAL_CODE_CHECK),
@@ -52,7 +44,7 @@ def minimum_mass_threshold_for(language)
5244
end
5345

5446
def mass_threshold_for(language, check)
55-
qm_threshold = checks.fetch(check, {}).fetch("config", {})["threshold"]
47+
qm_threshold = qm_checks.fetch(check, {}).fetch("config", {})["threshold"]
5648

5749
if qm_threshold
5850
qm_threshold.to_i
@@ -91,6 +83,14 @@ def patterns_for(language, fallbacks)
9183
Array(fetch_language(language).fetch("patterns", fallbacks))
9284
end
9385

86+
def check_enabled?(violation)
87+
legacy_config = legacy_checks.fetch(violation.fingerprint_check_name, {
88+
"enabled" => true
89+
})
90+
91+
qm_checks.fetch(violation.check_name, legacy_config).fetch("enabled", true)
92+
end
93+
9494
private
9595

9696
attr_reader :config
@@ -136,12 +136,12 @@ def coerce_array_entry(entry)
136136
end
137137
end
138138

139-
def checks
140-
config.fetch("config",{}).fetch("checks", {})
139+
def legacy_checks
140+
config.fetch("checks", {})
141141
end
142142

143-
def enabled?(check)
144-
checks.fetch(check, {}).fetch("enabled", true)
143+
def qm_checks
144+
config.fetch("config", {}).fetch("checks", {})
145145
end
146146
end
147147
end

‎lib/cc/engine/analyzers/reporter.rb‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -142,21 +142,13 @@ def skip?(violation)
142142
end
143143

144144
def below_threshold?(violation)
145-
violation.mass < language_strategy.check_mass_threshold(violation.inner_check_name)
145+
violation.mass < language_strategy.check_mass_threshold(violation.check_name)
146146
end
147147

148148
def insufficient_occurrence?(violation)
149149
(violation.occurrences + 1) < language_strategy.count_threshold
150150
end
151151

152-
def check_disabled?(violation)
153-
if violation.identical?
154-
!engine_config.identical_code_check_enabled?
155-
else
156-
!engine_config.similar_code_check_enabled?
157-
end
158-
end
159-
160152
def skip?(violation)
161153
insufficient_occurrence?(violation) || check_disabled?(violation)
162154
end
@@ -166,11 +158,7 @@ def insufficient_occurrence?(violation)
166158
end
167159

168160
def check_disabled?(violation)
169-
if violation.identical?
170-
!engine_config.identical_code_check_enabled?
171-
else
172-
!engine_config.similar_code_check_enabled?
173-
end
161+
!engine_config.check_enabled?(violation)
174162
end
175163
end
176164
end

‎lib/cc/engine/analyzers/violation.rb‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,18 @@ def identical?
5050
@identical
5151
end
5252

53-
def inner_check_name
54-
ifidentical?
55-
EngineConfig::IDENTICAL_CODE_CHECK
56-
else
57-
EngineConfig::SIMILAR_CODE_CHECK
58-
end
53+
def check_name
54+
"#{duplication_type}-code"
55+
end
56+
57+
deffingerprint_check_name
58+
"#{duplication_type.capitalize} code"
5959
end
6060

6161
private
6262

6363
attr_reader :language_strategy, :other_sexps, :current_sexp
6464

65-
def check_name
66-
"#{duplication_type.capitalize} code"
67-
end
68-
6965
def calculate_points
7066
@calculate_points ||= language_strategy.calculate_points(self)
7167
end
@@ -109,7 +105,7 @@ def fingerprint
109105
digest << "-"
110106
digest << current_sexp.mass.to_s
111107
digest << "-"
112-
digest << check_name
108+
digest << fingerprint_check_name
113109
digest.to_s
114110
end
115111

‎spec/cc/engine/analyzers/engine_config_spec.rb‎

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -336,43 +336,71 @@
336336
end
337337
end
338338

339-
describe "#similar_code_check_enabled?" do
340-
it "returns false when similarcode check set to false" do
339+
describe "#check_enabled?" do
340+
it "returns false for similar-code check when disabled" do
341341
engine_config = stub_qm_config(similar: false)
342342

343-
expect(engine_config).not_to be_similar_code_check_enabled
343+
violation = double(check_name: "similar-code", fingerprint_check_name: "Similar code")
344+
expect(engine_config.check_enabled?(violation)).to eq(false)
344345
end
345346

346-
it "returns true when similarcode check set to true" do
347+
it "returns true for similar-code check when enabled" do
347348
engine_config = stub_qm_config(similar: true)
348349

349-
expect(engine_config).to be_similar_code_check_enabled
350+
violation = double(check_name: "similar-code", fingerprint_check_name: "Similar code")
351+
expect(engine_config.check_enabled?(violation)).to eq(true)
352+
end
353+
354+
it "respects legacy config when present" do
355+
engine_config = described_class.new(
356+
"checks" => { "Similar code" => { "enabled" => false } },
357+
"config" => {
358+
"checks" => { "identical-code" => { "enabled" => true } },
359+
},
360+
)
361+
362+
violation = double(check_name: "similar-code", fingerprint_check_name: "Similar code")
363+
expect(engine_config.check_enabled?(violation)).to eq(false)
364+
end
365+
366+
it "overrides legacy config when both present" do
367+
engine_config = described_class.new(
368+
"checks" => { "Similar code" => { "enabled" => false } },
369+
"config" => {
370+
"checks" => { "similar-code" => { "enabled" => false } },
371+
},
372+
)
373+
374+
violation = double(check_name: "similar-code", fingerprint_check_name: "Similar code")
375+
expect(engine_config.check_enabled?(violation)).to eq(false)
350376
end
351377

352378
it "returns true by default" do
353379
engine_config = described_class.new({ "config" => {} })
354380

355-
expect(engine_config).to be_similar_code_check_enabled
381+
violation = double(check_name: "similar-code", fingerprint_check_name: "Similar code")
382+
expect(engine_config.check_enabled?(violation)).to eq(true)
356383
end
357-
end
358384

359-
describe "#identical_code_check_enabled?" do
360-
it "returns false when identical code check set to false" do
385+
it "returns false for identical-code check when disabled" do
361386
engine_config = stub_qm_config(identical: false)
362387

363-
expect(engine_config).not_to be_identical_code_check_enabled
388+
violation = double(check_name: "identical-code", fingerprint_check_name: "Identical code")
389+
expect(engine_config.check_enabled?(violation)).to eq(false)
364390
end
365391

366-
it "returns true when identicalcode check set to true" do
392+
it "returns true for identical-code check when enabled" do
367393
engine_config = stub_qm_config(identical: true)
368394

369-
expect(engine_config).to be_identical_code_check_enabled
395+
violation = double(check_name: "identical-code", fingerprint_check_name: "Identical code")
396+
expect(engine_config.check_enabled?(violation)).to eq(true)
370397
end
371398

372399
it "returns true by default" do
373400
engine_config = described_class.new({ "config" => {} })
374401

375-
expect(engine_config).to be_identical_code_check_enabled
402+
violation = double(check_name: "identical-code", fingerprint_check_name: "Identical code")
403+
expect(engine_config.check_enabled?(violation)).to eq(true)
376404
end
377405
end
378406

‎spec/cc/engine/analyzers/java/java_spec.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ module CC::Engine::Analyzers
5252
json = JSON.parse(result)
5353

5454
expect(json["type"]).to eq("issue")
55-
expect(json["check_name"]).to eq("Similar code")
55+
expect(json["check_name"]).to eq("similar-code")
5656
expect(json["description"]).to eq("Similar blocks of code found in 2 locations. Consider refactoring.")
5757
expect(json["categories"]).to eq(["Duplication"])
5858
expect(json["location"]).to eq({
@@ -94,7 +94,7 @@ module CC::Engine::Analyzers
9494
json = JSON.parse(result)
9595

9696
expect(json["type"]).to eq("issue")
97-
expect(json["check_name"]).to eq("Identical code")
97+
expect(json["check_name"]).to eq("identical-code")
9898
expect(json["description"]).to eq("Identical blocks of code found in 2 locations. Consider refactoring.")
9999
expect(json["categories"]).to eq(["Duplication"])
100100
expect(json["location"]).to eq({

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
json = JSON.parse(result)
2121

2222
expect(json["type"]).to eq("issue")
23-
expect(json["check_name"]).to eq("Identical code")
23+
expect(json["check_name"]).to eq("identical-code")
2424
expect(json["description"]).to eq("Identical blocks of code found in 3 locations. Consider refactoring.")
2525
expect(json["categories"]).to eq(["Duplication"])
2626
expect(json["location"]).to eq({
@@ -49,7 +49,7 @@
4949
json = JSON.parse(result)
5050

5151
expect(json["type"]).to eq("issue")
52-
expect(json["check_name"]).to eq("Similar code")
52+
expect(json["check_name"]).to eq("similar-code")
5353
expect(json["description"]).to eq("Similar blocks of code found in 3 locations. Consider refactoring.")
5454
expect(json["categories"]).to eq(["Duplication"])
5555
expect(json["location"]).to eq({

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
json = JSON.parse(result)
3535

3636
expect(json["type"]).to eq("issue")
37-
expect(json["check_name"]).to eq("Identical code")
37+
expect(json["check_name"]).to eq("identical-code")
3838
expect(json["description"]).to eq("Identical blocks of code found in 2 locations. Consider refactoring.")
3939
expect(json["categories"]).to eq(["Duplication"])
4040
expect(json["location"]).to eq({
@@ -76,7 +76,7 @@
7676
json = JSON.parse(result)
7777

7878
expect(json["type"]).to eq("issue")
79-
expect(json["check_name"]).to eq("Similar code")
79+
expect(json["check_name"]).to eq("similar-code")
8080
expect(json["description"]).to eq("Similar blocks of code found in 2 locations. Consider refactoring.")
8181
expect(json["categories"]).to eq(["Duplication"])
8282
expect(json["location"]).to eq({

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
json = JSON.parse(result)
2020

2121
expect(json["type"]).to eq("issue")
22-
expect(json["check_name"]).to eq("Identical code")
22+
expect(json["check_name"]).to eq("identical-code")
2323
expect(json["description"]).to eq("Identical blocks of code found in 3 locations. Consider refactoring.")
2424
expect(json["categories"]).to eq(["Duplication"])
2525
expect(json["location"]).to eq({
@@ -48,7 +48,7 @@
4848
json = JSON.parse(result)
4949

5050
expect(json["type"]).to eq("issue")
51-
expect(json["check_name"]).to eq("Similar code")
51+
expect(json["check_name"]).to eq("similar-code")
5252
expect(json["description"]).to eq("Similar blocks of code found in 3 locations. Consider refactoring.")
5353
expect(json["categories"]).to eq(["Duplication"])
5454
expect(json["location"]).to eq({
@@ -92,7 +92,7 @@ def c(thing: str):
9292
json = JSON.parse(result)
9393

9494
expect(json["type"]).to eq("issue")
95-
expect(json["check_name"]).to eq("Similar code")
95+
expect(json["check_name"]).to eq("similar-code")
9696
expect(json["description"]).to eq("Similar blocks of code found in 3 locations. Consider refactoring.")
9797
expect(json["categories"]).to eq(["Duplication"])
9898
expect(json["location"]).to eq({

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def self.from_remediation_amount(amount)
9292
json = JSON.parse(result)
9393

9494
expect(json["type"]).to eq("issue")
95-
expect(json["check_name"]).to eq("Similar code")
95+
expect(json["check_name"]).to eq("similar-code")
9696
expect(json["description"]).to eq("Similar blocks of code found in 2 locations. Consider refactoring.")
9797
expect(json["categories"]).to eq(["Duplication"])
9898
expect(json["location"]).to eq({
@@ -220,7 +220,7 @@ def identical
220220
output = run_engine(config).strip.split("0円").first.strip
221221
json = JSON.parse(output)
222222

223-
expect(json["check_name"]).to eq "Identical code"
223+
expect(json["check_name"]).to eq "identical-code"
224224
expect(json["location"]).to eq({
225225
"path" => "foo.rb",
226226
"lines" => { "begin" => 2, "end" => 2 },
@@ -238,7 +238,7 @@ def identical
238238
it "calculates mass overage points" do
239239
mass = threshold + 10
240240
overage = mass - threshold
241-
violation = OpenStruct.new(mass: mass, inner_check_name: "identical-code")
241+
violation = OpenStruct.new(mass: mass, check_name: "identical-code")
242242

243243
expected_points = base_points + overage * points_per
244244
points = analyzer.calculate_points(violation)
@@ -251,7 +251,7 @@ def identical
251251
it "calculates mass overage points" do
252252
mass = threshold - 5
253253
overage = mass - threshold
254-
violation = OpenStruct.new(mass: mass, inner_check_name: "identical-code")
254+
violation = OpenStruct.new(mass: mass, check_name: "identical-code")
255255

256256
expected_points = base_points + overage * points_per
257257
points = analyzer.calculate_points(violation)
@@ -264,7 +264,7 @@ def identical
264264
it "calculates mass overage points" do
265265
mass = threshold
266266
overage = mass - threshold
267-
violation = OpenStruct.new(mass: mass, inner_check_name: "identical-code")
267+
violation = OpenStruct.new(mass: mass, check_name: "identical-code")
268268

269269
expected_points = base_points + overage * points_per
270270
points = analyzer.calculate_points(violation)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /