S1854 Unused assignments should be removed

Please provide

  • Operating system: win 11
  • Visual Studio version: 17.6
  • SonarLint plugin version: 7.7.0.86423
  • Programming language you’re coding in: c#
  • Is connected mode used: NO
    • Connected to SonarCloud or SonarQube (and which version):

And a thorough description of the problem / question:

S1854 rule marks code as unused assignment but it’s used, because its a function Parameter
sample: AddGroup(++visibleIndex, “Name”); so the incremented value is used

Hi Robert,

Welcome to the community and thanks for sharing this with us.
This report is actually about the fact that you are using a side-effect (incrementing the value of visibleIndex) but not using the variable after.

In that case, we would expect to see visibleIndex+1 instead.
Usually, you would use the ++ notation if you expect to use the incremented value after the call to AddGroup.

Side note: you can report findings like these under the “Clean Code / Report False Positive-False Negative” topic.
Denis