-
Notifications
You must be signed in to change notification settings - Fork 887
cyclomatic-complexity: Don't count empty switch cases #2743
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
switch (foo) {
case 0:
case 1:
bar();
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw. if revert your change here to make them equal again, you probably need to disable the rule in almost all There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. related: why do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, these two code snippets seem equally complex to me: if (foo) {
return 0;
}
return 1; if (foo) {
return 0;
} else {
return 1;
} |
||
case ts.SyntaxKind.CatchClause: | ||
case ts.SyntaxKind.ConditionalExpression: | ||
case ts.SyntaxKind.DoStatement: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's not entirely right. consider the following code which does not increase complexity with this change:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's only one possible path through that code, so I don't think it should increase complexity.