Unused variables are either useless code and should be removed or a copy-paste error.
What constitutes use of variables varies based on several factors.:
- For primitive variables simply changing the value does not qualify as use.
- For list variables, changing the list by adding or removing elements does not qualify as a meaningful use unless that variable is a parameter.
- For non-persistent object variables, commit/rollback/delete without refresh are not considered as meaningful use unless the objects is a parameter.
- For object variables, changing an attribute is not considered meaningful use unless the variable is a parameter/iterable in a loop. Changing an association is always considered a meaningful use.
Disclaimer: We expect that this rule will trigger violations which are “false positives” i.e. violations that are not really something that needs your attention. In our view, the cost of a false positive is not as high as the cost of missing a bug. A false positive is easy to whitelist. On the other hand, a bug that ACR fails to detect can have large repercussions and costs in terms of development time and customer satisfaction. Therefore we will keep this rule as is in the hopes of catching bugs and accepting the occasional false positive.