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

SA1008, SA1012: false positives for property pattern inside parentheses #3812

Closed
adiessl opened this issue Mar 6, 2024 · 3 comments · Fixed by #3813
Closed

SA1008, SA1012: false positives for property pattern inside parentheses #3812

adiessl opened this issue Mar 6, 2024 · 3 comments · Fixed by #3813

Comments

@adiessl
Copy link

adiessl commented Mar 6, 2024

Using StyleCop.Analyzers version 1.2.0-beta.556

public static class Helpers
{
    public static bool HasValidLength(string s)
    {
        // ⚠ SA1008 Opening parenthesis should not be preceded by a space.
        // ⚠ SA1012 Opening brace should be preceded by a space
        //              ↓↓
        return s is not ({ Length: < 5 } or { Length: > 10 });
    }
}

This is similar to the problem fixed in #3141.

@bjornhellander
Copy link
Contributor

I can confirm SA1012, but I actually don't see a SA1008 in this example. Weird.

@adiessl
Copy link
Author

adiessl commented Mar 6, 2024

Yes, technically correct it would be like this:

public static class Helpers
{
    public static bool HasValidLength(string s)
    {
        // ⚠ SA1012 Opening brace should be preceded by a space
        //               ↓
        return s is not ({ Length: < 5 } or { Length: > 10 });
    }
}

"Fixing" this leads to the other error:

public static class Helpers
{
    public static bool HasValidLength(string s)
    {
        // ⚠ SA1008 Opening parenthesis should not be preceded by a space.
        //                ↓
        return s is not ( { Length: < 5 } or { Length: > 10 });
    }
}

@bjornhellander
Copy link
Contributor

Ok 👍

I am also seeing the same for ({ Length: < 5 } and { Length: > 2 }) and ({ Length: < 5 })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment