{"record":{"id":"318ab3be98b7774c","repo":"mozilla/pdf.js","slug":"bom-check-failed-run-gulp-lint-bom-fix-to-cle","errorCode":null,"errorMessage":"BOM check failed (run `gulp lint-bom --fix` to clear).","messagePattern":"BOM check failed \\(run `gulp lint-bom --fix` to clear\\)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"gulpfile.mjs","lineNumber":2568,"sourceCode":"  // Don't exhaust file descriptors.\n  const offenders = [];\n  for (let i = 0; i < files.length; i += 256) {\n    const chunk = files.slice(i, i + 256);\n    const flags = await Promise.all(chunk.map(hasBOM));\n    chunk.forEach((file, j) => flags[j] && offenders.push(file));\n  }\n  offenders.sort();\n\n  if (offenders.length === 0) {\n    console.log(\"files checked, no errors found\");\n    return;\n  }\n\n  if (!process.argv.includes(\"--fix\")) {\n    for (const file of offenders) {\n      console.log(`  Unexpected byte order mark: ${file}`);\n    }\n    throw new Error(\"BOM check failed (run `gulp lint-bom --fix` to clear).\");\n  }\n\n  // Strip the BOM on disk and let the user stage the change.\n  await Promise.all(\n    offenders.map(async file => {\n      const content = await fs.promises.readFile(file);\n      await fs.promises.writeFile(file, content.subarray(3));\n      console.log(`  removed byte order mark: ${file}`);\n    })\n  );\n  console.log(`done: ${offenders.length} file(s) updated`);\n});\n\ngulp.task(\"lint\", function (done) {\n  console.log(\"\\n### Linting JS/CSS/JSON/SVG/HTML files\");\n\n  // Ensure that we lint the Firefox specific *.jsm files too.\n  const esLintOptions = [","sourceCodeStart":2550,"sourceCodeEnd":2586,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/gulpfile.mjs#L2550-L2586","documentation":"The `lint-bom` task scans tracked source files for a leading UTF-8 byte order mark (EF BB BF). If any file starts with a BOM, the task prints each offender and throws, directing the user to `gulp lint-bom --fix`. The fix path strips the first 3 bytes from each offending file in place. This is a repo-hygiene check: BOMs can break concatenation, parsers, and the preprocessor, so PDF.js forbids them. It is a non-fatal lint gate, not a runtime defect.","triggerScenarios":"An editor or tool (Notepad, some Windows tools, certain PowerShell redirects) saved a source file with a UTF-8 BOM; a copied/pasted file retained a BOM; a generated file written with `utf-8` instead of `utf-8` without BOM; the BOM was introduced by an external commit that wasn't linted.","commonSituations":"Contributors on Windows; merging generated artifacts; CI gating a PR on `gulp lint` which transitively runs lint-bom.","solutions":["Run `gulp lint-bom --fix` — it strips the BOM from every offending file; then stage the change.","Configure your editor to save UTF-8 without BOM (VS Code: 'UTF-8', not 'UTF-8 with BOM').","Add the lint-bom check (or a pre-commit hook) so BOMs are caught before push.","If only one file is flagged, reopen and re-save it as UTF-8 (no BOM) manually."],"exampleFix":"# before\ngulp lint-bom        # throws, lists offenders\n# after\ngulp lint-bom --fix  # strips BOM, prints 'done: N file(s) updated'\ngit add -u","handlingStrategy":"validation","validationCode":"import { open } from 'fs/promises';\nasync function hasBOM(file) {\n  const h = await open(file, 'r');\n  try {\n    const { bytesRead, buffer } = await h.read(Buffer.alloc(3), 0, 3, 0);\n    return bytesRead === 3 && buffer[0] === 0xef && buffer[1] === 0xbb && buffer[2] === 0xbf;\n  } finally { await h.close(); }\n}\n// fail-fast in a pre-commit hook:\nfor (const f of stagedFiles) if (await hasBOM(f)) throw new Error(`${f} has a BOM; save as UTF-8 without BOM`);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `gulp lint-bom --fix` whenever the check fails; stage the result.","Set your editor to save 'UTF-8' (not 'UTF-8 with BOM').","Add lint-bom (or an equivalent pre-commit hook) so BOMs are blocked before push."],"tags":["lint","bom","encoding","repo-hygiene","utf8"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}