Implement SA1131 (UseReadableConditions)
See original GitHub issueCategory: Readability
Rule: Use readable conditions (alternatively: Do not use Yoda conditions)
Description: The equality and inequality operators ==
and !=
are generally symmetric. In combination with #862, there is no longer a need to write expressions with a literal as the first operand. This rule is described as follows:
The first operand of an equality operator should not be a literal (or
null
), unless the second operand is also a literal (ornull
).
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
High-Quality Automated Tests- Top StyleCop Coding ...
High-Quality Automated Tests- Top StyleCop Coding Styles Part 2 · 1. SA1203 Constants Must Appear Before Fields · 2. SA1131 Use Readable Conditions...
Read more >StyleCop.CSharp.Rules 5.0.0
Contains C# StyleCop analyzers that can be incorporated into other projects (such as ReSharper).
Read more >miko/PowerShell
SA1130.severity = none. # SA1131: Use readable conditions. # https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1131.md.
Read more >Chocolatey Software | StyleCop 4.7.55.0
StyleCop analyzes C# source code to enforce a set of style and consistency rules. It can be run from inside of Visual Studio...
Read more >7.2.md - PowerShell/PowerShell
General Cmdlet Updates and Fixes. Use $PSStyle.Formatting.FormatAccent for Format-List and $PSStyle.Formatting.TableHeader for Format ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I don’t like this rule. I’ve been coding C/C++/C# for a long time. I’ve always written my comparisons <constant> == <value>, it’s how all my code is formatted. I find it easier to read. The most important term come first. After updating StyleCop I now have to disable this rule in all my projects.
Just make sure complaining about the comparison to true or false is only for bool and not the bool? data type, where it is valid.