UNPKG

eslint-plugin-ft-flow

Version:
61 lines (53 loc) 1.55 kB
const schema = []; const create = (context) => { const markTypeAsUsed = (node) => { context.markVariableAsUsed(node.id.name); }; const markTypeAsUsedWithGenericType = (node) => { let typeId; let scope; let variable; if (node.id.type === 'Identifier') { typeId = node.id; } else if (node.id.type === 'QualifiedTypeIdentifier') { typeId = node.id; do { typeId = typeId.qualification; } while (typeId.qualification); } for (scope = context.getScope(); scope; scope = scope.upper) { variable = scope.set.get(typeId.name); if (variable && variable.defs.length) { context.markVariableAsUsed(typeId.name); break; } } }; return { DeclareClass: markTypeAsUsed, DeclareFunction: markTypeAsUsed, DeclareModule: markTypeAsUsed, DeclareVariable: markTypeAsUsed, GenericTypeAnnotation: markTypeAsUsedWithGenericType, TypeParameterDeclaration(node) { for (const param of node.params) { if (param.default && param.default.typeParameters) { if (param.default.type === 'GenericTypeAnnotation') { markTypeAsUsedWithGenericType(param.default); } for (const typeParameterNode of param.default.typeParameters.params) { if (typeParameterNode.type === 'GenericTypeAnnotation') { markTypeAsUsedWithGenericType(typeParameterNode); } } } } }, }; }; export default { create, meta: { schema, }, };