Skip to content

Commit

Permalink
Merge pull request #1905 from alexzherdev/1700-boolean-prop-naming-fl…
Browse files Browse the repository at this point in the history
…ow-crash

[Fix] Handle inline Flow type in boolean-prop-naming
  • Loading branch information
ljharb committed Jul 27, 2018
2 parents 4e80833 + 470fdd9 commit 05d781b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/rules/boolean-prop-naming.js
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
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]?)+)'
}]
}]
});

0 comments on commit 05d781b

Please sign in to comment.