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

Do not warn SA1001 (Commas should be spaced correctly) if comma follows a preprocessor directive #3816

Open
mikernet opened this issue Mar 9, 2024 · 4 comments · May be fixed by #3839
Open

Comments

@mikernet
Copy link

mikernet commented Mar 9, 2024

Example where I don't think I should need to suppress the diagnostic:

partial struct Money : IFormattable
#if !NETSTANDARD
#pragma warning disable SA1001 // Commas should be spaced correctly
    , ISpanFormattable
#pragma warning restore SA1001
#endif
@mikernet mikernet changed the title Do not warn SA1001 (Commas should be spaced correctly) if it follows a preprocessor directive Do not warn SA1001 (Commas should be spaced correctly) if comma follows a preprocessor directive Mar 9, 2024
@sharwell
Copy link
Member

This is fine to fix. Can also likely work around:

partial struct Money :
#if !NETSTANDARD
    ISpanFormattable,
#endif
    IFormattable

Or:

partial struct Money
#if NET6_OR_GREATER
    : ISpanFormattable
#else
    : IFormattable
#endif

@mikernet
Copy link
Author

Good point, didn't think of that tbh.
Another one, before:

public readonly struct BigDecimal : IComparable<BigDecimal>, IEquatable<BigDecimal>, IComparable, IFormattable
#if NET7_0_OR_GREATER
#pragma warning disable SA1001 // Commas should be spaced correctly
    , IFloatingPoint<BigDecimal>
#pragma warning restore SA1001
#endif

After:

public readonly struct BigDecimal :
#if NET7_0_OR_GREATER
    IFloatingPoint<BigDecimal>,
#endif
    IComparable<BigDecimal>, IEquatable<BigDecimal>, IComparable, IFormattable

That works for me.

@mikernet
Copy link
Author

mikernet commented Mar 12, 2024

Given that there is a suitable alternative form that avoids the warning, I'm fine with this being closed if you don't think it is needed. I prefer the suggested workaround anyway, the leading comma bothered me haha.

@sharwell
Copy link
Member

I'm leaving this open because it's fairly standard for us to ignore the end-of-line/beginning-of-line rules in the presence of preprocessor directives. We could either ignore all directives here, or we could just ignore conditional directives (#if/#elif/#else/#endif). I think I lean towards the latter.

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

Successfully merging a pull request may close this issue.

2 participants