dotnet / roslyn-analyzers

MIT License
1.58k stars 463 forks source link

CA1416 Enable generated code analysis on razor pages #5971

Open buyaa-n opened 2 years ago

buyaa-n commented 2 years ago

CA1416 is turned off for generated code, we have been discussing to add an option for opting in for generated code analysis but that haven't been implemented.

This is causing No platform compatibility analyzer warnings in Razor, we need an option to enable it in razor pages (blazor projects)

CC @mavasani @jmarolf @sharwell @jeffhandley @terrajobst

buyaa-n commented 2 years ago

I do not recall how we were planning to handle this, I am thinking of few options:

  1. Enable source analysis for a project having <SupportedPlatform>browser</SupportedPlatform> property (without having an option for opting in for generated code analysis, only for fixing the blazor issue)
  2. Add option for opting in:

    • Add editor config option, I think this will require each blazor projects opt-in manually
    • Add MSBuild property for opt-in and add it automatically for blazor projects (needs MSBuild update)
    • Another question is how the option should work, if the option should be analyzer specific, i.e. list of analyzer ids separated with comma or if we want a global config for all analyzers, any configured with that option would support generated source analysis

    Please let me know your thoughts @mavasani @jmarolf @sharwell @jeffhandley @terrajobst

buyaa-n commented 2 years ago

As per offline discussion the suggested solution is same as one in https://github.com/dotnet/roslyn/issues/39758#issuecomment-552641591 the analyzer should opt in for generated code analysis, but have a quick check in the analyzer itself to see if the current file is the expected generated code and return without performing the analysis if it's not a generated Razor file