Skip to content

Commit

Permalink
Fix: unicode-bom fixer insert BOM in appropriate location (fixes #8083)…
Browse files Browse the repository at this point in the history
… (#8084)

* Fix: unicode-bom fixer insert BOM in appropriate location (fixes #8083)

* Fix: unicode-bom fixer insert BOM in appropriate location. Add test (refs #8083)
  • Loading branch information
pantosha authored and ilyavolodin committed Feb 16, 2017
1 parent 55ac302 commit c53e034
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/unicode-bom.js
Expand Up @@ -45,7 +45,7 @@ module.exports = {
loc: location,
message: "Expected Unicode BOM (Byte Order Mark).",
fix(fixer) {
return fixer.insertTextBefore(node, "\uFEFF");
return fixer.insertTextBeforeRange([0, 1], "\uFEFF");
}
});
} else if (sourceCode.hasBOM && (requireBOM === "never")) {
Expand Down
6 changes: 6 additions & 0 deletions tests/lib/rules/unicode-bom.js
Expand Up @@ -41,6 +41,12 @@ ruleTester.run("unicode-bom", rule, {
options: ["always"],
output: "\uFEFFvar a = 123;"
},
{
code: " // here's a comment \nvar a = 123;",
errors: [{ message: "Expected Unicode BOM (Byte Order Mark).", type: "Program" }],
options: ["always"],
output: "\uFEFF // here's a comment \nvar a = 123;"
},
{
code: "\uFEFF var a = 123;",
errors: [{ message: "Unexpected Unicode BOM (Byte Order Mark).", type: "Program" }],
Expand Down

0 comments on commit c53e034

Please sign in to comment.