From 0714704b73fcc9dfe260dc1327ee82b9c6f97168 Mon Sep 17 00:00:00 2001 From: HenryBrown0 <26250092+HenryBrown0@users.noreply.github.com> Date: Sun, 24 Sep 2023 13:36:54 +0100 Subject: [PATCH] [Refactor] `boolean-prop-naming`: invert if statement Co-authored-by: HenryBrown0 <26250092+HenryBrown0@users.noreply.github.com> Co-authored-by: Jordan Harband --- CHANGELOG.md | 1 + lib/rules/boolean-prop-naming.js | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 210cc8666b..16cb6cc0a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange ### Changed * [Refactor] `propTypes`: extract type params to var ([#3634][] @HenryBrown0) +* [Refactor] [`boolean-prop-naming`]: invert if statement ([#3634][] @HenryBrown0) [#3638]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3638 [#3634]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3634 diff --git a/lib/rules/boolean-prop-naming.js b/lib/rules/boolean-prop-naming.js index f1c7420a7f..b5dd37b529 100644 --- a/lib/rules/boolean-prop-naming.js +++ b/lib/rules/boolean-prop-naming.js @@ -240,19 +240,24 @@ module.exports = { } if ( - component.node.parent - && component.node.parent.type === 'VariableDeclarator' - && component.node.parent.id - && component.node.parent.id.type === 'Identifier' - && component.node.parent.id.typeAnnotation - && component.node.parent.id.typeAnnotation.typeAnnotation - && component.node.parent.id.typeAnnotation.typeAnnotation.typeParameters - && ( - component.node.parent.id.typeAnnotation.typeAnnotation.typeParameters.type === 'TSTypeParameterInstantiation' - || component.node.parent.id.typeAnnotation.typeAnnotation.typeParameters.type === 'TypeParameterInstantiation' + !component.node.parent + || component.node.parent.type !== 'VariableDeclarator' + || !component.node.parent.id + || component.node.parent.id.type !== 'Identifier' + || !component.node.parent.id.typeAnnotation + || !component.node.parent.id.typeAnnotation.typeAnnotation + ) { + return; + } + + const annotationTypeParams = component.node.parent.id.typeAnnotation.typeAnnotation.typeParameters; + if ( + annotationTypeParams && ( + annotationTypeParams.type === 'TSTypeParameterInstantiation' + || annotationTypeParams.type === 'TypeParameterInstantiation' ) ) { - return component.node.parent.id.typeAnnotation.typeAnnotation.typeParameters.params.find( + return annotationTypeParams.params.find( (param) => param.type === 'TSTypeReference' || param.type === 'GenericTypeAnnotation' ); }