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 S2325: Should raise issues for methods and properties with SuppressMessage attribute #631

Closed
ohadschn opened this issue Aug 1, 2017 · 2 comments
Assignees
Labels
Type: Bug Exceptions and blocking issues during analysis.
Milestone

Comments

@ohadschn
Copy link

ohadschn commented Aug 1, 2017

Description

Methods and properties with an attribute do not raise issues.

ORIGINAL: SuppressMessage with nonexistent category and check ID still suppresses issues.

Repro steps

Define the following method and make sure S2325: Methods and properties that don't access instance data should be static is enabled:

private int Get()
{
    return 42;
}

Note S2325 is reported. Now add the following suppression attribute:

[System.Diagnostics.CodeAnalysis.SuppressMessage("Foo", "Bar", Justification = "baz")]
private int Get()
{
    return 42;
}

EDIT: Any attribute breaks the rule.

Expected behavior

The issue should remain, since the proper category (pitfall?) and check ID (S2325) weren't supplied.

Actual behavior

The issue is suppressed.

Known workarounds

Use #pragma warning disable / #pragma warning restore

Related information

  • SonarC# Version 6.2.0.2536
  • Visual Studio Version 2017 (15.2, 26430.16)
@valhristov
Copy link
Contributor

Thanks for your feedback! I was able to reproduce the problem, the fix will be included in the next version of SonarC#.

@valhristov valhristov added this to the 6.4 milestone Aug 3, 2017
@valhristov valhristov added Area: Rules Type: Bug Exceptions and blocking issues during analysis. labels Aug 3, 2017
@valhristov valhristov self-assigned this Aug 3, 2017
@valhristov valhristov changed the title SuppressMessage with nonexistent category and check ID still suppresses issues Fix S2325: Methods and properties with attribute do not raise issues Aug 3, 2017
@valhristov valhristov changed the title Fix S2325: Methods and properties with attribute do not raise issues Fix S2325: Should raise issues for methods and properties with SuppressMessage attribute Aug 8, 2017
@valhristov
Copy link
Contributor

We decided to allow raising issues only if there is a SuppressMessage attribute. If other attributes are present we will not raise in order to reduce the false positives when using attribute-based functionality such as serialization, WCF, etc...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Exceptions and blocking issues during analysis.
Projects
None yet
Development

No branches or pull requests

2 participants