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

Fix S4226: False positive for interfaces #1553

Closed
MaxTranced opened this issue Jul 12, 2018 · 3 comments
Closed

Fix S4226: False positive for interfaces #1553

MaxTranced opened this issue Jul 12, 2018 · 3 comments
Assignees
Labels
Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@MaxTranced
Copy link

Description

Extensions should be in separate namespaces.
It makes little sense to create an extension method when it is possible to just add that method to the type itself.

However, adding a method is impossible when an interface is involved (at least for C# language versions prior to v8).

Expected behavior

S4226 is not triggered for interfaces in language versions that don't support default method implementations.

Known workarounds

N/A

Related information

  • SonarC# Version: 7.2 (build 5463)
  • Visual Studio Version: 15.7.5
  • If running through the Scanner for MSBuild, its version: 4.3.1.1372
@agigleux agigleux added this to the 7.5 milestone Jul 30, 2018
@Evangelink Evangelink added Status: Todo Type: False Positive Rule IS triggered when it shouldn't be. labels Jul 30, 2018
@Evangelink
Copy link
Contributor

Hi @MaxTranced,

Thanks for the feedback. We add a couple of discussions about this because we were not entirely sure where to go with this rule but at the end we decided to tweak the rule to allow extension methods on interface within the same namespace.

@MaxTranced
Copy link
Author

Sounds good to me! 🙂

@andrei-epure-sonarsource
Copy link
Contributor

andrei-epure-sonarsource commented Jul 31, 2018

Update: S4226 should only be reported for class extension methods. It should ignore interfaces, structs (which should be lightweight), enums (which cannot have methods) and generics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: False Positive Rule IS triggered when it shouldn't be.
Projects
None yet
Development

No branches or pull requests

4 participants