Skip to content

Enable and fix many .NET Code Analysis warnings #1533

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

Merged
merged 10 commits into from
Aug 3, 2021

Conversation

andyleejordan
Copy link
Member

@andyleejordan andyleejordan commented Aug 2, 2021

Pulling this out of #1532, enabling and fixing the code analysis warnings that matter to us one-by-one, and treating them as build errors. I should note that there are many other warnings we're ignoring for now and should fix eventually.

Since all our projects target the `Microsoft.NET.Sdk` we can use
roslyn's built-in analyzers instead of the out-of-date package (we could
update that instead, but this is the modern method).
@andyleejordan andyleejordan requested a review from rjmholt August 2, 2021 23:12
@andyleejordan andyleejordan added Area-Debugging Issue-Enhancement A feature request (enhancement). labels Aug 2, 2021
@andyleejordan andyleejordan force-pushed the andschwa/dotnet-analysis branch 3 times, most recently from 4f02fb6 to f1d920c Compare August 3, 2021 00:11
@andyleejordan andyleejordan changed the title WIP: Enable and fix .NET Code Analysis Warnings WIP: Enable and fix many .NET Code Analysis warnings Aug 3, 2021
@andyleejordan andyleejordan changed the title WIP: Enable and fix many .NET Code Analysis warnings Enable and fix many .NET Code Analysis warnings Aug 3, 2021
@andyleejordan andyleejordan marked this pull request as ready for review August 3, 2021 01:18
@@ -62,7 +62,7 @@ internal static class AstOperations
ILogger logger,
CancellationToken cancellationToken)
{
if (!s_completionHandle.Wait(0))
if (!s_completionHandle.Wait(0, cancellationToken))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't need the cancellation passed through, since it's a Wait(0) -- the token should never get a chance to cancel

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tell that to the compiler that complained.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose it can't hurt here, but I don't like the idea of misleading code -- the cancellation token definitely has no utility here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could pass CancellationToken.None instead (which says explicitly this won't be cancelled).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah I think what you've got works fine

@andyleejordan andyleejordan force-pushed the andschwa/dotnet-analysis branch from 5872caf to d07af0f Compare August 3, 2021 18:52
@@ -75,7 +75,7 @@ public async Task<DisconnectResponse> Handle(DisconnectArguments request, Cancel

#pragma warning disable CS4014
// Trigger the clean up of the debugger. No need to wait for it.
Task.Run(_psesDebugServer.OnSessionEnded);
Task.Run(_psesDebugServer.OnSessionEnded, cancellationToken);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rjmholt Should this one be explicitly CancellationToken.None? Presumably we probably don't want to the debug server's clean up to be cancelled.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that said if it's cancelled here then we don't return the DisconnectResponse so I suppose it would get cancelled again?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I think None seems reasonable

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops forgot about this 🤷

@@ -14,9 +14,6 @@ namespace Microsoft.PowerShell.EditorServices.Services.TextDocument
/// </summary>
internal static class TokenOperations
{
// Region kinds to align with VSCode's region kinds
private const string RegionKindComment = "comment";
private const string RegionKindRegion = "region";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These unused fields smell like olllld code to me.

@andyleejordan andyleejordan force-pushed the andschwa/dotnet-analysis branch from d07af0f to 52501c8 Compare August 3, 2021 19:09
@andyleejordan andyleejordan force-pushed the andschwa/dotnet-analysis branch from 52501c8 to 707cad6 Compare August 3, 2021 19:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Debugging Issue-Enhancement A feature request (enhancement).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants