Skip to content

Commit

Permalink
[Fix] boolean-prop-naming: fix CI issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mobily committed Mar 12, 2022
1 parent 521f13b commit 81ec186
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions lib/rules/boolean-prop-naming.js
Expand Up @@ -228,7 +228,7 @@ module.exports = {
args.filter((arg) => arg.type === 'ObjectExpression').forEach((object) => validatePropNaming(node, object.properties));
}

function getTypeAnnotation(component) {
function getComponentTypeAnnotation(component) {
// If this is a functional component that uses a global type, check it
if (
(component.node.type === 'FunctionDeclaration' || component.node.type === 'ArrowFunctionExpression')
Expand All @@ -247,24 +247,32 @@ module.exports = {
&& 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 === 'TSTypeParameterInstantiation'
|| component.node.parent.id.typeAnnotation.typeAnnotation.typeParameters.type === 'TypeParameterInstantiation'
)
) {
return component.node.parent.id.typeAnnotation.typeAnnotation.typeParameters.params.find(
(param) => param.type === 'TSTypeReference'
(param) => param.type === 'TSTypeReference' || param.type === 'GenericTypeAnnotation'
);
}
}

function findTypeAnnotations(identifier, node) {
if (node.type === 'TSTypeLiteral') {
function findAllTypeAnnotations(identifier, node) {
if (node.type === 'TSTypeLiteral' || node.type === 'ObjectTypeAnnotation') {
const currentNode = [].concat(
objectTypeAnnotations.get(identifier.name) || [],
node
);
objectTypeAnnotations.set(identifier.name, currentNode);
} else if (node.type === 'TSIntersectionType' || node.type === 'TSUnionType') {
} else if (
node.type === 'TSIntersectionType'
|| node.type === 'TSUnionType'
|| node.type === 'IntersectionTypeAnnotation'
|| node.type === 'UnionTypeAnnotation'
) {
node.types.forEach((type) => {
findTypeAnnotations(identifier, type);
findAllTypeAnnotations(identifier, type);
});
}
}
Expand Down Expand Up @@ -333,14 +341,11 @@ module.exports = {
},

TypeAlias(node) {
// Cache all ObjectType annotations, we will check them at the end
if (node.right.type === 'ObjectTypeAnnotation') {
objectTypeAnnotations.set(node.id.name, node.right);
}
findAllTypeAnnotations(node.id, node.right);
},

TSTypeAliasDeclaration(node) {
findTypeAnnotations(node.id, node.typeAnnotation);
findAllTypeAnnotations(node.id, node.typeAnnotation);
},

// eslint-disable-next-line object-shorthand
Expand All @@ -352,7 +357,7 @@ module.exports = {
const list = components.list();

Object.keys(list).forEach((component) => {
const annotation = getTypeAnnotation(list[component]);
const annotation = getComponentTypeAnnotation(list[component]);

if (annotation) {
let propType;
Expand Down

0 comments on commit 81ec186

Please sign in to comment.