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

SA1025 possible bug #3684

Closed
Drake53 opened this issue Aug 1, 2023 · 2 comments · Fixed by #3765
Closed

SA1025 possible bug #3684

Drake53 opened this issue Aug 1, 2023 · 2 comments · Fixed by #3765

Comments

@Drake53
Copy link

Drake53 commented Aug 1, 2023

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.

@bjornhellander
Copy link
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?

@sharwell
Copy link
Member

sharwell commented Aug 7, 2023

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
Labels
None yet
Projects
None yet
3 participants