Skip to content

Commit 6acf02c

Browse files
committed
Nested control aka too many return statements
1 parent b7f0d51 commit 6acf02c

File tree

2 files changed

+111
-1
lines changed

2 files changed

+111
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using System;
2+
3+
public class Main
4+
{
5+
public static void NotNested(string foo, string bar)
6+
{
7+
if ((foo == "cat" && bar == "dog") || (foo == "dog" && bar == "cat"))
8+
{
9+
Console.WriteLine("Got a cat and a dog!");
10+
}
11+
else
12+
{
13+
Console.WriteLine("Got nothing");
14+
}
15+
}
16+
17+
public static void F0(bool bar, bool baz, bool qux, bool quux)
18+
{
19+
if (bar)
20+
{
21+
if (baz)
22+
{
23+
if (qux)
24+
{
25+
if (quux)
26+
{
27+
Console.WriteLine("Not deeply nested enough!");
28+
}
29+
}
30+
}
31+
}
32+
}
33+
34+
public static string F2(int foo)
35+
{
36+
switch (foo)
37+
{
38+
case 1:
39+
return "bar1";
40+
case 2:
41+
return "bar2";
42+
case 3:
43+
return "bar3";
44+
case 4:
45+
return "bar4";
46+
case 5:
47+
return "bar5";
48+
case 6:
49+
return "bar6";
50+
case 7:
51+
return "bar7";
52+
case 8:
53+
return "bar8";
54+
case 9:
55+
return "bar9";
56+
case 10:
57+
return "bar10";
58+
default:
59+
throw new ArgumentException("Invalid foo value");
60+
}
61+
}
62+
}

qlty-cli/tests/lang/csharp/basic.stdout

+49-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"metadata": {
33
"buildId": "[..]",
44
"result": "ANALYSIS_RESULT_SUCCESS",
5-
"filesAnalyzed": 5,
5+
"filesAnalyzed": 6,
66
"startTime": "[..]",
77
"finishTime": "[..]",
88
"commitMessage": "initial/n",
@@ -240,6 +240,34 @@
240240
}
241241
},
242242
"mode": "MODE_BLOCK"
243+
},
244+
{
245+
"buildId": "[..]",
246+
"analyzedAt": "[..]",
247+
"tool": "qlty",
248+
"driver": "structure",
249+
"ruleKey": "return-statements",
250+
"message": "Function with many returns (count = 10): F2",
251+
"level": "LEVEL_MEDIUM",
252+
"language": "LANGUAGE_C_SHARP",
253+
"category": "CATEGORY_STRUCTURE",
254+
"snippet": "public static string F2(int foo)/n {/n switch (foo)/n {/n case 1:/n return /"bar1/";/n case 2:/n return /"bar2/";/n case 3:/n return /"bar3/";/n case 4:/n return /"bar4/";/n case 5:/n return /"bar5/";/n case 6:/n return /"bar6/";/n case 7:/n return /"bar7/";/n case 8:/n return /"bar8/";/n case 9:/n return /"bar9/";/n case 10:/n return /"bar10/";/n default:/n throw new ArgumentException(/"Invalid foo value/");/n }/n }",
255+
"snippetWithContext": " {/n if (quux)/n {/n Console.WriteLine(/"Not deeply nested enough!/");/n }/n }/n }/n }/n }/n/n public static string F2(int foo)/n {/n switch (foo)/n {/n case 1:/n return /"bar1/";/n case 2:/n return /"bar2/";/n case 3:/n return /"bar3/";/n case 4:/n return /"bar4/";/n case 5:/n return /"bar5/";/n case 6:/n return /"bar6/";/n case 7:/n return /"bar7/";/n case 8:/n return /"bar8/";/n case 9:/n return /"bar9/";/n case 10:/n return /"bar10/";/n default:/n throw new ArgumentException(/"Invalid foo value/");/n }/n }/n}",
256+
"effortMinutes": 35,
257+
"value": 10,
258+
"valueDelta": 4,
259+
"location": {
260+
"path": "NestedControl.cs",
261+
"range": {
262+
"startLine": 34,
263+
"startColumn": 5,
264+
"endLine": 61,
265+
"endColumn": 6,
266+
"startByte": 714,
267+
"endByte": 1398
268+
}
269+
},
270+
"mode": "MODE_BLOCK"
243271
}
244272
],
245273
"stats": [
@@ -342,6 +370,26 @@
342370
"complexity": 1,
343371
"cyclomatic": 3,
344372
"lcom4": 0
373+
},
374+
{
375+
"buildId": "[..]",
376+
"analyzedAt": "[..]",
377+
"name": "NestedControl.cs",
378+
"fullyQualifiedName": "NestedControl.cs",
379+
"path": "NestedControl.cs",
380+
"kind": "COMPONENT_TYPE_FILE",
381+
"language": "LANGUAGE_C_SHARP",
382+
"files": 1,
383+
"classes": 1,
384+
"functions": 3,
385+
"fields": 0,
386+
"lines": 62,
387+
"codeLines": 48,
388+
"commentLines": 0,
389+
"blankLines": 14,
390+
"complexity": 15,
391+
"cyclomatic": 24,
392+
"lcom4": 0
345393
}
346394
]
347395
}

0 commit comments

Comments
 (0)