It would be great to be able to disable switches from being taken into account for cyclomatic complexity, specially
Imagine the following: you have to render an icon depending on a status prop on a pure function. This piece of code can render up to as many icons as the application requires for it's component statuses.
switch(this.status) {
case State.Idle:
return <IdleIcon />
case State.Active:
return <ActiveIcon/>
(...)
case State.Deleted:
return <DeletedIcon/>
}
You're now left with a couple of options:
this.renderActiveOrIdle, pretty annoying)I think these kind of switches are really easy to visualize. That said, I understand that more complex switches could be the reason to negate the request. Maybe adding a character threshold or line threshold between cases could suffice?
We have the threshold at 6 and it is often the case that we add the disabler comment (though we only allow it for switches).
At least in our case we tend to use switches for quick conditionals only, such as the case above. Any chance this could be a feature in the future?
This is an interesting request. Would it be reasonable to also add options for other control flow constructs such as while loops?
Marking as in discussion to gather more community feedback. ๐
I'm guessing the more granular the better, maybe having the ability to set the default weight of each thing is enough. Say we can set the switch cases to have a cyclomatic complexity of 0 and such.
"cyclomatic-complexity": [
true,
10,
{ "ignoredClauses": ["caseClause"] }
]
I think the proposed config is great and solves the problem we were having. What other clauses (other than cases and ifs) could be ignored on that ignoredClauses field?
Maybe having a compoundConditionals (A && B && C) could help so we can make those scenarios count as 1?
โ ๏ธ TSLint's time has come! โ ๏ธ
TSLint is no longer accepting most feature requests per #4534. See typescript-eslint.io for the new, shiny way to lint your TypeScript code with ESLint. โจ
It was a pleasure open sourcing with you all!
๐ค Beep boop! ๐ TSLint is deprecated ๐ _(#4534)_ and you should switch to typescript-eslint! ๐ค
๐ This issue is being locked to prevent further unnecessary discussions. Thank you! ๐
Most helpful comment
4489 had an interesting configuration proposal (@mouadennaciri):