mirror of
https://github.com/samiyev/puaros.git
synced 2025-12-28 07:16:53 +05:00
feat: add dependency direction enforcement (v0.4.0)
Implement dependency direction detection to enforce Clean Architecture rules: - Domain layer can only import from Domain and Shared - Application layer can only import from Domain, Application, and Shared - Infrastructure layer can import from all layers - Shared layer can be imported by all layers Added: - IDependencyDirectionDetector interface in domain layer - DependencyViolation value object with detailed suggestions and examples - DependencyDirectionDetector implementation in infrastructure - Integration with AnalyzeProject use case - New DEPENDENCY_DIRECTION rule in constants - 43 comprehensive tests covering all scenarios (100% passing) - Good and bad examples in examples directory Improvements: - Optimized extractLayerFromImport method to reduce complexity - Fixed indentation in DependencyGraph.ts - Updated getExampleFix to avoid false positives in old detector Test Results: - All 261 tests passing - Build successful - Self-check: 0 architecture violations in src code
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { DependencyViolation } from "../value-objects/DependencyViolation"
|
||||
|
||||
/**
|
||||
* Interface for detecting dependency direction violations in the codebase
|
||||
*
|
||||
* Dependency direction violations occur when a layer imports from a layer
|
||||
* that it should not depend on according to Clean Architecture principles:
|
||||
* - Domain should not import from Application or Infrastructure
|
||||
* - Application should not import from Infrastructure
|
||||
* - Infrastructure can import from Application and Domain
|
||||
* - Shared can be imported by all layers
|
||||
*/
|
||||
export interface IDependencyDirectionDetector {
|
||||
/**
|
||||
* Detects dependency direction violations in the given code
|
||||
*
|
||||
* Analyzes import statements to identify violations of dependency rules
|
||||
* between architectural layers.
|
||||
*
|
||||
* @param code - Source code to analyze
|
||||
* @param filePath - Path to the file being analyzed
|
||||
* @param layer - The architectural layer of the file (domain, application, infrastructure, shared)
|
||||
* @returns Array of detected dependency direction violations
|
||||
*/
|
||||
detectViolations(
|
||||
code: string,
|
||||
filePath: string,
|
||||
layer: string | undefined,
|
||||
): DependencyViolation[]
|
||||
|
||||
/**
|
||||
* Checks if an import violates dependency direction rules
|
||||
*
|
||||
* @param fromLayer - The layer that is importing
|
||||
* @param toLayer - The layer being imported
|
||||
* @returns True if the import violates dependency rules
|
||||
*/
|
||||
isViolation(fromLayer: string, toLayer: string): boolean
|
||||
|
||||
/**
|
||||
* Extracts the layer from an import path
|
||||
*
|
||||
* @param importPath - The import path to analyze
|
||||
* @returns The layer name if detected, undefined otherwise
|
||||
*/
|
||||
extractLayerFromImport(importPath: string): string | undefined
|
||||
}
|
||||
Reference in New Issue
Block a user