-
Notifications
You must be signed in to change notification settings - Fork 231
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 S4143: FP with List<T>.Add
method calls
#2674
Comments
I think it is okay that this warning is shown. You could argue that this behaviour should not be applied on a You could argue that the message should than be different, but it tells you (indirectly) why this is a bad practice: a list is intended for keeping track of multiple elements of T ( |
I'd argue that a list is allowed to have duplicate entries in it, if I wanted unique then I'd be using a dictionary or hashset. |
Hello @cg110 , thanks for reporting this. |
List<T>.Add
method calls
List<T>.Add
method callsList<T>.Add
method calls
Description
Using the SonarAnalyzer.CSharp nuget, S4143 flags issues for List (and probably any lists)
Repro steps
Using the code:
The last 2 Adds are showing with warnings for S4143, as they are Adds they're extending the list rather than overwriting any existing entries.
Expected behavior
The above code shouldn't generate a warning.
Actual behavior
S4143 generates warnings.
Known workarounds
Set the warning to info or suppress.
Related information
The text was updated successfully, but these errors were encountered: