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 S6964 FP: Issues should not be raised in autogenerated code #9260

Closed
hugoqribeiro opened this issue May 8, 2024 · 1 comment
Closed
Labels
Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be.

Comments

@hugoqribeiro
Copy link

hugoqribeiro commented May 8, 2024

Description

S6964 is not respecting generated code.

Repro steps

This rule is being triggered on a model defined in a file named Models.gen.cs, that includes the auto-generated comment, in a class that is annotated with GeneratedCode attribute.

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

[System.CodeDom.Compiler.GeneratedCode("Lithium", "8")]
public abstract partial class ClaimDataBase
{
    [Cegid.Hydrogen.ComponentModel.DataAnnotations.Required(AllowEmptyStrings = false)]
    [Cegid.Hydrogen.ComponentModel.DataAnnotations.TextMaxLength(250)]
    [System.ComponentModel.DataAnnotations.Display(Name = nameof(Localization.ModelsResources.RES_Display_ClaimData_Type), ResourceType = typeof(Localization.ModelsResources))]
    [System.Diagnostics.CodeAnalysis.MaybeNull]
    [System.Text.Json.Serialization.JsonPropertyName("type")]
    public virtual string Type
    {
        get;
        set;
    }

    // (...)
}

Expected behavior

Generated code should not trigger rules.

It would be nice if the rule allowed to configure which attribute is applying the Required semantic. Notice that we're using our own attribute.

Known workarounds

None.

Related information

  • SonarAnalyzer.CSharp version 9.25.0.90414
  • Visual Studio 17.9.6
  • .NET 8.0.204
  • Windows 10
@hugoqribeiro hugoqribeiro changed the title Fix Sxxxx FP/FN: Issue title Fix S6964 FP/FN: rule applied to generated code May 8, 2024
@hugoqribeiro hugoqribeiro changed the title Fix S6964 FP/FN: rule applied to generated code Fix S6964 FP: rule applied to generated code May 8, 2024
@hugoqribeiro hugoqribeiro changed the title Fix S6964 FP: rule applied to generated code S6964 rule applied to generated code May 8, 2024
@mary-georgiou-sonarsource
Copy link
Contributor

Hello again @hugoqribeiro,

I confirm this should not happen - we already have an open issue to fix this behavior.

@mary-georgiou-sonarsource mary-georgiou-sonarsource changed the title S6964 rule applied to generated code S6964 should not raise issues in autogenerated code May 15, 2024
@mary-georgiou-sonarsource mary-georgiou-sonarsource changed the title S6964 should not raise issues in autogenerated code Fix S6964 FP: Issues should not be raised in autogenerated code May 15, 2024
@mary-georgiou-sonarsource mary-georgiou-sonarsource added Area: C# C# rules related issues. Type: False Positive Rule IS triggered when it shouldn't be. labels May 15, 2024
@mary-georgiou-sonarsource mary-georgiou-sonarsource closed this as not planned Won't fix, can't repro, duplicate, stale May 16, 2024
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