Skip to content

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

Open
@mikernet

Description

@mikernet

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

Activity

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[/+] on Mar 9, 2024
sharwell

sharwell commented on Mar 11, 2024

@sharwell
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

mikernet commented on Mar 12, 2024

@mikernet
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

mikernet commented on Mar 12, 2024

@mikernet
Author

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

sharwell commented on Mar 18, 2024

@sharwell
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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @sharwell@mikernet

      Issue actions

        Do not warn SA1001 (Commas should be spaced correctly) if comma follows a preprocessor directive · Issue #3816 · DotNetAnalyzers/StyleCopAnalyzers