UNPKG

@regele/devtools

Version:

A collection of developer utilities for code processing and text analysis

42 lines (41 loc) 1.46 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 unbatched DOM updates */ export declare class UnbatchedDOMUpdatesRule extends Rule { readonly id = "perf-unbatched-dom"; readonly name = "Unbatched DOM Updates"; readonly description = "Detects multiple DOM updates that could be batched for better performance"; readonly category = CategoryType.Performance; readonly defaultSeverity = SeverityLevel.Warning; readonly requiresAST = true; private readonly domMethods; private readonly domProperties; /** * 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[]; /** * Generate a suggestion for batching DOM updates * * @param code - Original code * @param domUpdates - List of DOM updates * @returns Suggested code */ protected generateSuggestion(_code: string, domUpdates?: any[]): 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; }