UNPKG

@samiyev/guardian

Version:

Research-backed code quality guardian for AI-assisted development. Detects hardcodes, secrets, circular deps, framework leaks, entity exposure, and 9 architecture violations. Enforces Clean Architecture/DDD principles. Works with GitHub Copilot, Cursor, W

62 lines 2.51 kB
import { IHardcodeDetector } from "../../domain/services/IHardcodeDetector"; import { HardcodedValue } from "../../domain/value-objects/HardcodedValue"; /** * Detects hardcoded values (magic numbers and strings) in TypeScript/JavaScript code * * This detector uses Abstract Syntax Tree (AST) analysis via tree-sitter to identify * configuration values, URLs, timeouts, ports, and other constants that should be * extracted to configuration files. AST-based detection provides more accurate context * understanding and reduces false positives compared to regex-based approaches. * * The detector uses a modular architecture with specialized components: * - AstContextChecker: Checks if nodes are in specific contexts (exports, types, etc.) * - AstNumberAnalyzer: Analyzes number literals to detect magic numbers * - AstStringAnalyzer: Analyzes string literals to detect magic strings * - AstTreeTraverser: Traverses the AST and coordinates analyzers * * @example * ```typescript * const detector = new HardcodeDetector() * const code = ` * const timeout = 5000 * const url = "http://localhost:8080" * ` * const violations = detector.detectAll(code, 'config.ts') * // Returns array of HardcodedValue objects * ``` */ export declare class HardcodeDetector implements IHardcodeDetector { private readonly constantsChecker; private readonly parser; private readonly traverser; constructor(); /** * Detects all hardcoded values (both numbers and strings) in the given code * * @param code - Source code to analyze * @param filePath - File path for context (used in violation reports) * @returns Array of detected hardcoded values with suggestions */ detectAll(code: string, filePath: string): HardcodedValue[]; /** * Detects magic numbers in code * * @param code - Source code to analyze * @param filePath - File path (used for constants file check) * @returns Array of detected magic numbers */ detectMagicNumbers(code: string, filePath: string): HardcodedValue[]; /** * Detects magic strings in code * * @param code - Source code to analyze * @param filePath - File path (used for constants file check) * @returns Array of detected magic strings */ detectMagicStrings(code: string, filePath: string): HardcodedValue[]; /** * Parses code based on file extension */ private parseCode; } //# sourceMappingURL=HardcodeDetector.d.ts.map