Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function checkParameters(params: TSESTree.Parameter[]): void {
for (const param of params) {
let annotationNode: TSESTree.Node | undefined;
switch (param.type) {
case AST_NODE_TYPES.AssignmentPattern:
annotationNode = param.left;
break;
case AST_NODE_TYPES.TSParameterProperty:
annotationNode = param.parameter;
// Check TS parameter property with default value like `constructor(private param: string = 'something') {}`
if (
annotationNode &&
annotationNode.type === AST_NODE_TYPES.AssignmentPattern
) {
annotationNode = annotationNode.left;
}
break;
default:
annotationNode = param;
break;
}
param => param.type === AST_NODE_TYPES.TSParameterProperty,
)
function isTSParameterProperty(
node: TSESTree.Node,
): node is TSESTree.TSParameterProperty {
return (
(node as TSESTree.TSParameterProperty).type ===
AST_NODE_TYPES.TSParameterProperty
);
}
export function isTSParameterProperty(
node: TSESTree.Node
): node is TSESTree.TSParameterProperty {
return node.type === AST_NODE_TYPES.TSParameterProperty;
}
param => param.type === AST_NODE_TYPES.TSParameterProperty,
)
param => param.type === AST_NODE_TYPES.TSParameterProperty,
)
AST_NODE_TYPES.TSIndexedAccessType,
AST_NODE_TYPES.TSIndexSignature,
AST_NODE_TYPES.TSInferType,
AST_NODE_TYPES.TSInterfaceBody,
AST_NODE_TYPES.TSInterfaceDeclaration,
AST_NODE_TYPES.TSInterfaceHeritage,
AST_NODE_TYPES.TSIntersectionType,
AST_NODE_TYPES.TSImportEqualsDeclaration,
AST_NODE_TYPES.TSLiteralType,
AST_NODE_TYPES.TSMappedType,
AST_NODE_TYPES.TSMethodSignature,
'TSMinusToken',
AST_NODE_TYPES.TSModuleBlock,
AST_NODE_TYPES.TSModuleDeclaration,
AST_NODE_TYPES.TSNonNullExpression,
AST_NODE_TYPES.TSParameterProperty,
AST_NODE_TYPES.TSParenthesizedType,
'TSPlusToken',
AST_NODE_TYPES.TSPropertySignature,
AST_NODE_TYPES.TSQualifiedName,
'TSQuestionToken',
AST_NODE_TYPES.TSRestType,
AST_NODE_TYPES.TSThisType,
AST_NODE_TYPES.TSTupleType,
AST_NODE_TYPES.TSTypeAnnotation,
AST_NODE_TYPES.TSTypeLiteral,
AST_NODE_TYPES.TSTypeOperator,
AST_NODE_TYPES.TSTypeParameter,
AST_NODE_TYPES.TSTypeParameterDeclaration,
AST_NODE_TYPES.TSTypeParameterInstantiation,
AST_NODE_TYPES.TSTypeReference,
AST_NODE_TYPES.TSUnionType,
node.params.forEach(param => {
if (param.type === AST_NODE_TYPES.TSParameterProperty) {
return;
}
const identifiers: TSESTree.Identifier[] = [];
getIdentifiersFromPattern(param, identifiers);
identifiers.forEach(i => {
validator(i);
});
});
},