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

Fix S4158 FP: Should not report on HashSet.UnionWith for readonly fields. #8483

Closed
pavel-mikula-sonarsource opened this issue Dec 19, 2023 · 0 comments · Fixed by #8712
Closed
Assignees
Labels
Area: C# C# rules related issues. Area: VB.NET VB.NET rules related issues. Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules.
Milestone

Comments

@pavel-mikula-sonarsource
Copy link
Contributor

https://sonarcloud.io/project/issues?open=AYqIsHtcRlgCy-_ohqo9&id=sonarlint-visualstudio

S4158 should not report on UnionWith, when the symbol is a read-only field. Because changing it to non-read-only is not a desirable action.

To consider: should it be even raised on local variables? As there's no AddRange, and replacing the entire instance is not always an option.

private readonly ISet<string> supportedSchemes = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

public void Go(ISet<string> supportedSchemes)
{
    this.supportedSchemes.Clear();
    this.supportedSchemes.UnionWith(supportedSchemes); // FP, as there's no AddRange method in HashSet
}
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: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants