Skip to content
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

Enable Microsoft Code Analysis #1782

Open
wants to merge 28 commits into
base: development
Choose a base branch
from
Open

Enable Microsoft Code Analysis #1782

wants to merge 28 commits into from

Conversation

amoerie
Copy link
Collaborator

@amoerie amoerie commented May 2, 2024

Fixes #1781

Checklist

  • The pull request branch is in sync with latest commit on the fo-dicom/development branch
  • I have updated API documentation
  • I have included unit tests
  • I have updated the change log
  • I am listed in the CONTRIBUTORS file

Changes proposed in this pull request:

  • Enable CodeAnalysis "Minimum" = the most basic set of checks that Microsoft deemed as essential. We can dial it up to "Recommended" later
  • I manually edited the .editorconfig to set the severity of several reliability and performance related checks to "Warning". For example, the "ConfigureAwait" check was not part of the "Minimum" set, so I had to enable this separately.
  • Fix various warnings that surfaced after turning on the analysis.

Screenshot of what it looks like now if you forget ConfigureAwait(false):

image

var length = (ushort) ms.Position;
rawPdu.GetCommonFields(buffer, length);
await stream.WriteAsync(buffer.Bytes, 0, RawPDU.CommonFieldsLength + length, cancellationToken).ConfigureAwait(false);
RawPDU pdu = null;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Small note here: "await using" is compiler syntax sugar for DisposeAsync being called inside an automatically generated finally block.
Unfortunately there is no easy way to say "also add ConfigureAwait(false)", so this syntax sugar needed to be unwrapped manually.

I could also suppress the warning here, since the method RawPDU.DisposeAsync doesn't actually do anything async for now, but that felt more dangerous.

@amoerie amoerie mentioned this pull request May 6, 2024
5 tasks
@amoerie amoerie marked this pull request as ready for review May 23, 2024 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Microsoft Code Analysis
1 participant