2 * @fileoverview Require or disallow Unicode BOM
3 * @author Andrew Johnston <https://github.com/ehjay>
7 //------------------------------------------------------------------------------
9 //------------------------------------------------------------------------------
16 description: "require or disallow Unicode byte order mark (BOM)",
17 category: "Stylistic Issues",
19 url: "https://eslint.org/docs/rules/unicode-bom"
22 fixable: "whitespace",
26 enum: ["always", "never"]
30 expected: "Expected Unicode BOM (Byte Order Mark).",
31 unexpected: "Unexpected Unicode BOM (Byte Order Mark)."
37 //--------------------------------------------------------------------------
39 //--------------------------------------------------------------------------
43 Program: function checkUnicodeBOM(node) {
45 const sourceCode = context.getSourceCode(),
46 location = { column: 0, line: 1 },
47 requireBOM = context.options[0] || "never";
49 if (!sourceCode.hasBOM && (requireBOM === "always")) {
53 messageId: "expected",
55 return fixer.insertTextBeforeRange([0, 1], "\uFEFF");
58 } else if (sourceCode.hasBOM && (requireBOM === "never")) {
62 messageId: "unexpected",
64 return fixer.removeRange([-1, 0]);