Angular Modernizer
    Preparing search index...

    Transform rule for refactoring inheritance to composition. Wraps InheritanceAnalyzer and InheritanceToCompositionTransformer from @angular-modernizer/core. Runs only when the plugin config sets transformationType: 'inheritance-to-composition'.

    This rule detects classes that extend base classes and refactors them to use composition via dependency injection instead. It extracts base class methods into separate services and updates the derived class to inject those services.

    • Detects classes with extends clauses
    • Analyzes method usage and extractability
    • Calculates confidence scores based on complexity
    1. Analyze inheritance patterns in the source file
    2. Filter patterns by confidence threshold
    3. For each high-confidence pattern:
      • Extract base class methods into a new service
      • Remove the extends clause from the derived class
      • Add constructor parameter for the extracted service
      • Update method calls to use the injected service
      • Add Angular dependency injection decorators
    • minConfidence: Minimum confidence score (0-1) to perform transformation (default: 0.8)
    • requireApproval: Require user approval for medium-confidence transformations (default: false)
    • safeMode: Generate only high-confidence transformations (default: false)
    • preserveOriginalAsComments: Preserve original code as comments (default: false)
    • useInjectFunction: Use modern inject() function instead of constructor injection (default: true)
    // Before transformation
    export class CustomDateAdapter extends NativeDateAdapter {
    parse(value: any): Date | null { ... }
    format(date: Date, displayFormat: any): string { ... }
    }

    // After transformation (with extract strategy)
    @Injectable()
    export class DateFormattingService {
    parse(value: any): Date | null { ... }
    format(date: Date, displayFormat: any): string { ... }
    }

    @Injectable()
    export class CustomDateAdapter {
    constructor(
    private dateFormatting: DateFormattingService,
    private nativeDateAdapter: NativeDateAdapter
    ) {}
    }

    Implements

    Index

    Constructors

    Properties

    Methods

    Constructors

    Properties

    category: "refactoring" = 'refactoring'

    Rule category for grouping.

    description: "Refactor inheritance patterns to composition using dependency injection" = 'Refactor inheritance patterns to composition using dependency injection'

    Rule description.

    id: "angular:transform:inheritance-to-composition" = 'angular:transform:inheritance-to-composition'

    Unique rule identifier.

    name: "Inheritance to Composition" = 'Inheritance to Composition'

    Human-readable rule name.

    tags: string[] = ...

    Tags for filtering and search.

    Methods