eslint-plugin-sonarjs
Version:
48 lines (47 loc) • 1.86 kB
TypeScript
import type { AST, Rule } from 'eslint';
import type estree from 'estree';
import { type FunctionNodeType } from '../helpers/ast.js';
interface ComplexityTraversal {
enterFunction(node: FunctionNodeType): void;
leaveFunction(): void;
addBranch(node: estree.Node): void;
hasNestedFunction(node: estree.Node): boolean;
}
/** Supply AST data without tying complexity counting to ESLint. */
interface ComplexityAstAccess {
getBranchToken(node: estree.Node): ComplexityToken | null | undefined;
getFunctionParent(node: FunctionNodeType): estree.Node | undefined;
}
/** Store branch tokens for the current function, separate from its nested functions. */
export declare class ComplexityAccumulator implements ComplexityTraversal {
private readonly ast;
private readonly functions;
private readonly functionStack;
private readonly functionsWithNested;
constructor(ast: ComplexityAstAccess);
enterFunction(node: FunctionNodeType): void;
leaveFunction(): void;
addBranch(node: estree.Node): void;
hasNestedFunction(node: estree.Node): boolean;
getFunctions(): readonly FunctionInfo[];
}
/** Connect complexity counting to ESLint token locations and issue reporting. */
export declare class ComplexityTracker implements ComplexityTraversal {
private readonly context;
private readonly accumulator;
constructor(context: Rule.RuleContext);
enterFunction(node: FunctionNodeType): void;
leaveFunction(): void;
addBranch(node: estree.Node): void;
hasNestedFunction(node: estree.Node): boolean;
reportOverThreshold(threshold: number, isExcluded: (node: estree.Node) => boolean): void;
}
interface ComplexityToken {
loc: AST.SourceLocation;
}
interface FunctionInfo {
node: FunctionNodeType;
parent: estree.Node | undefined;
tokens: ComplexityToken[];
}
export {};