13 New code quality rules for .Net developers

Hello .Net developers,

During the past month we have added 4 Bug detection and 9 Code Smell rules:

  • S2251 (C#) A “for” loop update clause should move the counter in the right direction (Bug)
  • S2252 (C#) Loop conditions should be true at least once (Bug)
  • S2857 (C#) SQL keywords should be delimited by whitespace (Bug)
  • S4583 (C#) Calls to delegate’s method “BeginInvoke” should be paired with calls to “EndInvoke” (Bug)
  • S4136 (C#, VB.Net) Method overloads should be grouped together (Code Smell)
  • S4201 (C#, VB.Net) Null checks should not be used with “instanceof” (Code Smell)
  • S2302 (improved in C#, new in VB.Net) “nameof” should be used (Code Smell)
  • S2479 (C#) Whitespace and control characters in string literals should be explicit (Code Smell)
  • S4487 (C#) Unread “private” fields should be removed (Code Smell)
  • S4635 (C#) String offset-based methods should be preferred for finding substrings from offsets (Code Smell)
  • S1128 (C#) Unnecessary imports should be removed (Code Smell)
  • S1199 (C#) Nested code blocks should not be used (Code Smell)
  • S5034 (C#) “ValueTask” should be consumed correctly (Code Smell)

A big thank you to Alex Angas and Corniel Nobel for having suggested some of these new rules.
If you use SonarQube/SonarCloud/SonarLint and have suggestions, don’t hesitate to post them on this forum (new rule ideas, False Positives or other bugs)

You can already enjoy these new rules on SonarCloud. As for SonarQube, we invite you to install SonarC# and SonarVB 8.0. For more information you can see the changelogs here: v7.17, v8.0.

All feedback is welcome.

Cheers,
Nicolas

2 Likes