(filePath: string)
| 83 | * @returns true if the file should be excluded from attribution |
| 84 | */ |
| 85 | export function isGeneratedFile(filePath: string): boolean { |
| 86 | // Normalize path separators for consistent pattern matching (patterns use posix-style /) |
| 87 | const normalizedPath = |
| 88 | posix.sep + filePath.split(sep).join(posix.sep).replace(/^\/+/, '') |
| 89 | const fileName = basename(filePath).toLowerCase() |
| 90 | const ext = extname(filePath).toLowerCase() |
| 91 | |
| 92 | // Check exact filename matches |
| 93 | if (EXCLUDED_FILENAMES.has(fileName)) { |
| 94 | return true |
| 95 | } |
| 96 | |
| 97 | // Check extension matches |
| 98 | if (EXCLUDED_EXTENSIONS.has(ext)) { |
| 99 | return true |
| 100 | } |
| 101 | |
| 102 | // Check for compound extensions like .min.js |
| 103 | const parts = fileName.split('.') |
| 104 | if (parts.length > 2) { |
| 105 | const compoundExt = '.' + parts.slice(-2).join('.') |
| 106 | if (EXCLUDED_EXTENSIONS.has(compoundExt)) { |
| 107 | return true |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | // Check directory patterns |
| 112 | for (const dir of EXCLUDED_DIRECTORIES) { |
| 113 | if (normalizedPath.includes(dir)) { |
| 114 | return true |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | // Check filename patterns |
| 119 | for (const pattern of EXCLUDED_FILENAME_PATTERNS) { |
| 120 | if (pattern.test(fileName)) { |
| 121 | return true |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | return false |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Filter a list of files to exclude generated files. |
no test coverage detected