-
-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cake script is contributing unactionable diagnostics to the Problems pane #791
Comments
The code generation predates .NET 6 / 7, so could be that there could be optimizations to utilize newer features i.e. code like private Cake.Common.Build.BuildSystem _BuildSystem;
public Cake.Common.Build.BuildSystem BuildSystem
{
[System.Diagnostics.DebuggerStepThrough]
get
{
if (_BuildSystem==null)
{
_BuildSystem = Cake.Common.Build.BuildSystemAliases.BuildSystem(Context);
}
return _BuildSystem;
}
} could be something like (plus some handling for obsolete logging) private Cake.Common.Build.BuildSystem _BuildSystem;
public Cake.Common.Build.BuildSystem BuildSystem
=> _BuildSystem ??= Cake.Common.Build.BuildSystemAliases.BuildSystem(Context); Right now you could disable the warning with a pragma on top of your cake file #pragma warning disable IDE0074 See: https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0054-ide0074 |
This doesn't actually seem to work FWIW. More broadly, I don't know if it ever makes sense for the user to see diagnostics from generated code that comes from Cake itself anyway. To me, it would be a bit like getting diagnostics from code created by a source generator. There's not a whole lot that I, as a user, can do about it. |
Probably because generated is inserted before your script, the code is merged with your code so Roslyn sees it as the same code, the code was written before the language feature analyzer suggests existed, it's also the same code generated regardless of the target framework. And analyzer didn't use to flag this suggestion for potential improvement. Another possibility could be to exclude with config, something like [*.cake]
dotnet_diagnostic.IDE0074.severity = none https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/configuration-files Cake now only targets net6 & net7 so future code gen could be improved in a future version, but hard to fix retroactively. |
Thanks @alexrp I added an issue on the Cake repo, to see what we can do to Cake itself, to avoid these problems being reported - cake-build/cake#4150 |
Closing since cake-build/cake#4150 was fixed. |
These aren't from a real file, so clicking them takes me nowhere. I would assume that they come from code that Cake inserts?
The repo where this happens is here.
The text was updated successfully, but these errors were encountered: