EditorConfig - simplify boolean evaluations?

Viewed 179

Is there an EditorConfig setting for simplifying boolean evaluations in if statements? e.g.

// prefer:
if (thingy)

// over:
if (thingy == true)

and

// prefer:
if (!thingy)

// over:
if (thingy == false)
5 Answers

There isn't such a setting in EditorConfig. Note that EditorConfig isn't really a static analysis tool, but a configuration setting for formatting files with regard to indentation, tabs vs spaces etc.

AFAIK, there is no such built-in VS editor config. Usually, you would use either StyleCop, or Resharper and alike for code style rules and refactorings like that.

Add the .editorconfig in your solution path and if you're using VSCode, install official C# plugin. To enable .editorconfig validation just go to settings (ctrl/command + ,) > "Extensions" > "C# configuration" > Check "Omnisharp: Enable Editor Config Support". Also, make sure option "Format: Enable" is checked.

If you want to actually make build fail, you could use Microsoft.CodeAnalysis.CSharp.CodeStyle NuGet package in the project you want to validate code style. This will generate build failure if the code is not compliant to .editorconfig. More informations in about this issue.

Related