Is your feature request related to a problem? Please describe.
UnusedLocalVariable, UnusedFormalParameter flag all unused variables.
Describe the solution you'd like
Please add a property to the rule specifying a pattern such as starts with $, _ or unused for the variable name so that variables that meet the criteria are excluded. Additionally, you could support custom annotations that mark the variables as Unused. e.g., @Unused.
Describe alternatives you've considered
Example code flagged by ForLoopCanBeForEach when usual for loop used:
@SuppressWarnings("PMD.UnusedLocalVariable")
@Override
public Solution solve() {
int[] dp = new int[capacity + 1];
List<Item> itemsList = new ArrayList<>(items.length);
int i = 0;
for (int dpVal : dp) {
for (Item item : items) {
if (item.weight <= i) {
int includedVal = dp[i - item.weight] + item.value;
if (includedVal > dp[i]) dp[i] = includedVal;
}
}
++i;
}
path(items, capacity, dp, itemsList);
itemsList = Item.pack(itemsList);
return new Solution(itemsList, dp[capacity]);
}
Additional context
Haskell/Python style
Error-prone
Also see #2923
Is your feature request related to a problem? Please describe.
UnusedLocalVariable, UnusedFormalParameter flag all unused variables.
Describe the solution you'd like
Please add a property to the rule specifying a pattern such as starts with
$,_orunusedfor the variable name so that variables that meet the criteria are excluded. Additionally, you could support custom annotations that mark the variables as Unused. e.g.,@Unused.Describe alternatives you've considered
Example code flagged by ForLoopCanBeForEach when usual for loop used:
Additional context
Haskell/Python style
Error-prone
Also see #2923