Skip to content

Commit

Permalink
Fix: Fix error with one-var (fixes #10937) (#10938)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrup authored and btmills committed Oct 12, 2018
1 parent 95c4cb1 commit 543edfa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/rules/one-var.js
Expand Up @@ -314,6 +314,11 @@ module.exports = {
function splitDeclarations(declaration) {
return fixer => declaration.declarations.map(declarator => {
const tokenAfterDeclarator = sourceCode.getTokenAfter(declarator);

if (tokenAfterDeclarator === null) {
return null;
}

const afterComma = sourceCode.getTokenAfter(tokenAfterDeclarator, { includeComments: true });

if (tokenAfterDeclarator.value !== ",") {
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/rules/one-var.js
Expand Up @@ -949,6 +949,17 @@ ruleTester.run("one-var", rule, {
column: 1
}]
},
{
code: "var a = 1, b = 2",
output: "var a = 1; var b = 2",
options: ["never"],
errors: [{
message: "Split 'var' declarations into multiple statements.",
type: "VariableDeclaration",
line: 1,
column: 1
}]
},
{
code: "var foo = require('foo'), bar;",
output: null,
Expand Down

0 comments on commit 543edfa

Please sign in to comment.