Skip to content

Commit 0714704

Browse files
HenryBrown0ljharb
andcommitted
[Refactor] boolean-prop-naming: invert if statement
Co-authored-by: HenryBrown0 <[email protected]> Co-authored-by: Jordan Harband <[email protected]>
1 parent 9fb0d42 commit 0714704

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1616

1717
### Changed
1818
* [Refactor] `propTypes`: extract type params to var ([#3634][] @HenryBrown0)
19+
* [Refactor] [`boolean-prop-naming`]: invert if statement ([#3634][] @HenryBrown0)
1920

2021
[#3638]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3638
2122
[#3634]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3634

lib/rules/boolean-prop-naming.js

+16-11
Original file line numberDiff line numberDiff line change
@@ -240,19 +240,24 @@ module.exports = {
240240
}
241241

242242
if (
243-
component.node.parent
244-
&& component.node.parent.type === 'VariableDeclarator'
245-
&& component.node.parent.id
246-
&& component.node.parent.id.type === 'Identifier'
247-
&& component.node.parent.id.typeAnnotation
248-
&& component.node.parent.id.typeAnnotation.typeAnnotation
249-
&& component.node.parent.id.typeAnnotation.typeAnnotation.typeParameters
250-
&& (
251-
component.node.parent.id.typeAnnotation.typeAnnotation.typeParameters.type === 'TSTypeParameterInstantiation'
252-
|| component.node.parent.id.typeAnnotation.typeAnnotation.typeParameters.type === 'TypeParameterInstantiation'
243+
!component.node.parent
244+
|| component.node.parent.type !== 'VariableDeclarator'
245+
|| !component.node.parent.id
246+
|| component.node.parent.id.type !== 'Identifier'
247+
|| !component.node.parent.id.typeAnnotation
248+
|| !component.node.parent.id.typeAnnotation.typeAnnotation
249+
) {
250+
return;
251+
}
252+
253+
const annotationTypeParams = component.node.parent.id.typeAnnotation.typeAnnotation.typeParameters;
254+
if (
255+
annotationTypeParams && (
256+
annotationTypeParams.type === 'TSTypeParameterInstantiation'
257+
|| annotationTypeParams.type === 'TypeParameterInstantiation'
253258
)
254259
) {
255-
return component.node.parent.id.typeAnnotation.typeAnnotation.typeParameters.params.find(
260+
return annotationTypeParams.params.find(
256261
(param) => param.type === 'TSTypeReference' || param.type === 'GenericTypeAnnotation'
257262
);
258263
}

0 commit comments

Comments
 (0)