@regele/devtools
Version:
A collection of developer utilities for code processing and text analysis
62 lines (61 loc) • 1.89 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 enforce naming conventions
*/
export declare class NamingConventionRule extends Rule {
readonly id = "style-naming-convention";
readonly name = "Naming Convention";
readonly description = "Enforces consistent naming conventions for variables, functions, and classes";
readonly category = CategoryType.Style;
readonly defaultSeverity = SeverityLevel.Info;
readonly requiresAST = true;
private readonly CONSTANT_PATTERN;
private readonly CAMEL_CASE_PATTERN;
private readonly PASCAL_CASE_PATTERN;
private readonly PRIVATE_MEMBER_PATTERN;
/**
* 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[];
/**
* Add a naming convention finding
*
* @param findings - Findings array
* @param node - AST node
* @param code - Source code
* @param filePath - File path
* @param name - Current name
* @param message - Finding message
* @param suggestion - Suggested name
*/
private addNamingFinding;
/**
* Convert a string to camelCase
*
* @param str - Input string
* @returns camelCase string
*/
private toCamelCase;
/**
* Convert a string to PascalCase
*
* @param str - Input string
* @returns PascalCase string
*/
private toPascalCase;
/**
* Convert a string to UPPER_SNAKE_CASE
*
* @param str - Input string
* @returns UPPER_SNAKE_CASE string
*/
private toUpperSnakeCase;
}