-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Don't trigger naming style violation for prefixed numbers. #48306
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
Conversation
@@ -179,7 +179,7 @@ public bool IsNameCompliant(string name, out string failureReason) | |||
// remove specified Prefix, then look for any other common prefixes | |||
name = StripCommonPrefixes(name.Substring(Prefix.Length), out var prefix); | |||
|
|||
if (prefix != string.Empty) | |||
if (prefix != string.Empty && !char.IsDigit(name[0])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if this is ok. i.e. if would thinkg _0foo
was ok. i think it should check all the remainder of hte string and only ignore if it's all a number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would also need a comment explaining this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this helper method from Remove Unused Parameter could be moved so it can be re-used?
https://github.com/dotnet/roslyn/blob/master/src/Analyzers/Core/Analyzers/RemoveUnusedParametersAndValues/AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer.cs#L327-L334
This allows for only one digit after an underscore, but at least we'd have consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for locating the code @davidwengier . Resolving the conflicting nature of the two rules was my goal with #47569
We'll take this one too design review tomorrow and make sure it's the direction we want. |
/// are optionally followed by an integer, such as '_', '_1', '_2', etc. | ||
/// These are treated as special discard symbol names. | ||
/// </summary> | ||
internal static bool IsSymbolWithSpecialDiscardName(ISymbol symbol) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we instead make this as extension method on ISymbol
and move it to https://github.com/dotnet/roslyn/blob/master/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/ISymbolExtensions.cs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After I moved, IntelliSense says that the extension is available for Features
, but not CodeStyle
project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This extension belongs to Workspace
, thus unavailable from CodeStyle
. Since CodeStyle
is being refactored out, I think there should be another suitable shared position.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which project/file did you move the extension to? Please ensure the file is moved to the shared project at the location mentioned above, which is imported into both CodeStyle and Workspaces layer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved to wrong file, with the same namespace Microsoft.CodeAnalysis.Shared.Extensions
. It really confuses me that there are so many files named ISymbolExtension
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but Roslyn has multiple layers, each requiring its own set of extensions, so it is unavoidable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Once the helper method is made an extension method, I can merge the PR.
Hello @mavasani! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Auto-approval
Fixes #47569
The rule is quite naive and I'm not sure if it's appropriate.