Skip to content

Commit

Permalink
Fix FilterSuppressions to match on hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
srchase committed Feb 24, 2023
1 parent ff9df7d commit af5a8c6
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,18 @@ private Model filterSuppressionTraits(

// Only keep IDs that actually acted to suppress an event.
if (config.getRemoveUnused()) {
Set<String> matched = suppressedEvents.stream()
Set<ValidationEvent> matchedEvents = suppressedEvents.stream()
.filter(event -> Objects.equals(shape.getId(), event.getShapeId().orElse(null)))
.map(ValidationEvent::getId)
.collect(Collectors.toSet());
allowed.removeIf(value -> !matched.contains(value));
List<String> toKeep = new ArrayList<>();
for (String allowedValue : allowed) {
for (ValidationEvent event : matchedEvents) {
if (event.containsId(allowedValue)) {
toKeep.add(allowedValue);
}
}
}
allowed = toKeep;
}

if (allowed.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public void cannotSetBothNamespaceAllowAndDenyList() {
"namespaces,filterWithProjectionImports",
"namespaces,detectsValidatorRemoval",
"namespaces,unchanged",
"noSuppressions,removeUnused"
"noSuppressions,removeUnused",
"eventHierarchy,removeUnused"
})
public void runTransformTests(String modelFile, String testName) throws Exception {
Model model = Model.assembler()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0",
"projections": {
"foo": {
"transforms": [
{
"name": "filterSuppressions",
"args": {
"removeUnused": true
}
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
$version: "2.0"

metadata validators = [
{
name: "EmitEachSelector",
id: "A.B",
severity: "WARNING",
configuration: {
selector: ":not([id='smithy.example#NoMatches'])"
}
},
{
name: "EmitEachSelector",
id: "B.C.D",
severity: "WARNING",
configuration: {
selector: ":not([id='smithy.example#NoMatches'])"
}
}
]

namespace smithy.example

@suppress(["A", "B.C"])
structure Foo {
@suppress(["A", "B.C"])
foo: String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
$version: "2.0"

metadata validators = [
{
name: "EmitEachSelector",
id: "A.B",
severity: "WARNING",
configuration: {
selector: ":not([id='smithy.example#NoMatches'])"
}
},
{
name: "EmitEachSelector",
id: "B.C.D",
severity: "WARNING",
configuration: {
selector: ":not([id='smithy.example#NoMatches'])"
}
}
]

namespace smithy.example

@suppress(["A", "B.C"])
structure Foo {
@suppress(["A", "B.C"])
foo: String
}

0 comments on commit af5a8c6

Please sign in to comment.