Skip to content

Commit

Permalink
refactor: split get type annotation if statement
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryBrown0 committed Sep 6, 2023
1 parent 7c356ee commit 0f45d97
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions lib/rules/boolean-prop-naming.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,27 +240,25 @@ 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.typeArguments
&& (
component.node.parent.id.typeAnnotation.typeAnnotation.typeArguments.type === 'TSTypeParameterInstantiation'
|| component.node.parent.id.typeAnnotation.typeAnnotation.typeArguments.type === 'TypeParameterInstantiation'
))
|| (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 component.node.parent.id.typeAnnotation.typeAnnotation.typeParameters.params.find(
(param) => param.type === 'TSTypeReference' || param.type === 'GenericTypeAnnotation'
);
return;
}

const annotationArgs = component.node.parent.id.typeAnnotation.typeAnnotation.typeArguments
|| component.node.parent.id.typeAnnotation.typeAnnotation.typeParameters;
if (
annotationArgs
&& (annotationArgs.type === 'TSTypeParameterInstantiation' || annotationArgs.type === 'TypeParameterInstantiation')
) {
return annotationArgs.params.find((param) => (
param.type === 'TSTypeReference' || param.type === 'GenericTypeAnnotation'
));
}
}

Expand Down

0 comments on commit 0f45d97

Please sign in to comment.