Skip to content

Commit

Permalink
Fix FilterSuppressions to match on hierarchy (#1631)
Browse files Browse the repository at this point in the history
  • Loading branch information
srchase authored Feb 24, 2023
1 parent 77c49fb commit 8f32289
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,10 @@ 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));
allowed.removeIf(value -> matchedEvents.stream().noneMatch(event -> event.containsId(value)));
}

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 8f32289

Please sign in to comment.