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 S3963: Should not raise issue when the static constructor does not assign any fields #366

Closed
dee-see opened this issue May 24, 2017 · 3 comments
Assignees
Labels
Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@dee-see
Copy link

dee-see commented May 24, 2017

Description

Rule S3963, as far as I understand by reading the code, raises an error as soon as there is a static constructor. That picks up much more cases than the "Initialize all 'static fields' inline and remove the 'static constructor'" description would suggest.

Repro steps

    class Program
    {
        static Program() 
        {
            System.Console.WriteLine("Not assigning a field");
        }
    }

Real life examples instead of a WriteLine: initialization of GUI component, static initialisation of a vendor's license, basically all sorts of void method calls with side effects.

Expected behavior

No issue found

Actual behavior

S3963 is raised

Known workarounds

Turning off the rule or flagging as false positive

Related information

SonarQube 6.3.1
SonarCSharp 5.10.1 (build 1411)
MSBuild 14

@valhristov valhristov changed the title Rule S3963: False positive when static constructor does not assign any fields Fix S3963: False positive when static constructor does not assign any fields May 29, 2017
@valhristov valhristov added this to the near-future milestone May 29, 2017
@valhristov valhristov changed the title Fix S3963: False positive when static constructor does not assign any fields Update S3963: Should not raise issue when the static constructor does not assign any fields May 29, 2017
@Evangelink
Copy link
Contributor

RSPEC-3963

@Evangelink Evangelink modified the milestones: 6.0, near-future Jun 13, 2017
@Evangelink Evangelink self-assigned this Jun 13, 2017
@Evangelink Evangelink added Type: False Positive Rule IS triggered when it shouldn't be. and removed Type: Improvement labels Jun 13, 2017
@Evangelink Evangelink changed the title Update S3963: Should not raise issue when the static constructor does not assign any fields Fix S3963: Should not raise issue when the static constructor does not assign any fields Jun 13, 2017
@levindv
Copy link

levindv commented Oct 26, 2022

The same issue in VS2022 for SonarLint 6.9.0.54300.

@pavel-mikula-sonarsource
Copy link
Contributor

Hi @levindv,

Please create a new issue with the reproducer and a clear description of the problem. This one has been closed 5 years ago.

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

5 participants