Skip to content

Commit

Permalink
[Refactor] boolean-prop-naming: invert if statement
Browse files Browse the repository at this point in the history
Co-authored-by: HenryBrown0 <26250092+HenryBrown0@users.noreply.github.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
  • Loading branch information
HenryBrown0 and ljharb committed Sep 24, 2023
1 parent 9fb0d42 commit 0714704
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 16 additions & 11 deletions lib/rules/boolean-prop-naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
}
Expand Down

0 comments on commit 0714704

Please sign in to comment.