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 S1144: False Positive when private member is only used in a generated file #2312

Closed
ValentijnMakkenze opened this issue Mar 1, 2019 · 1 comment
Assignees
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.
Milestone

Comments

@ValentijnMakkenze
Copy link

ValentijnMakkenze commented Mar 1, 2019

Description

We get a false positive for Unused private types or members should be removed

Repro steps

We have a private function that is called from the Dispose function that is in the designer file

namespace WindowsFormsApp3
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

    private void DoMoreDisposing()
    {
    }
  }
}

namespace WindowsFormsApp3
{
  partial class Form1
  {
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
      if (disposing && (components != null))
      {
        components.Dispose();
      }

      DoMoreDisposing();
      base.Dispose(disposing);
    }

    #region Windows Form Designer generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
      this.SuspendLayout();
      // 
      // Form1
      // 
      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
      this.ClientSize = new System.Drawing.Size(800, 450);
      this.Name = "Form1";
      this.Text = "Form1";
      this.ResumeLayout(false);

    }

    #endregion
  }
}

Expected behavior

No warning

Actual behavior

Message S1144 Remove the unused private method 'DoMoreDisposing'.

Known workarounds

Move the dispose method or mark item as false positive

Related information

  • SonarC# Version 7.11.0.8083
  • Visual Studio Version 2017
  • If running through the Scanner for MSBuild, its version 4.5.0.1761

Reproduced in VS2019 with SonarAnalyzer.CSharp 7.11.0.8083

@Evangelink Evangelink changed the title False positive for S1144: Unused private types or members should be removed Fix S1144: False Positive when private member is only used in a generated file Mar 6, 2019
@Evangelink Evangelink self-assigned this Mar 6, 2019
@Evangelink Evangelink added Area: Rules Type: False Positive Rule IS triggered when it shouldn't be. Area: C# C# rules related issues. labels Mar 6, 2019
@Evangelink Evangelink added this to the 7.12 milestone Mar 6, 2019
@Evangelink
Copy link
Contributor

Hi @ValentijnMakkenze,

Thank you for the feedback. I have been able to reproduce the issue and I found a way to avoid this issue so I'll create a PR soon.

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: False Positive Rule IS triggered when it shouldn't be.
Projects
None yet
Development

No branches or pull requests

2 participants