Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude enum and intEnum from some linting #1133

Merged
merged 1 commit into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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