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

Rule Idea: void method implementations should not be async #9711

Open
Tim-Pohlmann opened this issue Nov 29, 2024 · 3 comments
Open

Rule Idea: void method implementations should not be async #9711

Tim-Pohlmann opened this issue Nov 29, 2024 · 3 comments
Labels
Area: C# C# rules related issues. Type: Rule Idea Idea for a rule that has NOT been specified.

Comments

@Tim-Pohlmann
Copy link
Contributor

Tim-Pohlmann commented Nov 29, 2024

interface IInterface
{
    void InterfaceMethod();
}

class Base
{
    protected virtual void BaseMethod() {}
}

class Sample : Base, IInterface
{
    public async void InterfaceMethod() {}           // Noncompliant 
    protected override async void BaseMethod() {}    // Noncompliant
    protected virtual async void VirtualMethod() {}  // Noncompliant
    async void OtherMethod() {}                      // Compliant: covered by S3168
}

This rule complements S3168, which ignores methods that implement an interface, override a base method, or are virtual. Having this functionality as a separate rule allows users to tailor their analysis to their needs.

@Tim-Pohlmann Tim-Pohlmann added Area: C# C# rules related issues. Type: Rule Idea Idea for a rule that has NOT been specified. labels Nov 29, 2024
@Tim-Pohlmann
Copy link
Contributor Author

The implementation should be a straightforward adaption of S3168.

@qhris
Copy link

qhris commented Nov 29, 2024

This looks good to me!

Some questions regarding the exceptions raised in SonarSource/rspec#4547:

Would this capture all these scenarios?

  • Methods implementing an interface
  • Methods overriding a base class method
  • Virtual methods

From the wording here it should capture all 3 cases, correct?

@Tim-Pohlmann
Copy link
Contributor Author

I clarified it. Thanks for pointing it out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: C# C# rules related issues. Type: Rule Idea Idea for a rule that has NOT been specified.
Projects
None yet
Development

No branches or pull requests

2 participants