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

[Fix] Handle inline Flow type in boolean-prop-naming #1905

Merged
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
9 changes: 8 additions & 1 deletion lib/rules/boolean-prop-naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,14 @@ module.exports = {
list[component].node.params[0].typeAnnotation
) {
const typeNode = list[component].node.params[0].typeAnnotation;
const propType = objectTypeAnnotations.get(typeNode.typeAnnotation.id.name);
const annotation = typeNode.typeAnnotation;

let propType;
if (annotation.type === 'GenericTypeAnnotation') {
propType = objectTypeAnnotations.get(annotation.id.name);
} else if (annotation.type === 'ObjectTypeAnnotation') {
propType = annotation;
}
if (propType) {
validatePropNaming(list[component].node, propType.properties);
}
Expand Down
37 changes: 37 additions & 0 deletions tests/lib/rules/boolean-prop-naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,23 @@ ruleTester.run('boolean-prop-naming', rule, {
options: [{
rule: '^is[A-Z]([A-Za-z0-9]?)+'
}]
}, {
// inline Flow type
code: `
function SomeComponent({
isSomething,
}: {
isSomething: boolean,
}) {
return (
<span>{isSomething}</span>
);
}
`,
options: [{
rule: '^is[A-Z]([A-Za-z0-9]?)+'
}],
parser: 'babel-eslint'
}],

invalid: [{
Expand Down Expand Up @@ -772,5 +789,25 @@ ruleTester.run('boolean-prop-naming', rule, {
errors: [{
message: 'Prop name (something) doesn\'t match rule (^is[A-Z]([A-Za-z0-9]?)+)'
}]
}, {
// inline Flow type
code: `
function SomeComponent({
something,
}: {
something: boolean,
}) {
return (
<span>{something}</span>
);
}
`,
options: [{
rule: '^is[A-Z]([A-Za-z0-9]?)+'
}],
parser: 'babel-eslint',
errors: [{
message: 'Prop name (something) doesn\'t match rule (^is[A-Z]([A-Za-z0-9]?)+)'
}]
}]
});