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

Fields and properties with different string values in them should not be marked as duplicate #2614

Open
andrei-epure-sonarsource opened this issue Aug 30, 2019 · 2 comments
Labels
Area: C# C# rules related issues. Area: VB.NET VB.NET rules related issues. Type: Rule rework Change rule behavior

Comments

@andrei-epure-sonarsource
Copy link
Contributor

Description

With a base class

    internal abstract class CodeGenBase
    {
        protected abstract string GenericTypeStart { get; }
        protected abstract string GenericTypeEnd { get; }
    }

and two sub classes

    class CodeGenCs : CodeGenBase
    {
        Type[] types = { typeof(int), typeof(uint), typeof(string) };

        string[] names = { "int", "uint", "string" };

        protected override string GenericTypeStart => "<";

        protected override string GenericTypeEnd => ">";
        // ... some duplicated code below to make sure class has many lines
    }

and

   class CodeGenVb : CodeGenBase
    {
        Type[] types = { typeof(int), typeof(uint), typeof(string) };

        string[] names = { "Integer", "UInteger", "String" };

        protected override string GenericTypeStart => "(Of";

        protected override string GenericTypeEnd => ")";
        // ... some duplicated code below to make sure class has many lines
    }

The lines with names, GenericTypeStart and GenericTypeEnd are marked as duplicates, even if the string values they contain are different.

See this community thread for details

Expected behavior

Lines that are not duplicated should be considered as such.

Related information

  • SonarC# Version 7.16
@pavel-mikula-sonarsource
Copy link
Contributor

@andrei-epure-sonarsource Can you please add labels since it's confirmed? I'm not sure how/where code duplication for SQ is generated.

@andrei-epure-sonarsource andrei-epure-sonarsource added Area: SQ Plugin Java plugin related issues. Area: C# C# rules related issues. Area: VB.NET VB.NET rules related issues. and removed Area: SQ Plugin Java plugin related issues. labels Dec 9, 2019
@andrei-epure-sonarsource
Copy link
Contributor Author

I guess it's the dotnet analyzers which compute the metrics for syntax nodes and in this case it probably doesn't check the content of the string values.

it is confirmed, I remember I tried to do a repro

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. Area: VB.NET VB.NET rules related issues. Type: Rule rework Change rule behavior
Projects
None yet
Development

No branches or pull requests

3 participants