sonar-dotnet icon indicating copy to clipboard operation
sonar-dotnet copied to clipboard

CSharpExecutableLinesMetric does not count executable line for multiple syntax kinds

Open csaba-sagi-sonarsource opened this issue 4 years ago • 5 comments

Description

CSharpExecutableLinesMetric does not count executable line for expression bodied methods, variable declarations with initialization, switch expression arms and using statements.

Repro steps


 public static bool IsLetter(this char c) =>
                                c is >= 'a' and <= 'z' or >= 'A' and <= 'Z'; // FN

var x = s switch
                            {
                                    ""a"" => true, // FN
                                    ""b"" => false, // FN
                                    _ => true // FN
                            };

Expected behavior

CSharpExecutableLinesMetric counts executable line for expression bodied methods and also for switch expression arms.

Actual behavior

CSharpExecutableLinesMetric does not count those lines.

Known workarounds

Related information

  • C#/VB.NET Plugins version: 8.26.0.34506

csaba-sagi-sonarsource avatar Jul 15 '21 08:07 csaba-sagi-sonarsource

@csaba-sagi-sonarsource is this truly a False Positive? I don't understand from the description the FPs this problem creates.

@csaba-sagi-sonarsource is this truly a False Positive? I don't understand from the description the FPs this problem creates.

This is not an FP, I`ll update the labels.

csaba-sagi-sonarsource avatar Sep 03 '21 15:09 csaba-sagi-sonarsource

@tom-howlett-sonarsource did you get to talk in the PM team about this?

See this comment - https://github.com/SonarSource/sonar-dotnet/pull/4695#issuecomment-881273807

I think I did have extensive discussion around ExecutableLines, although I'm not sure we came to a good conclusion. I think the main issue here is whether we need to notify users when there is a change and that decision would be made based on the likely size of the change on the ExecutableLinesMetric. If we do notify users we should consider the most effective way to do so.

tom-howlett-sonarsource avatar May 04 '22 16:05 tom-howlett-sonarsource

@tom-howlett-sonarsource should this go in the LTS?