UNPKG

@regele/devtools

Version:

A collection of developer utilities for code processing and text analysis

69 lines (68 loc) 2.28 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 enforce consistent indentation */ export declare class IndentationRule extends Rule { readonly id = "style-indentation"; readonly name = "Indentation"; readonly description = "Enforces consistent indentation (spaces or tabs)"; readonly category = CategoryType.Style; readonly defaultSeverity = SeverityLevel.Info; readonly requiresAST = false; private readonly DEFAULT_INDENT_SIZE; private readonly DEFAULT_INDENT_TYPE; /** * 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[]; /** * Apply the rule without AST parsing * * @param code - Source code * @param filePath - Path to the file * @returns Array of findings */ applyWithoutAST(code: string, filePath: string): CodeFinding[]; /** * Detect the indentation style used in the file * * @param code - Source code * @returns Indentation information */ private detectIndentation; /** * Generate a suggestion for fixing inconsistent indentation type * * @param line - Original line * @param targetType - Target indentation type * @param targetSize - Target indentation size * @returns Suggested line */ private generateIndentationTypeSuggestion; /** * Generate a suggestion for fixing inconsistent indentation size * * @param line - Original line * @param targetType - Target indentation type * @param targetSize - Target indentation size * @returns Suggested line */ private generateIndentationSizeSuggestion; /** * Generate a suggestion for fixing mixed indentation * * @param line - Original line * @param targetType - Target indentation type * @param targetSize - Target indentation size * @returns Suggested line */ private generateMixedIndentationSuggestion; }