From c51bbc004fa82245a16311dc09af9783473c149a Mon Sep 17 00:00:00 2001 From: David Allison <62114487+david-allison-1@users.noreply.github.com> Date: Thu, 12 Nov 2020 06:19:01 +0000 Subject: [PATCH] NF: Duplicate CrowdIn Strings - Invert if Massive improvement in readability Related: 7582 --- .../lint/rules/DuplicateCrowdInStrings.java | 77 ++++++++++--------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/lint-rules/src/main/java/com/ichi2/anki/lint/rules/DuplicateCrowdInStrings.java b/lint-rules/src/main/java/com/ichi2/anki/lint/rules/DuplicateCrowdInStrings.java index 10e2e9c79b..91dddcc871 100644 --- a/lint-rules/src/main/java/com/ichi2/anki/lint/rules/DuplicateCrowdInStrings.java +++ b/lint-rules/src/main/java/com/ichi2/anki/lint/rules/DuplicateCrowdInStrings.java @@ -160,53 +160,54 @@ public class DuplicateCrowdInStrings extends ResourceXmlDetector { @Override public void afterCheckRootProject(@NotNull Context context) { for (List duplicates : allStrings.values()) { - if (duplicates.size() > 1) { - Location firstLocation = null; - Location prevLocation = null; - String prevString = ""; - boolean caseVaries = false; - List names = new ArrayList<>(); - for (StringDeclaration duplicate : duplicates) { - names.add(duplicate.getName()); - String string = duplicate.getText(); - Location location = duplicate.getLocation().resolve(); - if (prevLocation == null) { - firstLocation = location; - } else { - prevLocation.setSecondary(location); - location.setMessage(String.format("Duplicates value in `%s`", names.get(0))); - location.setSelfExplanatory(false); - if (!string.equals(prevString)) { - caseVaries = true; - location.setMessage(location.getMessage() + " (case varies, but you can use " + - "`android:inputType` or `android:capitalize` in the " + - "presentation)"); - } + if (duplicates.size() <= 1) { + continue; + } + Location firstLocation = null; + Location prevLocation = null; + String prevString = ""; + boolean caseVaries = false; + List names = new ArrayList<>(); + for (StringDeclaration duplicate : duplicates) { + names.add(duplicate.getName()); + String string = duplicate.getText(); + Location location = duplicate.getLocation().resolve(); + if (prevLocation == null) { + firstLocation = location; + } else { + prevLocation.setSecondary(location); + location.setMessage(String.format("Duplicates value in `%s`", names.get(0))); + location.setSelfExplanatory(false); + if (!string.equals(prevString)) { + caseVaries = true; + location.setMessage(location.getMessage() + " (case varies, but you can use " + + "`android:inputType` or `android:capitalize` in the " + + "presentation)"); } - prevLocation = location; - prevString = string; } - // Was in the Kotlin - but marked as unreachable - maybe a bug? + prevLocation = location; + prevString = string; + } + // Was in the Kotlin - but marked as unreachable - maybe a bug? /* if (firstLocation == null) { continue; } */ - List nameValues = new ArrayList<>(); - for (String name : names) { - nameValues.add(String.format("`%s`", name)); - } - - - String nameList = LintUtils.formatList(nameValues, nameValues.size(),true); - String message = String.format("Duplicate string value `%s`, used in %s", prevString, nameList); - if (caseVaries) { - message += ". Use `android:inputType` or `android:capitalize` " + - "to treat these as the same and avoid string duplication."; - } - context.report(ISSUE, firstLocation, message); + List nameValues = new ArrayList<>(); + for (String name : names) { + nameValues.add(String.format("`%s`", name)); } + + + String nameList = LintUtils.formatList(nameValues, nameValues.size(),true); + String message = String.format("Duplicate string value `%s`, used in %s", prevString, nameList); + if (caseVaries) { + message += ". Use `android:inputType` or `android:capitalize` " + + "to treat these as the same and avoid string duplication."; + } + context.report(ISSUE, firstLocation, message); } } } \ No newline at end of file