Skip to content

Commit

Permalink
Fixed duplicate NoninclusiveTerms events
Browse files Browse the repository at this point in the history
  • Loading branch information
rchache committed Sep 12, 2023
1 parent 4815bf7 commit 5b8717c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -116,11 +118,11 @@ private NoninclusiveTermsValidator(Config config) {
@Override
public List<ValidationEvent> validate(Model model) {
TextIndex textIndex = TextIndex.of(model);
List<ValidationEvent> validationEvents = new ArrayList<>();
Set<ValidationEvent> validationEvents = new HashSet<>();
for (TextInstance text : textIndex.getTextInstances()) {
validationEvents.addAll(getValidationEvents(text));
}
return validationEvents;
return new ArrayList<>(validationEvents);
}

/**
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 5b8717c

Please sign in to comment.