Angular Modernizer
    Preparing search index...

    Detects magic string selector arguments passed to dynamic component loading methods. Passing a raw string or template literal to methods like getComponentBySelector or loadComponent creates fragile implicit contracts that cannot be verified by the TypeScript compiler and break silently when component selectors are renamed.

    Detection scope:

    • CallExpression nodes whose called method name matches a configured targetMethodPatterns list (default: 'getComponentBySelector', 'loadComponent', /get.*Component/i).
    • Argument classification:
      • StringLiteral -> argumentType: 'string-literal', severity: 'error'
      • NoSubstitutionTemplateLiteral / TemplateExpression -> argumentType: 'template-literal', severity: 'error'
      • PropertyAccessExpression (e.g. this.config.selector) -> argumentType: 'config-property', severity: 'warning'; with selectorPropertyNames only when the accessed property is one of them
      • All other argument kinds -> not flagged (too many false positives).

    Skipped:

    • .d.ts declaration files.
    • Call expressions with no arguments.
    • First arguments that are plain identifiers, function calls, or other non-literal, non-property-access expressions.

    Pattern compilation:

    • String entries in targetMethodPatterns are compiled to exact-match regexes ('^' + p + '$'), preventing partial matches such as 'load' matching 'loadComponentFactory'.
    • RegExp entries are passed through unchanged (they express partial matching explicitly, e.g. /get.*Component/i).
    const rule = new MagicStringSelectorRule();
    const results = await rule.analyze(createContext(sourceFile, project));
    // results[0].metadata.violationType -> 'magic-string-selector'
    // results[0].metadata.methodName -> 'getComponentBySelector'
    // results[0].metadata.argumentType -> 'string-literal'
    // results[0].metadata.severity -> 'error'

    Implements

    Index

    Constructors

    Properties

    Methods

    Constructors

    Properties

    category: "angular-architecture" = 'angular-architecture'

    Rule category for grouping.

    description: "Detects magic string selector arguments passed to dynamic component loading methods" = 'Detects magic string selector arguments passed to dynamic component loading methods'

    Rule description explaining what it checks.

    id: "angular:magic-string-selector" = 'angular:magic-string-selector'

    Unique rule identifier (scoped to plugin). Format: "plugin-name:rule-name" (e.g., "angular-standalone:component-not-standalone")

    name: "Magic String Selector" = 'Magic String Selector'

    Human-readable rule name.

    severity: "error" = ...

    Rule severity level.

    tags: string[] = ...

    Tags for filtering and search.

    Methods