Skip to content

NET-2280 New Rule Idea: Do not use is not { } #9755

@alex-meseldzija-sonarsource

Description

Description

Do not use is not { }.

This code is confusing, and 99% of the time can be refactored into more readable and less obfuscated code.

In the (very)rare case that this is cleaner, it can be accepted.

Noncompliant code snippet

if(SomeMethod() is not {  } token)  // Noncompliant
{
    DoSomethingWithoutToken();
}
DoSomethingWithToken(token);

Compliant code snippet

if(SomeMethod() is {  } token)  // Compliant
{
    DoSomethingWithToken(token);
}
 DoSomethingWithoutToken();

Metadata

Metadata

Assignees

No one assigned

    Labels

    Rule IdeaIdea for a rule that has NOT been specified.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions