Skip to content

SA1025 possible bug #3684

Closed
Closed

Description

@Drake53

Consider the following code:

public enum MyEnum
{
    FirstValue,
    SecondValue,
    ThirdValue,
    FourthValue,
    FifthValue,
}

[Flags]
public enum MyEnums
{
    FirstValue  = 1 << MyEnum.FirstValue,
    SecondValue = 1 << MyEnum.SecondValue,
    ThirdValue  = 1 << MyEnum.ThirdValue,
    FourthValue = 1 << MyEnum.FourthValue,
    FifthValue  = 1 << MyEnum.FifthValue,
}

For readability I like to have all the = aligned in the flags enum. This triggers rule SA1025 due to having multiple whitespace characters in a row, however if I understand the documentation correctly this should be an exception.
Rule description for reference:
A violation of this rule occurs whenever the code contains multiple whitespace characters in a row, unless the characters come at the beginning or end of a line of code, following a comma or semicolon or preceding a symbol.

If it's not a bug but working as intended, I'd like to request that an exception be added for this case.

Activity

  1. bjornhellander commented on Aug 1, 2023

    @bjornhellander
    Contributor

    Well, I see no trace of taking symbols into consideration in this rule's code. If that was intended, then it looks a bit like a bug.

    If this is the original StyleCop code, then it definitely handles spaces preceding symbols/operators somehow: https://github.com/StyleCop/StyleCop/blob/7da86d484c6487c5fff1ae84cbd41c03c5c212d8/Project/Src/StyleCop.CSharp.Rules/SpacingRules.cs#L1964-L1978,

    I tried the StyleCop plugin to Resharper and that one did not complain about the provided code example. I also tried with extra spaces before +, - * etc and it did not trigger in any of those cases.

    Could not find anything relevant in the KnownChanges.md document, or in the open/closed issues.

    @sharwell, do you remember any intentional deviations in this rule? Any opinions?

  2. sharwell commented on Aug 7, 2023

    @sharwell
    Member

    It's not listed in known issues:
    https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/KnownChanges.md#sa1025

    Based on the age of the current behavior, I lean towards not making a change here (and instead updating the documentation).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions