(filePath: string, source?: string, overrides?: Record<string, Language>)
| 278 | * `EXTENSION_MAP`. Omitting it is byte-identical to the zero-config behavior. |
| 279 | */ |
| 280 | export function detectLanguage(filePath: string, source?: string, overrides?: Record<string, Language>): Language { |
| 281 | // Play `conf/routes` has no grammar — route through the no-symbol path; the |
| 282 | // Play framework resolver extracts route nodes from it. |
| 283 | if (isPlayRoutesFile(filePath)) return 'yaml'; |
| 284 | const ext = filePath.substring(filePath.lastIndexOf('.')).toLowerCase(); |
| 285 | // Shopify OS 2.0 JSON templates / section groups → the Liquid extractor (it |
| 286 | // links each section `"type"` to its `sections/<type>.liquid`). |
| 287 | if (isShopifyLiquidJson(filePath)) return 'liquid'; |
| 288 | const lang = (overrides && overrides[ext]) || EXTENSION_MAP[ext] || 'unknown'; |
| 289 | |
| 290 | // .h files could be C, C++, or Objective-C — check source content |
| 291 | if (lang === 'c' && ext === '.h' && source) { |
| 292 | if (looksLikeCpp(source)) return 'cpp'; |
| 293 | if (looksLikeObjc(source)) return 'objc'; |
| 294 | } |
| 295 | |
| 296 | return lang; |
| 297 | } |
| 298 | |
| 299 | /** |
| 300 | * Heuristic: does a .h file contain C++ constructs? |
no test coverage detected