dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.06k stars 4.04k forks source link

IDE1006 Naming Violation -- need legacy rule #40409

Closed jrmoreno1 closed 4 days ago

jrmoreno1 commented 4 years ago

Version Used: 16.4

Steps to Reproduce:

Create a project that uses either winforms or asp.net forms, create a control using what was previously the recommended naming pattern:

For example:

private System.Windows.Forms.Button btnOK; // https://support.microsoft.com/fi-fi/help/816145/how-to-use-the-dialogresult-property-in-visual-c

private void btnShowForm2_Click(object sender, System.EventArgs e)
{
}

Expected Behavior:

No warnings for either the btnOK declaration or the btnShowFrom2 event handelr.

Actual Behavior: IDE1006 Naming Violation for both.

==== The prefix is apps hungarian, and fairly standardized. btn, txt, lbl, ddl.

It would be great if there was some way to exclude these wholesale. There are just too many of them to exclude or change individually.

jrmoreno1 commented 1 year ago

Is this something you'd accept a PR for, and if so would you want it to be under configuration control (i.e. editorconfig setting) or just something it did automatically given the expected prefixes?

jrmoreno1 commented 1 year ago

@sharwell , @CyrusNajmabadi ?

CyrusNajmabadi commented 1 year ago

It looks like only you have requested this in an this time. Probably a better approach is to simply exclude these files from that analyzer in your editorconfig file.

jrmoreno1 commented 1 year ago

@CyrusNajmabadi : I understand saying I'm possibly the only person in the world that wants this (based on no votes in nearly 4 years), but this is quite literally every single file in such projects. The link has rotted, but at the time it was to official MS documentation and that was the naming convention. Every button on every page will be prefixed with btn, every text input field will be prefixed with txt and so forth. MS's recommendation was followed religiously.

Excluding individual files with this convention from such projects is just another way of saying exclude the analyzer from the projects.

sharwell commented 1 year ago

@jrmoreno1 Another option here would be to define a DiagnosticSuppressor which suppresses IDE1006 from these cases.

I believe the WinForms designer was updated a while back to generate event handler methods which meet the coding styles automatically, so this shouldn't be as much of a problem for new code as old.

jrmoreno1 commented 1 year ago

@sharwell : Thanks for the info about diagnostic suppressor, hadn’t heard of them before

jrmoreno1 commented 12 months ago

@sharwell : is there a sample diagnostic suppressor project with unit tests out that I could use as a starting point? Unlike analyzers there doesn’t seem to be a template project (and the analyzer template doesn’t include a suppressor project)

CyrusNajmabadi commented 4 days ago

Closing out due to lack of broad feedback, the ability to suppress through editorconfig, and the ability to use a diagnostic suppressor.