feat(guardian): add guardian package - code quality analyzer

Add @puaros/guardian package v0.1.0 - code quality guardian for vibe coders and enterprise teams.

Features:
- Hardcode detection (magic numbers, magic strings)
- Circular dependency detection
- Naming convention enforcement (Clean Architecture)
- Architecture violation detection
- CLI tool with comprehensive reporting
- 159 tests with 80%+ coverage
- Smart suggestions for fixes
- Built for AI-assisted development

Built with Clean Architecture and DDD principles.
Works with Claude, GPT, Copilot, Cursor, and any AI coding assistant.
This commit is contained in:
imfozilbek
2025-11-24 02:54:39 +05:00
parent 9f97509b06
commit 03705b5264
96 changed files with 9520 additions and 0 deletions

View File

@@ -0,0 +1,91 @@
/**
* Default file scanning options
*/
export const DEFAULT_EXCLUDES = [
"node_modules",
"dist",
"build",
"coverage",
".git",
".puaros",
] as const
export const DEFAULT_EXTENSIONS = [".ts", ".tsx", ".js", ".jsx"] as const
/**
* Allowed numbers that are not considered magic numbers
*/
export const ALLOWED_NUMBERS = new Set([-1, 0, 1, 2, 10, 100, 1000])
/**
* Default context extraction size (characters)
*/
export const CONTEXT_EXTRACT_SIZE = 30
/**
* String length threshold for magic string detection
*/
export const MIN_STRING_LENGTH = 3
/**
* Single character limit for string detection
*/
export const SINGLE_CHAR_LIMIT = 1
/**
* Git defaults
*/
export const GIT_DEFAULTS = {
REMOTE: "origin",
BRANCH: "main",
} as const
/**
* Tree-sitter node types for function detection
*/
export const TREE_SITTER_NODE_TYPES = {
FUNCTION_DECLARATION: "function_declaration",
ARROW_FUNCTION: "arrow_function",
FUNCTION_EXPRESSION: "function_expression",
} as const
/**
* Detection keywords for hardcode analysis
*/
export const DETECTION_KEYWORDS = {
TIMEOUT: "timeout",
DELAY: "delay",
RETRY: "retry",
LIMIT: "limit",
MAX: "max",
MIN: "min",
PORT: "port",
INTERVAL: "interval",
TEST: "test",
DESCRIBE: "describe",
CONSOLE_LOG: "console.log",
CONSOLE_ERROR: "console.error",
HTTP: "http",
API: "api",
} as const
/**
* Code patterns for detecting exported constants
*/
export const CODE_PATTERNS = {
EXPORT_CONST: "export const ",
EXPORT: "export ",
IMPORT: "import ",
AS_CONST: " as const",
AS_CONST_OBJECT: "} as const",
AS_CONST_ARRAY: "] as const",
AS_CONST_END_SEMICOLON_OBJECT: "};",
AS_CONST_END_SEMICOLON_ARRAY: "];",
OBJECT_START: "= {",
ARRAY_START: "= [",
} as const
/**
* File encoding
*/
export const FILE_ENCODING = "utf-8" as const

View File

@@ -0,0 +1,66 @@
/**
* Naming Convention Detector Constants
*
* Following Clean Code principles:
* - No magic strings
* - Single source of truth
* - Easy to maintain
*/
/**
* Files to exclude from naming convention checks
*/
export const EXCLUDED_FILES = [
"index.ts",
"BaseUseCase.ts",
"BaseMapper.ts",
"IBaseRepository.ts",
"BaseEntity.ts",
"ValueObject.ts",
"BaseRepository.ts",
"BaseError.ts",
"DomainEvent.ts",
"Suggestions.ts",
] as const
/**
* File suffixes for pattern matching
*/
export const FILE_SUFFIXES = {
SERVICE: "Service.ts",
DTO: "Dto.ts",
REQUEST: "Request.ts",
RESPONSE: "Response.ts",
MAPPER: "Mapper.ts",
CONTROLLER: "Controller.ts",
REPOSITORY: "Repository.ts",
ADAPTER: "Adapter.ts",
} as const
/**
* Path patterns for detection
*/
export const PATH_PATTERNS = {
USE_CASES: "/use-cases/",
USE_CASES_ALT: "/usecases/",
} as const
/**
* Common words for pattern matching
*/
export const PATTERN_WORDS = {
REPOSITORY: "Repository",
I_PREFIX: "I",
} as const
/**
* Error messages for naming violations
*/
export const NAMING_ERROR_MESSAGES = {
DOMAIN_FORBIDDEN:
"Domain layer should not contain DTOs, Controllers, or Request/Response objects",
USE_PASCAL_CASE: "Use PascalCase noun (e.g., User.ts, Order.ts, Email.ts)",
USE_DTO_SUFFIX: "Use *Dto, *Request, or *Response suffix (e.g., UserResponseDto.ts)",
USE_VERB_NOUN: "Use verb + noun in PascalCase (e.g., CreateUser.ts, UpdateProfile.ts)",
USE_CASE_START_VERB: "Use cases should start with a verb",
} as const