Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule S1125: Boolean literals should not be redundant #2267

Merged
merged 8 commits into from
Feb 7, 2019

Conversation

andrei-epure-sonarsource
Copy link
Contributor

Fix #2061

internal const string DiagnosticId = "S1125";
protected const string MessageFormat = "Remove the unnecessary Boolean literal(s).";

protected abstract TSyntaxKind TrueLiteral { get; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of asking sub-classes to provide TrueLiteral, FalseLiteral and IsKind you could require only IsTrueLiteralKind and IsFalseLiteralKind methods

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TSyntaxKind is passed as argument to many methods: CheckForBooleanConstantOnLeft, CheckForBooleanConstantOnRight and CheckForBooleanConstant. I think the code is readable enough as is

x = false; // Fixed
x = Foo(); // Fixed
x = Foo(); // Fixed
x = Foo(); // Fixed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[cosmetic] Could you align the // Fixed comments. This will means that the // Noncompliant are also aligned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it is not possible for both //Noncompliant and //Fixed to be aligned.

  • the // Noncompliant are aligned
  • the // Fixed are not aligned because code is being cut out, and False has 5 letters, True has 4 letters, thus the lines cannot be aligned between themselves in both files

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aaaah!

Dim exp = True
Dim exp2 = True

Dim z = True OrElse ((True)) ' Noncompliant (also S1764)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a check with And and Or (the operators forcing both parts to be evaluated).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really good catch, thanks!!!

@andrei-epure-sonarsource andrei-epure-sonarsource merged commit 42e96c6 into master Feb 7, 2019
@andrei-epure-sonarsource andrei-epure-sonarsource deleted the andrei/vb-s1125 branch February 7, 2019 15:05
@ghost ghost removed the Status: Needs Review label Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants