Skip to content

Commit 76c612d

Browse files
ivandalboscovilchik-elena
authored andcommitted
SONARPY-188 Reduce the threshold of function cyclomatic complexity check (#75)
1 parent f22d75c commit 76c612d

File tree

4 files changed

+189
-1
lines changed

4 files changed

+189
-1
lines changed

its/ruling/src/test/resources/expected/python-FunctionComplexity.json

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
'project:buildbot-0.8.6p1/buildbot/changes/mail.py':[
33
82,
4+
273,
5+
409,
46
],
57
'project:buildbot-0.8.6p1/buildbot/changes/p4poller.py':[
68
101,
@@ -17,24 +19,53 @@
1719
'project:buildbot-0.8.6p1/buildbot/scripts/runner.py':[
1820
1143,
1921
],
22+
'project:buildbot-0.8.6p1/buildbot/status/builder.py':[
23+
352,
24+
],
25+
'project:buildbot-0.8.6p1/buildbot/status/logfile.py':[
26+
445,
27+
],
2028
'project:buildbot-0.8.6p1/buildbot/status/mail.py':[
2129
69,
30+
169,
31+
402,
2232
],
2333
'project:buildbot-0.8.6p1/buildbot/status/web/build.py':[
2434
144,
2535
],
36+
'project:buildbot-0.8.6p1/buildbot/status/web/console.py':[
37+
413,
38+
],
39+
'project:buildbot-0.8.6p1/buildbot/status/web/feeds.py':[
40+
169,
41+
],
2642
'project:buildbot-0.8.6p1/buildbot/status/web/waterfall.py':[
43+
229,
2744
534,
2845
689,
2946
],
3047
'project:buildbot-0.8.6p1/buildbot/steps/python_twisted.py':[
3148
209,
3249
409,
50+
503,
51+
],
52+
'project:buildbot-0.8.6p1/buildbot/steps/shell.py':[
53+
462,
54+
652,
55+
],
56+
'project:buildbot-0.8.6p1/buildbot/steps/subunit.py':[
57+
36,
58+
],
59+
'project:buildbot-0.8.6p1/buildbot/test/fake/fakedb.py':[
60+
880,
3361
],
3462
'project:buildbot-slave-0.8.6p1/buildslave/runprocess.py':[
63+
232,
3564
395,
3665
],
3766
'project:django-1.4/django/contrib/admin/options.py':[
67+
924,
68+
1012,
3869
1103,
3970
],
4071
'project:django-1.4/django/contrib/admin/templatetags/admin_list.py':[
@@ -44,18 +75,43 @@
4475
14,
4576
262,
4677
],
78+
'project:django-1.4/django/contrib/admin/views/main.py':[
79+
80,
80+
],
81+
'project:django-1.4/django/contrib/auth/management/commands/createsuperuser.py':[
82+
46,
83+
],
84+
'project:django-1.4/django/contrib/contenttypes/views.py':[
85+
7,
86+
],
4787
'project:django-1.4/django/contrib/gis/db/backends/postgis/operations.py':[
4888
483,
4989
],
5090
'project:django-1.4/django/contrib/gis/db/models/query.py':[
5191
571,
5292
],
93+
'project:django-1.4/django/contrib/localflavor/id/forms.py':[
94+
115,
95+
],
96+
'project:django-1.4/django/contrib/staticfiles/management/commands/collectstatic.py':[
97+
134,
98+
],
99+
'project:django-1.4/django/core/handlers/base.py':[
100+
72,
101+
],
102+
'project:django-1.4/django/core/management/commands/dumpdata.py':[
103+
30,
104+
119,
105+
],
53106
'project:django-1.4/django/core/management/commands/inspectdb.py':[
54107
27,
55108
],
56109
'project:django-1.4/django/core/management/commands/loaddata.py':[
57110
37,
58111
],
112+
'project:django-1.4/django/core/management/commands/makemessages.py':[
113+
263,
114+
],
59115
'project:django-1.4/django/core/management/commands/syncdb.py':[
60116
24,
61117
],
@@ -65,35 +121,93 @@
65121
'project:django-1.4/django/core/management/validation.py':[
66122
16,
67123
],
124+
'project:django-1.4/django/core/servers/fastcgi.py':[
125+
90,
126+
],
68127
'project:django-1.4/django/db/backends/creation.py':[
69128
31,
70129
],
130+
'project:django-1.4/django/db/backends/oracle/base.py':[
131+
151,
132+
],
71133
'project:django-1.4/django/db/models/base.py':[
72134
32,
135+
278,
73136
467,
137+
642,
138+
],
139+
'project:django-1.4/django/db/models/deletion.py':[
140+
225,
74141
],
75142
'project:django-1.4/django/db/models/query.py':[
143+
165,
76144
231,
77145
1240,
146+
1339,
147+
1579,
78148
],
79149
'project:django-1.4/django/db/models/sql/compiler.py':[
80150
53,
151+
333,
81152
573,
82153
],
83154
'project:django-1.4/django/db/models/sql/query.py':[
84155
443,
156+
559,
157+
741,
85158
1030,
159+
1219,
86160
1270,
87161
],
162+
'project:django-1.4/django/db/models/sql/where.py':[
163+
130,
164+
],
165+
'project:django-1.4/django/forms/forms.py':[
166+
141,
167+
],
168+
'project:django-1.4/django/forms/models.py':[
169+
133,
170+
502,
171+
],
172+
'project:django-1.4/django/http/multipartparser.py':[
173+
92,
174+
],
175+
'project:django-1.4/django/middleware/common.py':[
176+
35,
177+
],
178+
'project:django-1.4/django/template/base.py':[
179+
885,
180+
],
181+
'project:django-1.4/django/templatetags/i18n.py':[
182+
361,
183+
],
88184
'project:django-1.4/django/test/_doctest.py':[
89185
875,
186+
1177,
187+
],
188+
'project:django-1.4/django/utils/dictconfig.py':[
189+
272,
90190
],
91191
'project:django-1.4/django/utils/html.py':[
92192
123,
93193
],
194+
'project:django-1.4/django/utils/ipv6.py':[
195+
143,
196+
],
197+
'project:django-1.4/django/utils/numberformat.py':[
198+
5,
199+
],
200+
'project:django-1.4/django/utils/regex_helper.py':[
201+
42,
202+
286,
203+
],
94204
'project:django-1.4/django/utils/translation/trans_real.py':[
205+
366,
95206
449,
96207
],
208+
'project:django-1.4/django/utils/unittest/main.py':[
209+
114,
210+
],
97211
'project:django-1.4/django/views/decorators/http.py':[
98212
78,
99213
],
@@ -102,21 +216,32 @@
102216
],
103217
'project:tornado-2.3/demos/appengine/markdown.py':[
104218
279,
219+
441,
105220
828,
106221
1578,
222+
1758,
107223
],
108224
'project:tornado-2.3/demos/blog/markdown.py':[
109225
279,
226+
441,
110227
828,
111228
1578,
229+
1758,
112230
],
113231
'project:tornado-2.3/tornado/curl_httpclient.py':[
114232
275,
115233
],
234+
'project:tornado-2.3/tornado/escape.py':[
235+
271,
236+
],
237+
'project:tornado-2.3/tornado/ioloop.py':[
238+
251,
239+
],
116240
'project:tornado-2.3/tornado/locale.py':[
117241
261,
118242
],
119243
'project:tornado-2.3/tornado/simple_httpclient.py':[
244+
128,
120245
237,
121246
],
122247
'project:tornado-2.3/tornado/template.py':[
@@ -125,21 +250,63 @@
125250
'project:tornado-2.3/tornado/web.py':[
126251
496,
127252
],
253+
'project:twisted-12.1.0/twisted/conch/ls.py':[
254+
16,
255+
],
256+
'project:twisted-12.1.0/twisted/conch/scripts/tkconch.py':[
257+
112,
258+
],
259+
'project:twisted-12.1.0/twisted/internet/defer.py':[
260+
476,
261+
],
262+
'project:twisted-12.1.0/twisted/internet/process.py':[
263+
719,
264+
],
265+
'project:twisted-12.1.0/twisted/mail/imap4.py':[
266+
3916,
267+
],
128268
'project:twisted-12.1.0/twisted/mail/scripts/mailmail.py':[
129269
62,
130270
],
271+
'project:twisted-12.1.0/twisted/mail/smtp.py':[
272+
372,
273+
],
274+
'project:twisted-12.1.0/twisted/names/authority.py':[
275+
78,
276+
],
277+
'project:twisted-12.1.0/twisted/names/common.py':[
278+
220,
279+
],
131280
'project:twisted-12.1.0/twisted/python/failure.py':[
132281
170,
133282
],
134283
'project:twisted-12.1.0/twisted/python/rebuild.py':[
135284
130,
136285
],
137286
'project:twisted-12.1.0/twisted/python/usage.py':[
287+
210,
138288
859,
139289
],
290+
'project:twisted-12.1.0/twisted/python/util.py':[
291+
935,
292+
],
140293
'project:twisted-12.1.0/twisted/spread/jelly.py':[
141294
468,
142295
],
296+
'project:twisted-12.1.0/twisted/test/iosim.py':[
297+
213,
298+
],
299+
'project:twisted-12.1.0/twisted/web/http.py':[
300+
889,
301+
],
302+
'project:twisted-12.1.0/twisted/web/microdom.py':[
303+
546,
304+
799,
305+
872,
306+
],
307+
'project:twisted-12.1.0/twisted/web/template.py':[
308+
169,
309+
],
143310
'project:twisted-12.1.0/twisted/words/xish/domish.py':[
144311
58,
145312
],

python-checks/src/main/java/org/sonar/python/checks/FunctionComplexityCheck.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
effortToFixDescription = "per complexity point above the threshold")
4343
@ActivatedByDefault
4444
public class FunctionComplexityCheck extends PythonCheck {
45-
private static final int DEFAULT_MAXIMUM_FUNCTION_COMPLEXITY_THRESHOLD = 20;
45+
private static final int DEFAULT_MAXIMUM_FUNCTION_COMPLEXITY_THRESHOLD = 15;
4646
private static final String MESSAGE = "Function has a complexity of %s which is greater than %s authorized.";
4747

4848
@RuleProperty(

python-checks/src/test/java/org/sonar/python/checks/FunctionComplexityCheckTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,10 @@ public void test() {
3131
PythonCheckVerifier.verify("src/test/resources/checks/functionComplexity.py", check);
3232
}
3333

34+
@Test
35+
public void test_with_default_threshold() {
36+
FunctionComplexityCheck check = new FunctionComplexityCheck();
37+
PythonCheckVerifier.verify("src/test/resources/checks/functionComplexityWithDefaultThreshold.py", check);
38+
}
39+
3440
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
def hello1(): # Noncompliant {{Function has a complexity of 16 which is greater than 15 authorized.}}
2+
if (1 == 2 and 1 == 2 and 1 == 2 and 1 == 2 and 1 == 2):
3+
pass
4+
if (1 == 2 and 1 == 2 and 1 == 2 and 1 == 2 and 1 == 2):
5+
pass
6+
if (1 == 2 and 1 == 2 and 1 == 2 and 1 == 2 and 1 == 2):
7+
pass
8+
return
9+
10+
def hello2(): # OK, complexity is 11
11+
if (1 == 2 and 1 == 2 and 1 == 2 and 1 == 2 and 1 == 2):
12+
pass
13+
if (1 == 2 and 1 == 2 and 1 == 2 and 1 == 2 and 1 == 2):
14+
pass
15+
return

0 commit comments

Comments
 (0)