close
Skip to content

Don't trigger naming style violation for prefixed numbers.#48306

Merged
5 commits merged into
dotnet:masterfrom
huoyaoyuan:naming-style-number
Oct 15, 2020
Merged

Don't trigger naming style violation for prefixed numbers.#48306
5 commits merged into
dotnet:masterfrom
huoyaoyuan:naming-style-number

Conversation

@huoyaoyuan
Copy link
Copy Markdown
Member

Fixes #47569
The rule is quite naive and I'm not sure if it's appropriate.

@huoyaoyuan huoyaoyuan requested a review from a team as a code owner October 4, 2020 11:00
name = StripCommonPrefixes(name.Substring(Prefix.Length), out var prefix);

if (prefix != string.Empty)
if (prefix != string.Empty && !char.IsDigit(name[0]))
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Member

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.

Copy link
Copy Markdown

@Forge36 Forge36 Oct 5, 2020

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

Comment thread src/Analyzers/CSharp/Tests/NamingStyles/NamingStylesTests.cs Outdated
@jinujoseph jinujoseph added Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee. labels Oct 4, 2020
@sharwell
Copy link
Copy Markdown
Contributor

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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

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.

Copy link
Copy Markdown
Member Author

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.

Copy link
Copy Markdown
Contributor

@mavasani mavasani Oct 15, 2020

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.

Copy link
Copy Markdown
Member Author

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.

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor

@mavasani mavasani left a 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.

@ghost
Copy link
Copy Markdown

ghost commented Oct 15, 2020

Hello @mavasani!

Because this pull request has the auto-merge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

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 (@msftbot) and give me an instruction to get started! Learn more here.

Copy link
Copy Markdown

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-approval

@ghost ghost merged commit a6144b2 into dotnet:master Oct 15, 2020
@ghost ghost added this to the Next milestone Oct 15, 2020
@huoyaoyuan huoyaoyuan deleted the naming-style-number branch October 15, 2020 21:25
@allisonchou allisonchou modified the milestones: Next, 16.9.P2 Nov 24, 2020
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-IDE auto-merge Community The pull request was submitted by a contributor who is not a Microsoft employee.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IDE1006 fires on discard parameters

8 participants