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:
@@ -1,6 +1,7 @@
|
||||
import { IEntityExposureDetector } from "../../domain/services/IEntityExposureDetector"
|
||||
import { EntityExposure } from "../../domain/value-objects/EntityExposure"
|
||||
import { LAYERS } from "../../shared/constants/rules"
|
||||
import { DTO_SUFFIXES, NULLABLE_TYPES, PRIMITIVE_TYPES } from "../constants/type-patterns"
|
||||
|
||||
/**
|
||||
* Detects domain entity exposure in controller/route return types
|
||||
@@ -29,15 +30,7 @@ import { LAYERS } from "../../shared/constants/rules"
|
||||
* ```
|
||||
*/
|
||||
export class EntityExposureDetector implements IEntityExposureDetector {
|
||||
private readonly dtoSuffixes = [
|
||||
"Dto",
|
||||
"DTO",
|
||||
"Request",
|
||||
"Response",
|
||||
"Command",
|
||||
"Query",
|
||||
"Result",
|
||||
]
|
||||
private readonly dtoSuffixes = DTO_SUFFIXES
|
||||
private readonly controllerPatterns = [
|
||||
/Controller/i,
|
||||
/Route/i,
|
||||
@@ -167,7 +160,9 @@ export class EntityExposureDetector implements IEntityExposureDetector {
|
||||
|
||||
if (cleanType.includes("|")) {
|
||||
const types = cleanType.split("|").map((t) => t.trim())
|
||||
const nonNullTypes = types.filter((t) => t !== "null" && t !== "undefined")
|
||||
const nonNullTypes = types.filter(
|
||||
(t) => !(NULLABLE_TYPES as readonly string[]).includes(t),
|
||||
)
|
||||
if (nonNullTypes.length > 0) {
|
||||
cleanType = nonNullTypes[0]
|
||||
}
|
||||
@@ -180,19 +175,7 @@ export class EntityExposureDetector implements IEntityExposureDetector {
|
||||
* Checks if a type is a primitive type
|
||||
*/
|
||||
private isPrimitiveType(type: string): boolean {
|
||||
const primitives = [
|
||||
"string",
|
||||
"number",
|
||||
"boolean",
|
||||
"void",
|
||||
"any",
|
||||
"unknown",
|
||||
"null",
|
||||
"undefined",
|
||||
"object",
|
||||
"never",
|
||||
]
|
||||
return primitives.includes(type.toLowerCase())
|
||||
return (PRIMITIVE_TYPES as readonly string[]).includes(type.toLowerCase())
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user