question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implement SA1131 (UseReadableConditions)

See original GitHub issue

Category: 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 (or null).

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
nridingcommented, Feb 21, 2017

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.

0reactions
GregReddickcommented, Feb 10, 2017

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found