Some continue statements are flagged as “Refactor the containing loop to do more than one iteration”, even though a continue statement cannot reduce the number of iterations a loop does. break, goto, return, and throw (at least) can reduce the number of iterations, but not continue.
static void Foo(string[] list) {
foreach (string s in list) {
continue; // Incorrect S1751 (also a correct S3626 in this sample, but not in the production code)
}
}
I’m using SonarQube 8.26.0.14164 on Visual Studio 17.14.14 and Windows 11 24H2.
They’re similar, but I’m only concerned with the use of S1751 on continue statements, while that also discusses return and break.
The issue I see here is that neither the error text nor description match the behavior of a continue statement. The fix that seems reasonable to me in this case, depending on the intent of S1751, is either
(a) never issue S1751 on a continue statement, because continue statements never reduce the loop count (possibly also introduce a new diagnostic for unconditional continues), or
(b) change the text of S1751 to something like “Refactor the containing loop to perform this jump statement conditionally,” and change C# static code analysis (the S1751 help page) to match the intended concern of unconditional jump statements rather than single-iteration loops.