Skip to content

Commit

Permalink
Exclude enum and intEnum from some linting
Browse files Browse the repository at this point in the history
This commit excludes linting enum and intEnum members for AbbreviationName
and CamelCase checks, as they are intended to be CAPS_SNAKE.
  • Loading branch information
kstich committed Mar 15, 2022
1 parent e4410e6 commit 91a1656
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,20 @@ private AbbreviationNameValidator(Config config) {
@Override
public List<ValidationEvent> validate(Model model) {
return model.shapes()
.flatMap(this::validateShapeName)
.flatMap(shape -> validateShapeName(model, shape))
.collect(Collectors.toList());
}

private Stream<ValidationEvent> validateShapeName(Shape shape) {
private Stream<ValidationEvent> validateShapeName(Model model, Shape shape) {
// Exclude members of enums from AbbreviationName validation,
// as they're intended to be CAPS_SNAKE.
if (shape.isMemberShape()) {
Shape container = model.expectShape(shape.asMemberShape().get().getContainer());
if (container.isEnumShape() || container.isIntEnumShape()) {
return Stream.empty();
}
}

String descriptor = shape.isMemberShape() ? "member" : "shape";
String name = shape.asMemberShape()
.map(MemberShape::getMemberName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ public List<ValidationEvent> validate(Model model) {

Pattern isValidMemberName = config.getMemberNames().getRegex();
model.shapes(MemberShape.class)
// Exclude members of enums from CamelCase validation,
// as they're intended to be CAPS_SNAKE.
.filter(shape -> {
Shape container = model.expectShape(shape.asMemberShape().get().getContainer());
return !container.isEnumShape() && !container.isIntEnumShape();
})
.filter(shape -> !isValidMemberName.matcher(shape.getMemberName()).find())
.map(shape -> danger(shape, format(
"Member shape member name, `%s`, is not %s camel case",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,28 @@
"target": "ns.foo#FooId"
}
}
},
"ns.foo#Enum": {
"type": "enum",
"members": {
"NAME": {
"target": "smithy.api#Unit",
"traits": {
"smithy.api#enumValue": "foo"
}
}
}
},
"ns.foo#IntEnum": {
"type": "intEnum",
"members": {
"NAME": {
"target": "smithy.api#Unit",
"traits": {
"smithy.api#enumValue": 1
}
}
}
}
},
"metadata": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,28 @@
},
"smithy.api#authDefinition": {}
}
},
"ns.foo#Enum": {
"type": "enum",
"members": {
"NAME": {
"target": "smithy.api#Unit",
"traits": {
"smithy.api#enumValue": "foo"
}
}
}
},
"ns.foo#IntEnum": {
"type": "intEnum",
"members": {
"NAME": {
"target": "smithy.api#Unit",
"traits": {
"smithy.api#enumValue": 1
}
}
}
}
},
"metadata": {
Expand Down

0 comments on commit 91a1656

Please sign in to comment.