Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Cannot read property 'range' of null error with one-var (#10937) #10938

Merged
merged 1 commit into from Oct 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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