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

Update SonarAnalyzer.CSharp #1494

Merged
merged 12 commits into from
Sep 19, 2024
Merged

Update SonarAnalyzer.CSharp #1494

merged 12 commits into from
Sep 19, 2024

Conversation

mus65
Copy link
Contributor

@mus65 mus65 commented Sep 14, 2024

There a quite a few new analyzers. For easier review, I created a separate commit for each analyzer, including a link to the sonar source docs and additional notes from me.

Some of these may be worth disabling instead of adding suppressions. I opted for adding suppressions for now.

Introduced abstractions for CancellationTokenSource.CancelAsync()
and Stream.DisposeAsync() to avoid #ifdef.

Supressed pipeStream.WriteAsync because it deadlocks the test.
I assume because PipeStream doesn't override WriteAsync.

https://rules.sonarsource.com/csharp/RSPEC-6966/

temp
Removed the Connect() from Multifactor_PublicKeyWithEmptyPassPhrase
because the Exception is already thrown in the factory.

https://rules.sonarsource.com/csharp/RSPEC-3431/
…uld be static

This one is pretty redundant with CA1822 (which is also disabled in the
tests).

It caught a few more cases in the library itself, most of which can't
be changed because they are public API.

https://rules.sonarsource.com/csharp/RSPEC-2325/
not sure if this one is worth having. The only cases it found
are imho legitimate or not worth fixing, so I supressed them.

https://rules.sonarsource.com/csharp/RSPEC-127/
@Rob-Hague
Copy link
Collaborator

IMHO S3993 (attribute usage) and S3431 (ExpectedException) have value, the others do not. But you can wait for other opinions - I don't like the "every analyzer" approach that we take

this is already covered by Test_PrivateKey_SSH2_Encrypted_ShouldThrowSshPassPhraseNullOrEmptyExceptionWhenPassphraseIsNull
@drieseng
Copy link
Member

@mus65 We should globally disable S2325 (and revert the changes that you applied to silence this rule).

This is what I have in my .editorconfig at work:

# S2325: Methods and properties that don't access instance data should be static
# https://rules.sonarsource.com/csharp/RSPEC-2325
#
# This is a duplicate of CA1822, and reports false positives for ASP.NET Core Middleware
dotnet_diagnostic.S2325.severity = none

CA1822 also allows you to configure the API surface that the rule applies to. We do this for example in the .editorconfig of the Renci.SshNet project. Also S2325 does not appear to respect the generated_code = true .editorconfig setting which we set for Bcrypt.cs (as that code was imported by us).

…data should be static"

suppress it instead

This reverts commit 2020604.
@mus65
Copy link
Contributor Author

mus65 commented Sep 15, 2024

@drieseng done

@Rob-Hague
Copy link
Collaborator

Sorry for the conflicts, can you also revert/suppress S127 then I'll merge

Copy link
Collaborator

@Rob-Hague Rob-Hague left a comment

Choose a reason for hiding this comment

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

Thanks

@Rob-Hague Rob-Hague merged commit 3b55ba3 into sshnet:develop Sep 19, 2024
1 check passed
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.

3 participants