EvilRoslynAnalyzers icon indicating copy to clipboard operation
EvilRoslynAnalyzers copied to clipboard

Feature idea: Every `if` must have `else`

Open TenCoKaciStromy opened this issue 10 months ago • 3 comments

Why? It's a protection against 10x ADHD developers who jumps from one project to another and stops coding in the middle of method and forgots the else part. (Instead of properly reporting every line of code to company timesheets and follow waterfall roadmap.)

Wrong:

if (something) { ... }

Right:

if (something) { ... }
else { /* didn't forgot about else branch */ }

TenCoKaciStromy avatar Apr 16 '24 15:04 TenCoKaciStromy

Something similar exists for real when using else if in the popular sonar scanner: https://rules.sonarsource.com/csharp/RSPEC-126/?search=Else

Mrxx99 avatar Apr 16 '24 19:04 Mrxx99

Something similar exists for real when using else if in the popular sonar scanner: https://rules.sonarsource.com/csharp/RSPEC-126/?search=Else

That's horrible 😭

TenCoKaciStromy avatar Apr 17 '24 04:04 TenCoKaciStromy

The Sonar rule is actually not that horrible 😅 It's the equivalent to an exhaustive pattern match, which is enforced in many languages to avoid a lot of logic flaws at compile time.

flobernd avatar Apr 17 '24 07:04 flobernd