Angular Modernizer
    Preparing search index...

    False Positive Detector

    Detects and filters false positive syntax errors that occur due to parser limitations with external decorator architectures and complex code patterns.

    Security: Regex patterns are designed to prevent ReDoS attacks. Lines longer than maxLineLength (default: 1000) are skipped to prevent performance degradation.

    1. Constructor Parameters with "import" keyword

      constructor(private importService: ImportService) {}
      // Parser error: "Import statement missing 'from' clause"
      // Reality: Valid parameter name
    2. Super Calls with "import" variables

      super(importConfig, importHelper);
      // Parser error: "Import statement missing 'from' clause"
      // Reality: Valid variable references
    3. Multiple Decorators

      @ExternalDecorator({ id: 'custom' })
      @Component({ selector: 'app-user' })
      export class UserComponent {}
      // Parser may report decorator syntax errors
    4. Path Aliases in Imports

      import { SharedModule } from '@shared/modules';
      // Parser error: Cannot find module '@shared/modules'
      // Reality: Valid tsconfig.json path alias
    SyntaxErrors[] → FalsePositiveDetector → {genuine, falsePositives}
    ↓
    Pattern Registry
    (5+ built-in patterns)
    const detector = new FalsePositiveDetector();
    const errors = [/* syntax errors from parser */];
    const fileContent = fs.readFileSync('component.ts', 'utf-8');

    const { genuine, falsePositives } = detector.filterFalsePositives(
    errors,
    fileContent
    );

    console.info(`Filtered ${falsePositives.length} false positives`);
    console.info(`Reporting ${genuine.length} genuine errors`);
    Index

    Constructors

    Methods

    • Add a custom pattern to the detector

      Allows extending the detector with project-specific patterns without modifying the built-in pattern set.

      Parameters

      Returns void

      If the pattern's regex is invalid

      detector.addPattern({
      pattern: /@CustomDecorator\(\{[^}]*\}\)\s*@Component/,
      context: 'decorator',
      errorMessage: 'Decorator',
      description: 'CustomDecorator with Component decorator'
      });
    • Filter false positives from an array of syntax errors

      This method processes all errors and separates genuine errors from false positives based on the registered patterns.

      Parameters

      • errors: FalsePositiveSyntaxError[]

        Array of syntax errors to filter

      • fileContent: string

        Complete file content for context

      Returns FalsePositiveFilterResult

      Object containing genuine errors and filtered false positives

      const result = detector.filterFalsePositives(
      [
      { message: 'Import statement missing', line: 15, column: 5 },
      { message: 'Unexpected token', line: 20, column: 10 }
      ],
      fileContent
      );

      console.info(`Genuine: ${result.genuine.length}`);
      console.info(`False positives: ${result.falsePositives.length}`);
      console.info('Filtered by context:', result.filteredByContext);
    • Get count of registered patterns

      Returns number

      Total number of patterns

    • Check if a single error is a false positive

      Parameters

      • errorMessage: string

        The error message from the parser

      • line: string

        The source code line where error occurred

      • _lineNumber: number

        The 1-based line number (reserved for future use)

      Returns FalsePositivePattern | null

      The matched pattern if false positive, null if genuine error

      Security: Lines longer than maxLineLength are skipped to prevent ReDoS attacks.

      const pattern = detector.isFalsePositive(
      'Import statement missing "from" clause',
      'constructor(private importService: ImportService) {}',
      42
      );
      if (pattern) {
      console.info(`False positive detected: ${pattern.context}`);
      }
    • Remove a pattern by index

      Parameters

      • index: number

        Index of the pattern to remove

      Returns void

      If attempting to remove a built-in pattern (index < 8)

      If index is out of bounds

      // Add a custom pattern
      detector.addPattern(myPattern);
      // Remove it (assuming it's at index 8)
      detector.removePattern(8);
    • Remove all patterns matching a specific context

      Only removes custom patterns; built-in patterns are preserved.

      Parameters

      Returns number

      Number of patterns removed

      // Remove all custom decorator patterns
      const removed = detector.removePatternsByContext('decorator');
      console.info(`Removed ${removed} decorator patterns`);
    • Reset to built-in patterns only

      Removes all custom patterns added via addPattern()

      Returns void