isGeneratedFile function

bool isGeneratedFile(
  1. String filePath
)

Check if a file should be excluded from attribution based on Linguist-style rules.

filePath - Relative file path from repository root. Returns true if the file should be excluded from attribution.

Implementation

bool isGeneratedFile(String filePath) {
  // Normalize path separators for consistent pattern matching
  final normalizedPath =
      '/${filePath.replaceAll(Platform.pathSeparator, '/').replaceAll(RegExp(r'^/+'), '')}';
  final fileName = p.basename(filePath).toLowerCase();
  final ext = p.extension(filePath).toLowerCase();

  // Check exact filename matches
  if (_excludedFilenames.contains(fileName)) {
    return true;
  }

  // Check extension matches
  if (_excludedExtensions.contains(ext)) {
    return true;
  }

  // Check for compound extensions like .min.js
  final parts = fileName.split('.');
  if (parts.length > 2) {
    final compoundExt = '.${parts.sublist(parts.length - 2).join('.')}';
    if (_excludedExtensions.contains(compoundExt)) {
      return true;
    }
  }

  // Check directory patterns
  for (final dir in _excludedDirectories) {
    if (normalizedPath.contains(dir)) {
      return true;
    }
  }

  // Check filename patterns
  for (final pattern in _excludedFilenamePatterns) {
    if (pattern.hasMatch(fileName)) {
      return true;
    }
  }

  return false;
}