Open captainsafia opened 2 weeks ago
Isn't there a special category/level for analyzers that are flagging redundant code? It might be Hidden
but I think there might actually be a bool to tell the editor to grey out the span, rather than squiggling it. Otherwise, LGTM.
Isn't there a special category/lever for analyzers that are flagging redundant code? It might be
Hidden
but I think there might actually be a bool to tell the editor to grey out the span, rather than squiggling it. Otherwise, LGTM.
This is the full set of available severities. I think our "Hidden" above aligns with the "None" below.
@amcasey Ah I see -- it looks like this is a tag that can be added in addition to the severity level of the property. I can incorporate this into the PR.
Minor nit on the message text:
Using public partial class Program { } to make the generated Program class public is no longer required. See https://aka.ms/aspnetcore-warnings/ASP0027 for more details.
[API Review]
Title Unnecessary public Program class declaration Message Using public partial class Program { } to make the generated Program class public is no longer required. See https://aka.ms/aspnetcore-warnings/ASP0027 for more details. Severity Hidden or Info, TBD
API Approved!
Background and Motivation
With the introduction of top-level statements in .NET 6, there is not longer an explicit
Program
class defined in user's ASP.NET Core applications. Instead, we rely on theProgram
class generated by the compiler, which has a default visibility ofinternal
.This introduces an annoying hurdle for users who want to write integration tests on top of our WebApplicationFactory which requires a public entrypoint as a generic type argument.
To work around this, we document that users can either:
IVT
from their application code to their test codepublic partial class Program {}
declarationThe first approach runs the risk of the user having to expose truly internal types to their test code. The second approach is hard to discover.
To resolve this issue, we introduced a new source generator to the shared framework that will emit the
public partial class Program {}
declaration to applications that:Program
class as public in some other fashionProgram.Main
declarationsThis source generator was implemented in https://github.com/dotnet/aspnetcore/pull/58199. Based on the code generation that we introduced here, users can get rid of the explicit
public partial class Program { }
declarations in their source code and rely on the new default behavior. We propose introducing an analyzer to find these explicit declarations and a code fixer to remove them.Proposed Analyzer
Analyzer Behavior and Message
Title
Explicit class declaration not required
Message
Using public partial class Program { } to make generated Program class public is no longer required. See https://aka.ms/aspnetcore-warnings/ASP0027 for more details.
Category
Severity Level
Usage Scenarios