Multiple rules triggered for the same cause (csharpsquid:2223 + csharpsquid:1104 + roslyn:CA2221)

Version: SonarQube Version 10.1 (build 73491)

This is not strictly a false positive, but rather a case of conflicting / redundant rules / presentation for code like this:

public static IReadOnlyCollection<SomeType> = SomeStaticCollectionField;

This single line for a single reason triggers three separate rules:

See this screenshot for more context:

As the root cause is only one, I think only one code smell should be detected here.

Hello @m-gallesio

You are right about the rules having an overlap in this case. But there are good reasons for raising both rules here. First, users can disable one of the two rules if they disagree. In such a case, we would miss the issue if we do not report for both rules.
The second cause is that both rules have different severity (Critical and Minor). S2223 is about mutable global state, which is much more severe than S1104, which is about insufficient encapsulation. You may have reasons to ignore the minor issue (even the .NET runtime does: EventArgs.Empty Field) but S2223 should be addressed.

Best, Martin

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.