dotnet / winforms

Windows Forms is a .NET UI framework for building Windows desktop applications.
MIT License
4.38k stars 971 forks source link

Write analyzer to identify component properties not annotated with `[SRCategory]` or `[SRDescription]` #10936

Open elachlan opened 7 months ago

elachlan commented 7 months ago

We should create an analyzer to help identify the missing attributes and then fix them. Its primarily an Internationalization (i18n) issue.

The main issue is that the CategoryAttribute isn't translated. So winforms needs to use SRCategoryAttribute, which is translated. The issue is most prevalent on properties missing any attribute, because it uses the default value Misc from the CategoryAttribute which is not translated.

By annotating all the public properties we can improve i18n.

Helps with issue: https://github.com/dotnet/runtime/issues/94365

Raised in: https://github.com/dotnet/winforms/pull/10728#issuecomment-1960601810

Tanya-Solyanik commented 7 months ago

API suggestion because SRCategoryAttribute is internal.

JeremyKuhne commented 6 months ago

@elachlan can you add more detail as to what this entails in this issue? The links should be backup, not the primary issue documentation.

elachlan commented 6 months ago

I have updated the issue description.

merriemcgaw commented 5 months ago

This would be worth considering making public at some point, but it's not at the top of our priorities. @elachlan if you want to implement something for the WinForms codebase, we'd love to take a look at it!

elachlan commented 5 months ago

I tried adding it to System.Windows.Forms.Analyzers but I don't think that gets applied to our own code base? Also I am unsure on the ID to use, I went with WFDEV004, but I am unsure if that makes sense?

Other than that I have the code written.

Edit: I think we should cover SRDescription as well.

elachlan commented 4 months ago

@Tanya-Solyanik Do you know how I should structure this? Do we want a public analyzer, or just internal? If Internal, I think I need a new project for the InternalAnalyzers. Probably something like System.Windows.Forms.InternalAnalyzers.

paul1956 commented 4 months ago

@Tanya-Solyanik If there is a way to have analyzers operating just on WinForms source, I would consider writing 1 or 2 Analzers to enforce VB Code Styles, like 2 spaces for XML Comments (something unique WinForms) and special blank line rules for blocks where current source has a mixture of blank lines after End Block. If nothing else knowing the agreed rules would be fantastic.

RussKie commented 4 months ago

This is the Windows Forms-repo specific analizer/source-generator project -> https://github.com/dotnet/winforms/tree/main/src/System.Windows.Forms.PrivateSourceGenerators. Since it started as and only contains source generators it was named "SourceGenerators", but to follow the established naming conventions in should be renamed to System.Windows.Forms.{Private|Internal}.Analyzers.Csharp since it's dealing with C# content. For VB-specific a new project will need to be created that follows the same naming convention, e.g.: System.Windows.Forms.{Private|Internal}.Analyzers.VisualBasic.

RussKie commented 4 months ago

I tried adding it to System.Windows.Forms.Analyzers but I don't think that gets applied to our own code base?

It requires some hackery similar how it was done in https://github.com/dotnet/winforms/pull/5035 with $(ResolveWinFormsAnalyzersFromSdkRefPack).

elachlan commented 4 months ago

@RussKie I'll add it to PrivateSourceGenerators.