diff --git a/smithy-linters/src/main/java/software/amazon/smithy/linters/NoninclusiveTermsValidator.java b/smithy-linters/src/main/java/software/amazon/smithy/linters/NoninclusiveTermsValidator.java index 5ea29032692..8b4df4f0b42 100644 --- a/smithy-linters/src/main/java/software/amazon/smithy/linters/NoninclusiveTermsValidator.java +++ b/smithy-linters/src/main/java/software/amazon/smithy/linters/NoninclusiveTermsValidator.java @@ -19,9 +19,11 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; import software.amazon.smithy.model.Model; import software.amazon.smithy.model.SourceLocation; @@ -116,11 +118,11 @@ private NoninclusiveTermsValidator(Config config) { @Override public List validate(Model model) { TextIndex textIndex = TextIndex.of(model); - List validationEvents = new ArrayList<>(); + Set validationEvents = new HashSet<>(); for (TextInstance text : textIndex.getTextInstances()) { validationEvents.addAll(getValidationEvents(text)); } - return validationEvents; + return new ArrayList<>(validationEvents); } /** @@ -172,7 +174,10 @@ private ValidationEvent constructValidationEvent(TextInstance instance, return validationEvent.toBuilder() .message(String.format( "'%s' trait value at path {%s} contains a non-inclusive term `%s`.%s", - idiomaticTraitName, valuePropertyPathFormatted, matchedText, replacementAddendum)) + idiomaticTraitName, + valuePropertyPathFormatted, + matchedText.toLowerCase(), + getReplacementAddendum(matchedText.toLowerCase(), replacements))) .id(getName() + "." + TRAIT + "." + matchedText.toLowerCase(Locale.US) + "." + idiomaticTraitName + "." + valuePropertyPathFormatted) .build(); diff --git a/smithy-linters/src/test/resources/software/amazon/smithy/linters/errorfiles/noninclusive-term-filter.errors b/smithy-linters/src/test/resources/software/amazon/smithy/linters/errorfiles/noninclusive-term-filter.errors index 50e535aeaee..f0401b31af1 100644 --- a/smithy-linters/src/test/resources/software/amazon/smithy/linters/errorfiles/noninclusive-term-filter.errors +++ b/smithy-linters/src/test/resources/software/amazon/smithy/linters/errorfiles/noninclusive-term-filter.errors @@ -11,3 +11,5 @@ [WARNING] ns.foo#AOutput: 'ns.foo#MyWhitelistTrait' trait value at path {collection/2/key} contains a non-inclusive term `whitelist`. Consider using one of the following terms instead: `allowList` | NoninclusiveTerms.Trait.whitelist.ns.foo#MyWhitelistTrait.collection/2/key [WARNING] ns.foo#AOutput: 'ns.foo#MyWhitelistTrait' trait value at path {collection/1/blacklist_key} contains a non-inclusive term `blacklist`. Consider using one of the following terms instead: `denyList` | NoninclusiveTerms.Trait.blacklist.ns.foo#MyWhitelistTrait.collection/1/blacklist_key [WARNING] ns.foo#MyUnionTrait$int_whitelist: Member shape uses a non-inclusive term `whitelist`. Consider using one of the following terms instead: `allowList` | NoninclusiveTerms.Shape.whitelist +[WARNING] ns.foo#A: 'examples' trait value at path {0/MasterUsername} contains a non-inclusive term `master`. Consider using one of the following terms instead: `main`, `parent`, `primary` | NoninclusiveTerms.Trait.master.examples.0/MasterUsername +[WARNING] ns.foo#A: Error validating trait `examples`.0: Invalid structure member `MasterUsername` found for `smithy.api#Example` | TraitValue.smithy.api#Example.MasterUsername diff --git a/smithy-linters/src/test/resources/software/amazon/smithy/linters/errorfiles/noninclusive-term-filter.json b/smithy-linters/src/test/resources/software/amazon/smithy/linters/errorfiles/noninclusive-term-filter.json index 62ab3608831..1a3929bd841 100644 --- a/smithy-linters/src/test/resources/software/amazon/smithy/linters/errorfiles/noninclusive-term-filter.json +++ b/smithy-linters/src/test/resources/software/amazon/smithy/linters/errorfiles/noninclusive-term-filter.json @@ -76,7 +76,13 @@ "target": "ns.foo#AOutput" }, "traits": { - "smithy.api#readonly": {} + "smithy.api#readonly": {}, + "smithy.api#examples": [ + { + "title": "testing multiple noninclusive matches", + "MasterUsername": "master" + } + ] } }, "ns.foo#AInput": {