mirror of
https://github.com/samiyev/puaros.git
synced 2025-12-28 07:16:53 +05:00
chore: refactor hardcoded values to constants (v0.5.1)
Major internal refactoring to eliminate hardcoded values and improve maintainability. Guardian now fully passes its own quality checks! Changes: - Extract all RepositoryViolation messages to domain constants - Extract all framework leak template strings to centralized constants - Extract all layer paths to infrastructure constants - Extract all regex patterns to IMPORT_PATTERNS constant - Add 30+ new constants for better maintainability New files: - src/infrastructure/constants/paths.ts (layer paths, patterns) - src/domain/constants/Messages.ts (25+ repository messages) - src/domain/constants/FrameworkCategories.ts (framework categories) - src/shared/constants/layers.ts (layer names) Impact: - Reduced hardcoded values from 37 to 1 (97% improvement) - Guardian passes its own src/ directory checks with 0 violations - All 292 tests still passing (100% pass rate) - No breaking changes - fully backwards compatible Test results: - 292 tests passing (100% pass rate) - 96.77% statement coverage - 83.82% branch coverage
This commit is contained in:
50
packages/guardian/src/domain/constants/Messages.ts
Normal file
50
packages/guardian/src/domain/constants/Messages.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
export const DEPENDENCY_VIOLATION_MESSAGES = {
|
||||
DOMAIN_INDEPENDENCE: "Domain layer should be independent and not depend on other layers",
|
||||
DOMAIN_MOVE_TO_DOMAIN:
|
||||
"Move the imported code to the domain layer if it contains business logic",
|
||||
DOMAIN_USE_DI:
|
||||
"Use dependency inversion: define an interface in domain and implement it in infrastructure",
|
||||
APPLICATION_NO_INFRA: "Application layer should not depend on infrastructure",
|
||||
APPLICATION_DEFINE_PORT: "Define an interface (Port) in application layer",
|
||||
APPLICATION_IMPLEMENT_ADAPTER: "Implement the interface (Adapter) in infrastructure layer",
|
||||
APPLICATION_USE_DI: "Use dependency injection to provide the implementation",
|
||||
}
|
||||
|
||||
export const ENTITY_EXPOSURE_MESSAGES = {
|
||||
METHOD_DEFAULT: "Method",
|
||||
METHOD_DEFAULT_NAME: "getEntity",
|
||||
}
|
||||
|
||||
export const FRAMEWORK_LEAK_MESSAGES = {
|
||||
DEFAULT_MESSAGE: "Domain layer should not depend on external frameworks",
|
||||
}
|
||||
|
||||
export const REPOSITORY_PATTERN_MESSAGES = {
|
||||
UNKNOWN_TYPE: "Unknown",
|
||||
CONSTRUCTOR: "constructor",
|
||||
DEFAULT_SUGGESTION: "Follow Repository Pattern best practices",
|
||||
NO_EXAMPLE: "// No example available",
|
||||
STEP_REMOVE_ORM_TYPES: "1. Remove ORM-specific types from repository interface",
|
||||
STEP_USE_DOMAIN_TYPES: "2. Use domain types (entities, value objects) instead",
|
||||
STEP_KEEP_CLEAN: "3. Keep repository interface clean and persistence-agnostic",
|
||||
STEP_DEPEND_ON_INTERFACE: "1. Depend on repository interface (IUserRepository) in constructor",
|
||||
STEP_MOVE_TO_INFRASTRUCTURE: "2. Move concrete implementation to infrastructure layer",
|
||||
STEP_USE_DI: "3. Use dependency injection to provide implementation",
|
||||
STEP_REMOVE_NEW: "1. Remove 'new Repository()' from use case",
|
||||
STEP_INJECT_CONSTRUCTOR: "2. Inject repository through constructor",
|
||||
STEP_CONFIGURE_DI: "3. Configure dependency injection container",
|
||||
STEP_RENAME_METHOD: "1. Rename method to use domain language",
|
||||
STEP_REFLECT_BUSINESS: "2. Method names should reflect business operations",
|
||||
STEP_AVOID_TECHNICAL: "3. Avoid technical database terms (query, insert, select)",
|
||||
EXAMPLE_PREFIX: "Example:",
|
||||
BAD_ORM_EXAMPLE: "❌ Bad: findOne(query: Prisma.UserWhereInput)",
|
||||
GOOD_DOMAIN_EXAMPLE: "✅ Good: findById(id: UserId): Promise<User | null>",
|
||||
BAD_NEW_REPO: "❌ Bad: const repo = new UserRepository()",
|
||||
GOOD_INJECT_REPO: "✅ Good: constructor(private readonly userRepo: IUserRepository) {}",
|
||||
SUGGESTION_FINDONE: "findById",
|
||||
SUGGESTION_FINDMANY: "findAll or findByFilter",
|
||||
SUGGESTION_INSERT: "save or create",
|
||||
SUGGESTION_UPDATE: "save",
|
||||
SUGGESTION_DELETE: "remove or delete",
|
||||
SUGGESTION_QUERY: "find or search",
|
||||
}
|
||||
Reference in New Issue
Block a user