Skip to content

Commit 0f45d97

Browse files
committed
refactor: split get type annotation if statement
1 parent 7c356ee commit 0f45d97

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

lib/rules/boolean-prop-naming.js

+18-20
Original file line numberDiff line numberDiff line change
@@ -240,27 +240,25 @@ 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-
&& (
250-
(component.node.parent.id.typeAnnotation.typeAnnotation.typeArguments
251-
&& (
252-
component.node.parent.id.typeAnnotation.typeAnnotation.typeArguments.type === 'TSTypeParameterInstantiation'
253-
|| component.node.parent.id.typeAnnotation.typeAnnotation.typeArguments.type === 'TypeParameterInstantiation'
254-
))
255-
|| (component.node.parent.id.typeAnnotation.typeAnnotation.typeParameters
256-
&& (component.node.parent.id.typeAnnotation.typeAnnotation.typeParameters.type === 'TSTypeParameterInstantiation'
257-
|| component.node.parent.id.typeAnnotation.typeAnnotation.typeParameters.type === 'TypeParameterInstantiation'
258-
))
259-
)
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
260249
) {
261-
return component.node.parent.id.typeAnnotation.typeAnnotation.typeParameters.params.find(
262-
(param) => param.type === 'TSTypeReference' || param.type === 'GenericTypeAnnotation'
263-
);
250+
return;
251+
}
252+
253+
const annotationArgs = component.node.parent.id.typeAnnotation.typeAnnotation.typeArguments
254+
|| component.node.parent.id.typeAnnotation.typeAnnotation.typeParameters;
255+
if (
256+
annotationArgs
257+
&& (annotationArgs.type === 'TSTypeParameterInstantiation' || annotationArgs.type === 'TypeParameterInstantiation')
258+
) {
259+
return annotationArgs.params.find((param) => (
260+
param.type === 'TSTypeReference' || param.type === 'GenericTypeAnnotation'
261+
));
264262
}
265263
}
266264

0 commit comments

Comments
 (0)