Skip to content

Commit

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

/**
Expand Down Expand Up @@ -174,10 +172,7 @@ 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.toLowerCase(),
getReplacementAddendum(matchedText.toLowerCase(), replacements)))
idiomaticTraitName, valuePropertyPathFormatted, matchedText, replacementAddendum))
.id(getName() + "." + TRAIT + "." + matchedText.toLowerCase(Locale.US)
+ "." + idiomaticTraitName + "." + valuePropertyPathFormatted)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
[WARNING] ns.foo#AOutput: 'ns.foo#MyWhitelistTrait' trait value at path {document/foo/0/bar} contains a non-inclusive term `whitelist`. Consider using one of the following terms instead: `allowList` | NoninclusiveTerms.Trait.whitelist.ns.foo#MyWhitelistTrait.document/foo/0/bar
[WARNING] ns.foo#AOutput: 'ns.foo#MyWhitelistTrait' trait value at path {nested/master_key_violation} contains a non-inclusive term `whitelist`. Consider using one of the following terms instead: `allowList` | NoninclusiveTerms.Trait.whitelist.ns.foo#MyWhitelistTrait.nested/master_key_violation
[WARNING] ns.foo#AOutput: 'ns.foo#MyWhitelistTrait' trait value at path {string_value} contains a non-inclusive term `whitelist`. Consider using one of the following terms instead: `allowList` | NoninclusiveTerms.Trait.whitelist.ns.foo#MyWhitelistTrait.string_value
[WARNING] ns.foo#AOutput: 'ns.foo#MyWhitelistTrait' trait value at path {document/whitelist_doc_key_violation_1} contains a non-inclusive term `whitelist`. Consider using one of the following terms instead: `allowList` | NoninclusiveTerms.Trait.whitelist.ns.foo#MyWhitelistTrait.document/whitelist_doc_key_violation_1
[WARNING] ns.foo#AOutput: 'ns.foo#MyWhitelistTrait' trait value at path {document/whitelist_doc_key_violation_1/key} contains a non-inclusive term `whitelist`. Consider using one of the following terms instead: `allowList` | NoninclusiveTerms.Trait.whitelist.ns.foo#MyWhitelistTrait.document/whitelist_doc_key_violation_1/key
[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#AOutput: 'ns.foo#MyWhitelistTrait' trait value at path {collection/1/blacklist_key/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/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
[WARNING] ns.foo#A: 'examples' trait value at path {0/MasterUsername/key} contains a non-inclusive term `Master`. Consider using one of the following terms instead: `Main`, `Parent`, `Primary` | NoninclusiveTerms.Trait.master.examples.0/MasterUsername/key
[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
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"smithy.api#readonly": {},
"smithy.api#examples": [
{
"title": "testing multiple noninclusive matches",
"title": "testing noninclusive key and value",
"MasterUsername": "master"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ private static void computeTextInstancesForAppliedTrait(
if (memberTypeShape == null) {
//This means the "property" key value isn't modeled in the trait's structure/shape definition
//and this text instance is unique
propertyPath.offerLast("key");
textInstances.add(TextInstance.createTraitInstance(
memberEntry.getKey(), parentShape, trait, propertyPath));
propertyPath.removeLast();
}
computeTextInstancesForAppliedTrait(memberEntry.getValue(), trait, parentShape, textInstances,
propertyPath, model, memberTypeShape);
Expand Down

0 comments on commit 5fd9a29

Please sign in to comment.