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

48 lines 2.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AstFunctionNameAnalyzer = void 0; const NamingViolation_1 = require("../../../domain/value-objects/NamingViolation"); const constants_1 = require("../../../shared/constants"); const rules_1 = require("../../../shared/constants/rules"); const detectorPatterns_1 = require("../../constants/detectorPatterns"); /** * AST-based analyzer for detecting function and method naming violations * * Analyzes function declaration, method definition, and arrow function nodes * to ensure proper naming conventions: * - Functions and methods should be camelCase * - Private methods with underscore prefix are allowed */ class AstFunctionNameAnalyzer { /** * Analyzes a function or method declaration node */ analyze(node, layer, filePath, _lines) { const functionNodeTypes = [ constants_1.AST_FUNCTION_TYPES.FUNCTION_DECLARATION, constants_1.AST_FUNCTION_TYPES.METHOD_DEFINITION, constants_1.AST_FUNCTION_TYPES.FUNCTION_SIGNATURE, ]; if (!functionNodeTypes.includes(node.type)) { return null; } const nameNode = node.childForFieldName(constants_1.AST_FIELD_NAMES.NAME); if (!nameNode) { return null; } const functionName = nameNode.text; const lineNumber = nameNode.startPosition.row + 1; if (functionName.startsWith("_")) { return null; } if (functionName === constants_1.CLASS_KEYWORDS.CONSTRUCTOR) { return null; } if (!/^[a-z][a-zA-Z0-9]*$/.test(functionName)) { return NamingViolation_1.NamingViolation.create(functionName, rules_1.NAMING_VIOLATION_TYPES.WRONG_CASE, layer, `${filePath}:${String(lineNumber)}`, detectorPatterns_1.NAMING_ERROR_MESSAGES.FUNCTION_CAMEL_CASE, functionName, detectorPatterns_1.NAMING_ERROR_MESSAGES.USE_CAMEL_CASE_FUNCTION); } return null; } } exports.AstFunctionNameAnalyzer = AstFunctionNameAnalyzer; //# sourceMappingURL=AstFunctionNameAnalyzer.js.map