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. Sprint: SE Short-lived* label for epic MMF-3077 *troll Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules.
Projects
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
}
@pavel-mikula-sonarsource pavel-mikula-sonarsource added Area: VB.NET VB.NET rules related issues. Area: C# C# rules related issues. Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules. labels Dec 19, 2023
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource added the Sprint: SE Short-lived* label for epic MMF-3077 *troll label Feb 8, 2024
@github-actions github-actions bot added this to To do in Best Kanban Feb 8, 2024
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource added this to the 9.20 milestone Feb 8, 2024
@github-actions github-actions bot moved this from To do to Review in progress in Best Kanban Feb 8, 2024
@github-actions github-actions bot moved this from Review in progress to Review approved in Best Kanban Feb 8, 2024
Best Kanban automation moved this from Review approved to Validate Peach Feb 8, 2024
@zsolt-kolbay-sonarsource zsolt-kolbay-sonarsource moved this from Validate Peach to Done in Best Kanban Feb 9, 2024
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. Sprint: SE Short-lived* label for epic MMF-3077 *troll Type: CFG/SE FPs Rule IS triggered when it shouldn't be for CFG and SE rules.
Projects
Best Kanban
  
Done
Development

Successfully merging a pull request may close this issue.

3 participants