Skip to content

Commit 05d781b

Browse files
authored
Merge pull request #1905 from alexzherdev/1700-boolean-prop-naming-flow-crash
[Fix] Handle inline Flow type in boolean-prop-naming
2 parents 4e80833 + 470fdd9 commit 05d781b

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

lib/rules/boolean-prop-naming.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,14 @@ module.exports = {
235235
list[component].node.params[0].typeAnnotation
236236
) {
237237
const typeNode = list[component].node.params[0].typeAnnotation;
238-
const propType = objectTypeAnnotations.get(typeNode.typeAnnotation.id.name);
238+
const annotation = typeNode.typeAnnotation;
239+
240+
let propType;
241+
if (annotation.type === 'GenericTypeAnnotation') {
242+
propType = objectTypeAnnotations.get(annotation.id.name);
243+
} else if (annotation.type === 'ObjectTypeAnnotation') {
244+
propType = annotation;
245+
}
239246
if (propType) {
240247
validatePropNaming(list[component].node, propType.properties);
241248
}

tests/lib/rules/boolean-prop-naming.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,23 @@ ruleTester.run('boolean-prop-naming', rule, {
358358
options: [{
359359
rule: '^is[A-Z]([A-Za-z0-9]?)+'
360360
}]
361+
}, {
362+
// inline Flow type
363+
code: `
364+
function SomeComponent({
365+
isSomething,
366+
}: {
367+
isSomething: boolean,
368+
}) {
369+
return (
370+
<span>{isSomething}</span>
371+
);
372+
}
373+
`,
374+
options: [{
375+
rule: '^is[A-Z]([A-Za-z0-9]?)+'
376+
}],
377+
parser: 'babel-eslint'
361378
}],
362379

363380
invalid: [{
@@ -772,5 +789,25 @@ ruleTester.run('boolean-prop-naming', rule, {
772789
errors: [{
773790
message: 'Prop name (something) doesn\'t match rule (^is[A-Z]([A-Za-z0-9]?)+)'
774791
}]
792+
}, {
793+
// inline Flow type
794+
code: `
795+
function SomeComponent({
796+
something,
797+
}: {
798+
something: boolean,
799+
}) {
800+
return (
801+
<span>{something}</span>
802+
);
803+
}
804+
`,
805+
options: [{
806+
rule: '^is[A-Z]([A-Za-z0-9]?)+'
807+
}],
808+
parser: 'babel-eslint',
809+
errors: [{
810+
message: 'Prop name (something) doesn\'t match rule (^is[A-Z]([A-Za-z0-9]?)+)'
811+
}]
775812
}]
776813
});

0 commit comments

Comments
 (0)