UNPKG

@regele/devtools

Version:

A collection of developer utilities for code processing and text analysis

49 lines (48 loc) 1.61 kB
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 deeply nested code */ export declare class DeepNestingRule extends Rule { readonly id = "maint-deep-nesting"; readonly name = "Deep Nesting"; readonly description = "Detects deeply nested code blocks that reduce readability"; readonly category = CategoryType.Maintainability; readonly defaultSeverity = SeverityLevel.Warning; readonly requiresAST = true; private readonly WARNING_THRESHOLD; private readonly ERROR_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[]; /** * Check if a node contributes to nesting depth * * @param node - AST node * @returns True if the node increases nesting depth */ private isNestingNode; /** * Generate a suggestion for reducing nesting * * @param code - Original code * @param depth - Nesting depth * @returns Suggested code */ protected generateSuggestion(code: string, _depth: number): string; /** * Get the name of the function containing this code * * @param path - AST path * @returns Function name or undefined */ protected getFunctionName(path: any): string | undefined; }