shouldSkipFile method

bool shouldSkipFile(
  1. String path
)

Check if a file path should be skipped based on context settings.

Implementation

bool shouldSkipFile(String path) {
  // Normalize path separators
  final normalizedPath = path.replaceAll('\\', '/');

  // =========================================================================
  // GLOBAL EXCLUSIONS (always skip, regardless of rule settings)
  // =========================================================================

  // Check global excluded folders
  for (final folder in _globalExcludedFolders) {
    if (normalizedPath.contains(folder)) {
      return true;
    }
  }

  // =========================================================================
  // RULE-CONFIGURABLE EXCLUSIONS
  // =========================================================================

  // Check generated code patterns
  if (skipGeneratedCode) {
    // Check file suffixes
    for (final suffix in _generatedFileSuffixes) {
      if (normalizedPath.endsWith(suffix)) {
        return true;
      }
    }

    // Check generated folder
    if (normalizedPath.contains('/generated/')) {
      return true;
    }

    // Check for generated file markers in content (deferred - expensive)
    // This is handled separately via content-based detection
  }

  // Check test files using TestRelevance
  final isTest = FileTypeDetector.isTestPath(normalizedPath);
  final relevance = _effectiveTestRelevance;
  if (relevance == TestRelevance.testOnly && !isTest) {
    return true; // Skip non-test files for test-only rules
  }
  if (relevance == TestRelevance.never && isTest) {
    return true; // Skip test files (default)
  }
  // TestRelevance.always: no skip based on test status

  // Check example files
  if (skipExampleFiles) {
    if (normalizedPath.contains('/example/') ||
        normalizedPath.contains('/examples/')) {
      return true;
    }
  }

  // Check fixture files - but NOT in example/ directory
  // (example fixtures are specifically for testing the linter rules)
  if (skipFixtureFiles) {
    final isInExample =
        normalizedPath.contains('/example/') ||
        normalizedPath.contains('/examples/');
    if (!isInExample) {
      if (normalizedPath.contains('/fixture/') ||
          normalizedPath.contains('/fixtures/') ||
          normalizedPath.contains('_fixture.dart')) {
        return true;
      }
    }
  }

  return false;
}