tslint-clean-code icon indicating copy to clipboard operation
tslint-clean-code copied to clipboard

New rule: avoid-if-else

Open froodley opened this issue 7 years ago • 3 comments

http://blog.timoxley.com/post/47041269194/avoid-else-return-early

Use of if-else is always unnecessary, and leads to cyclomatic complexity. Other clean code linters (phpmd, golint) enforce this pattern. Would love to have this rule as I have to enforce it manually in my typescript projects right now.

froodley avatar Jan 28 '18 20:01 froodley

May be related to https://github.com/ajafff/tslint-consistent-codestyle/blob/master/docs/no-else-after-return.md

Glavin001 avatar Jan 28 '18 22:01 Glavin001

Such rules are similar but not quite what I need. They only enforce that if the if branch has a return, else is unnecessary. We expressly forbid use of else, period. In SRP code it is a clear code smell.

froodley avatar Jan 29 '18 17:01 froodley

Oh I see what you mean now! Pull Requests very welcome! Great idea for a rule.

Glavin001 avatar Jan 29 '18 19:01 Glavin001