@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
85 lines • 3.82 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NamingConventionDetector = void 0;
const constants_1 = require("../../shared/constants");
const detectorPatterns_1 = require("../constants/detectorPatterns");
const CodeParser_1 = require("../parsers/CodeParser");
const AstClassNameAnalyzer_1 = require("../strategies/naming/AstClassNameAnalyzer");
const AstFunctionNameAnalyzer_1 = require("../strategies/naming/AstFunctionNameAnalyzer");
const AstInterfaceNameAnalyzer_1 = require("../strategies/naming/AstInterfaceNameAnalyzer");
const AstNamingTraverser_1 = require("../strategies/naming/AstNamingTraverser");
const AstVariableNameAnalyzer_1 = require("../strategies/naming/AstVariableNameAnalyzer");
/**
* Detects naming convention violations using AST-based analysis
*
* This detector uses Abstract Syntax Tree (AST) analysis via tree-sitter to identify
* naming convention violations in classes, interfaces, functions, and variables
* according to Clean Architecture layer rules.
*
* The detector uses a modular architecture with specialized components:
* - AstClassNameAnalyzer: Analyzes class names
* - AstInterfaceNameAnalyzer: Analyzes interface names
* - AstFunctionNameAnalyzer: Analyzes function and method names
* - AstVariableNameAnalyzer: Analyzes variable and constant names
* - AstNamingTraverser: Traverses the AST and coordinates analyzers
*
* @example
* ```typescript
* const detector = new NamingConventionDetector()
* const code = `
* class userService { // Wrong: should be UserService
* GetUser() {} // Wrong: should be getUser
* }
* `
* const violations = detector.detectViolations(code, 'UserService.ts', 'domain', 'src/domain/UserService.ts')
* // Returns array of NamingViolation objects
* ```
*/
class NamingConventionDetector {
parser;
traverser;
constructor() {
this.parser = new CodeParser_1.CodeParser();
const classAnalyzer = new AstClassNameAnalyzer_1.AstClassNameAnalyzer();
const interfaceAnalyzer = new AstInterfaceNameAnalyzer_1.AstInterfaceNameAnalyzer();
const functionAnalyzer = new AstFunctionNameAnalyzer_1.AstFunctionNameAnalyzer();
const variableAnalyzer = new AstVariableNameAnalyzer_1.AstVariableNameAnalyzer();
this.traverser = new AstNamingTraverser_1.AstNamingTraverser(classAnalyzer, interfaceAnalyzer, functionAnalyzer, variableAnalyzer);
}
/**
* Detects naming convention violations in the given code
*
* @param content - Source code to analyze
* @param fileName - Name of the file being analyzed
* @param layer - Architectural layer (domain, application, infrastructure, shared)
* @param filePath - File path for context (used in violation reports)
* @returns Array of detected naming violations
*/
detectViolations(content, fileName, layer, filePath) {
if (!layer) {
return [];
}
if (detectorPatterns_1.EXCLUDED_FILES.includes(fileName)) {
return [];
}
if (!content || content.trim().length === 0) {
return [];
}
const tree = this.parseCode(content, filePath);
return this.traverser.traverse(tree, content, layer, filePath);
}
/**
* Parses code based on file extension
*/
parseCode(code, filePath) {
if (filePath.endsWith(constants_1.FILE_EXTENSIONS.TYPESCRIPT_JSX)) {
return this.parser.parseTsx(code);
}
else if (filePath.endsWith(constants_1.FILE_EXTENSIONS.TYPESCRIPT)) {
return this.parser.parseTypeScript(code);
}
return this.parser.parseJavaScript(code);
}
}
exports.NamingConventionDetector = NamingConventionDetector;
//# sourceMappingURL=NamingConventionDetector.js.map