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 f2c3fb9

Browse files
committed
Read threshold config from QM checks key
Thresholds can be given for individual checks in QM via a standard `checks` key at top-level of `.codeclimate.{yml,json}`. The order of preference is QM checks -> legacy duplication config -> default.
1 parent d58c6ca commit f2c3fb9

File tree

3 files changed

+106
-9
lines changed

3 files changed

+106
-9
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def language
5959
end
6060

6161
def mass_threshold
62-
engine_config.mass_threshold_for(language) || self.class::DEFAULT_MASS_THRESHOLD
62+
engine_config.minimum_mass_threshold_for(language) || self.class::DEFAULT_MASS_THRESHOLD
6363
end
6464

6565
def count_threshold

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,24 @@ def similar_code_check_enabled?
4444
enabled?(SIMILAR_CODE_CHECK)
4545
end
4646

47-
def mass_threshold_for(language)
48-
threshold = fetch_language(language).fetch("mass_threshold", nil)
47+
def minimum_mass_threshold_for(language)
48+
[
49+
mass_threshold_for(language, IDENTICAL_CODE_CHECK),
50+
mass_threshold_for(language, SIMILAR_CODE_CHECK),
51+
].compact.min
52+
end
4953

50-
if threshold
51-
threshold.to_i
54+
def mass_threshold_for(language, check)
55+
qm_threshold = checks.fetch(check, {}).fetch("config", {})["threshold"]
56+
57+
if qm_threshold
58+
qm_threshold.to_i
59+
else
60+
threshold = fetch_language(language).fetch("mass_threshold", nil)
61+
62+
if threshold
63+
threshold.to_i
64+
end
5265
end
5366
end
5467

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

Lines changed: 88 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
end
9696
end
9797

98-
describe "mass_threshold_for" do
98+
describe "minimum_mass_threshold_for" do
9999
it "returns configured mass threshold as integer" do
100100
engine_config = described_class.new({
101101
"config" => {
@@ -104,10 +104,14 @@
104104
"mass_threshold" => "13",
105105
},
106106
},
107+
"checks" => {
108+
"identical-code" => {},
109+
"similar-code" => {},
110+
},
107111
},
108112
})
109113

110-
expect(engine_config.mass_threshold_for("elixir")).to eq(13)
114+
expect(engine_config.minimum_mass_threshold_for("elixir")).to eq(13)
111115
end
112116

113117
it "returns nil when language is empty" do
@@ -119,7 +123,7 @@
119123
},
120124
})
121125

122-
expect(engine_config.mass_threshold_for("ruby")).to be_nil
126+
expect(engine_config.minimum_mass_threshold_for("ruby")).to be_nil
123127
end
124128

125129
it "returns nil when language is empty via array" do
@@ -129,7 +133,87 @@
129133
},
130134
})
131135

132-
expect(engine_config.mass_threshold_for("ruby")).to be_nil
136+
expect(engine_config.minimum_mass_threshold_for("ruby")).to be_nil
137+
end
138+
139+
it "uses QM threshold when one specified" do
140+
engine_config = CC::Engine::Analyzers::EngineConfig.new({
141+
"config" => {
142+
"languages" => {
143+
"ruby" => { "mass_threshold" => 10 },
144+
},
145+
"checks" => {
146+
"identical-code" => { "config" => { "threshold" => 5 } },
147+
"similar-code" => {},
148+
},
149+
},
150+
})
151+
152+
expect(engine_config.minimum_mass_threshold_for("ruby")).to eq(5)
153+
end
154+
155+
it "uses minimum QM threshold when both specified" do
156+
engine_config = CC::Engine::Analyzers::EngineConfig.new({
157+
"config" => {
158+
"languages" => {
159+
"ruby" => { "mass_threshold" => 10 },
160+
},
161+
"checks" => {
162+
"identical-code" => { "config" => { "threshold" => 5 } },
163+
"similar-code" => { "config" => { "threshold" => 8 } },
164+
},
165+
},
166+
})
167+
168+
expect(engine_config.minimum_mass_threshold_for("ruby")).to eq(5)
169+
end
170+
end
171+
172+
describe "#mass_threshold_for" do
173+
it "gives the QM check treshold when specified" do
174+
engine_config = CC::Engine::Analyzers::EngineConfig.new({
175+
"config" => {
176+
"languages" => {
177+
"ruby" => { "mass_threshold" => 10 },
178+
},
179+
"checks" => {
180+
"identical-code" => { "config" => { "threshold" => 5 } },
181+
"similar-code" => {},
182+
},
183+
},
184+
})
185+
186+
expect(engine_config.mass_threshold_for("ruby", "identical-code")).to eq(5)
187+
end
188+
189+
it "gives the legacy language threshold when specified" do
190+
engine_config = CC::Engine::Analyzers::EngineConfig.new({
191+
"config" => {
192+
"languages" => {
193+
"ruby" => { "mass_threshold" => 10 },
194+
},
195+
"checks" => {
196+
"identical-code" => { "config" => { "threshold" => 5 } },
197+
"similar-code" => {},
198+
},
199+
},
200+
})
201+
202+
expect(engine_config.mass_threshold_for("ruby", "similar-code")).to eq(10)
203+
end
204+
205+
it "gives nil when no threshold specified" do
206+
engine_config = CC::Engine::Analyzers::EngineConfig.new({
207+
"config" => {
208+
"languages" => %w[ruby],
209+
"checks" => {
210+
"identical-code" => {},
211+
"similar-code" => {},
212+
},
213+
},
214+
})
215+
216+
expect(engine_config.mass_threshold_for("ruby", "identical-code")).to be_nil
133217
end
134218
end
135219

0 commit comments

Comments
(0)

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