From 470fdd9713fa75e20a77f056effdfc51c78f5030 Mon Sep 17 00:00:00 2001 From: Alex Zherdev Date: Thu, 26 Jul 2018 20:22:26 -0700 Subject: [PATCH] [Fix] Handle inline Flow type in boolean-prop-naming Resolves #1700 --- lib/rules/boolean-prop-naming.js | 9 ++++++- tests/lib/rules/boolean-prop-naming.js | 37 ++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/lib/rules/boolean-prop-naming.js b/lib/rules/boolean-prop-naming.js index fb8b204a3a..f65b8101f4 100644 --- a/lib/rules/boolean-prop-naming.js +++ b/lib/rules/boolean-prop-naming.js @@ -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); } diff --git a/tests/lib/rules/boolean-prop-naming.js b/tests/lib/rules/boolean-prop-naming.js index 384557ec65..16f000a7a6 100644 --- a/tests/lib/rules/boolean-prop-naming.js +++ b/tests/lib/rules/boolean-prop-naming.js @@ -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 ( + {isSomething} + ); + } + `, + options: [{ + rule: '^is[A-Z]([A-Za-z0-9]?)+' + }], + parser: 'babel-eslint' }], invalid: [{ @@ -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 ( + {something} + ); + } + `, + 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]?)+)' + }] }] });