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

Fix S1125 FN: recognize "is" keyword with constant pattern #2619

Closed
rangp opened this issue Sep 3, 2019 · 2 comments · Fixed by #7687
Closed

Fix S1125 FN: recognize "is" keyword with constant pattern #2619

rangp opened this issue Sep 3, 2019 · 2 comments · Fixed by #7687
Assignees
Labels
Area: C# C# rules related issues. Type: False Negative Rule is NOT triggered when it should be.
Milestone

Comments

@rangp
Copy link

rangp commented Sep 3, 2019

Description

Starting with c# 7.0 the is keyword can be used with a constant pattern as an alternative to == or .Equals(). This is not yet covered by the S1125 rule

Repro steps

var x = false;
if (x == true)
{
   // S1125 warning
}

if (x is true)
{
   // no S1125 warning
}

Expected behavior

Both of the above statements should get the S1125 warning since they're equivalent

Actual behavior

Only the first statement gets the warning

Known workarounds

None

@andrei-epure-sonarsource andrei-epure-sonarsource added this to the Support milestone Sep 26, 2019
@andrei-epure-sonarsource andrei-epure-sonarsource added Area: C# C# rules related issues. Status: Confirmed Type: False Negative Rule is NOT triggered when it should be. labels Oct 9, 2019
@andrei-epure-sonarsource
Copy link
Contributor

thanks @rangp , you're right!

@pavel-mikula-sonarsource
Copy link
Contributor

..when the tested expression is bool

For nullable value type bool?, the is true or is false does also a null check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Type: False Negative Rule is NOT triggered when it should be.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants