Implemented solution via #3066:
The following rules are affected:
The following variable names are ignored:
- any name starting with
ignored, e.g. ignoredParameter
- any name starting with
unused, e.g. unusedVar
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 or @Ignored.
E.g., https://github.com/Lanchon/r8/blob/e22a77d26e30615bfc9b5f598bb0f58f10dd082c/src/test/java/com/android/tools/r8/shaking/ifrule/IfOnAnnotationTestClasses.java
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
Referenced from: #2838
Implemented solution via #3066:
The following rules are affected:
The following variable names are ignored:
ignored, e.g.ignoredParameterunused, e.g.unusedVarIs 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.,
@Unusedor@Ignored.E.g., https://github.com/Lanchon/r8/blob/e22a77d26e30615bfc9b5f598bb0f58f10dd082c/src/test/java/com/android/tools/r8/shaking/ifrule/IfOnAnnotationTestClasses.java
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
Referenced from: #2838