forked from jshint/jshint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
max-cyclomatic-complexity-per-function.js
90 lines (78 loc) · 1.79 KB
/
max-cyclomatic-complexity-per-function.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
function functionWithCyclomaticComplexity_1() {
}
function functionWithCyclomaticComplexity_1_2() {
var dummy = 1;
}
function functionWithCyclomaticComplexity_2() {
var dummy = 10;
if (dummy < 20) {
dummy = 2;
}
}
function functionWithCyclomaticComplexity_2() {
var dummy = 10;
if (dummy < 20) {
dummy = 2;
} else {
// else does not count for cyclomatic complexity
dummy = 2;
}
}
function functionWithCyclomaticComplexity_2_try_catch() {
var dummy = 0;
try {
dummy = dummy / 0;
} catch (exception) {
dummy = 10;
} finally {
// finally does no count
dummy = 10;
}
}
function functionWithCyclomaticComplexity_1_try_finally() {
var dummy = 0;
try {
dummy = dummy / 0;
} finally {
// finally does no count
dummy = 10;
}
}
function functionWithCyclomaticComplexity_8() {
var dummy = 10;
if (dummy < 20) {
while (dummy > 0) {
dummy -= 1;
}
for (dummy = 1; dummy < 10; dummy++) {
dummy += 1;
}
} else if (dummy<100) {
dummy = 2;
} else {
// else does not count for cyclomatic complexity
dummy = 2;
}
do {
dummy++;
} while (dummy < 1000);
switch (dummy) {
case 1:
break;
case 2: break;
// default does not count
default :
}
}
function functionWithCyclomaticComplexityDueToTernaryStatements_2(a) {
var b = a ? true : false;
}
function functionWithCyclomaticComplexityDueToOrOperators_2(a) {
var b = a || {};
}
function functionWithCyclomaticComplexityDueToAndOperators_2(a) {
var b = a && {};
}
function functionWithCyclomaticComplexityDueToAndOperatorsWithNot_2(a) {
var b = !(!a && {});
}