@regele/devtools
Version:
A collection of developer utilities for code processing and text analysis
49 lines (48 loc) • 1.65 kB
TypeScript
import * as parser from '@babel/parser';
import * as t from '@babel/types';
import { Rule } from '../rule';
import { CategoryType, CodeFinding, SeverityLevel } from '../../types';
/**
* Rule to detect overly complex functions
*/
export declare class ComplexFunctionRule extends Rule {
readonly id = "maint-complex-function";
readonly name = "Complex Function";
readonly description = "Detects functions with high cyclomatic complexity";
readonly category = CategoryType.Maintainability;
readonly defaultSeverity = SeverityLevel.Warning;
readonly requiresAST = true;
private readonly WARNING_THRESHOLD;
private readonly ERROR_THRESHOLD;
private readonly CRITICAL_THRESHOLD;
/**
* Apply the rule to the given code
*
* @param code - Source code
* @param ast - Parsed AST
* @param filePath - Path to the file
* @returns Array of findings
*/
apply(code: string, ast: parser.ParseResult<t.File>, filePath: string): CodeFinding[];
/**
* Calculate the cyclomatic complexity of a function
*
* @param path - AST path of the function
* @returns Complexity score
*/
private calculateComplexity;
/**
* Generate a suggestion for reducing function complexity
*
* @param functionName - Name of the function
* @returns Suggested refactoring
*/
protected generateSuggestion(_code: string, functionName?: string): string;
/**
* Get the name of the function
*
* @param path - AST path
* @returns Function name or undefined
*/
protected getFunctionName(path: any): string | undefined;
}