Skip to content

Commit

Permalink
cyclomatic-complexity: Don't count empty switch cases (palantir#2743)
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-hanson authored and adidahiya committed May 31, 2017
1 parent 14bbecb commit 3da800c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/rules/cyclomaticComplexityRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ function walk(ctx: Lint.WalkContext<{ threshold: number }>): void {
function increasesComplexity(node: ts.Node): boolean {
switch (node.kind) {
case ts.SyntaxKind.CaseClause:
return (node as ts.CaseClause).statements.length > 0;
case ts.SyntaxKind.CatchClause:
case ts.SyntaxKind.ConditionalExpression:
case ts.SyntaxKind.DoStatement:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,11 @@ function invalidBinaryExpression() {
function validSwitch() {
switch(5) {
case 0:
return 0;
case 2:
return "even";
case 1:
return 1;
case 3:
return "odd";
default:
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"prefer-switch": [true, { "min-cases": 3 }],

// Don't want these
"cyclomatic-complexity": false,
"newline-before-return": false,
"no-parameter-properties": false,
"no-unused-variable": false,
Expand All @@ -34,7 +35,6 @@

// TODO: Enable these
"completed-docs": false,
"cyclomatic-complexity": false,
"no-any": false,
"no-magic-numbers": false,
"no-non-null-assertion": false,
Expand Down

0 comments on commit 3da800c

Please sign in to comment.