Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix: report end loc in one-var-declaration-per-line (refs #12334) (#1…
  • Loading branch information
yeonjuan committed May 22, 2020
1 parent 1710296 commit de0aab9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/one-var-declaration-per-line.js
Expand Up @@ -71,7 +71,7 @@ module.exports = {
context.report({
node,
messageId: "expectVarOnNewline",
loc: current.loc.start,
loc: current.loc,
fix: fixer => fixer.insertTextBefore(current, "\n")
});
}
Expand Down
2 changes: 2 additions & 0 deletions tests/lib/rules/one-var-declaration-per-line.js
Expand Up @@ -68,6 +68,7 @@ ruleTester.run("one-var-declaration-per-line", rule, {
],

invalid: [
{ code: "var foo, bar;", output: "var foo, \nbar;", options: ["always"], errors: [{ line: 1, column: 10, endLine: 1, endColumn: 13 }] },
{ code: "var a, b;", output: "var a, \nb;", options: ["always"], errors: [errorAt(1, 8)] },
{ code: "let a, b;", output: "let a, \nb;", options: ["always"], parserOptions: { ecmaVersion: 6 }, errors: [errorAt(1, 8)] },
{ code: "var a, b = 0;", output: "var a, \nb = 0;", options: ["always"], errors: [errorAt(1, 8)] },
Expand All @@ -76,6 +77,7 @@ ruleTester.run("one-var-declaration-per-line", rule, {
{ code: "let a, b = 0;", output: "let a, \nb = 0;", options: ["always"], parserOptions: { ecmaVersion: 6 }, errors: [errorAt(1, 8)] },
{ code: "const a = 0, b = 0;", output: "const a = 0, \nb = 0;", options: ["always"], parserOptions: { ecmaVersion: 6 }, errors: [errorAt(1, 14)] },

{ code: "var foo, bar, baz = 0;", output: "var foo, bar, \nbaz = 0;", options: ["initializations"], errors: [{ line: 1, column: 15, endLine: 1, endColumn: 22 }] },
{ code: "var a, b, c = 0;", output: "var a, b, \nc = 0;", options: ["initializations"], errors: [errorAt(1, 11)] },
{ code: "var a, b,\nc = 0, d;", output: "var a, b,\nc = 0, \nd;", options: ["initializations"], errors: [errorAt(2, 8)] },
{ code: "var a, b,\nc = 0, d = 0;", output: "var a, b,\nc = 0, \nd = 0;", options: ["initializations"], errors: [errorAt(2, 8)] },
Expand Down

0 comments on commit de0aab9

Please sign in to comment.