Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
Fix: requireVarDeclFirst - ignore let/const
Browse files Browse the repository at this point in the history
Fixes #1783
  • Loading branch information
hzoo committed Oct 17, 2015
1 parent ae65ec3 commit 2199ca4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/rules/require-var-decl-first.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ module.exports.prototype = {
});

file.iterateNodesByType(['VariableDeclaration'], function(varDecl) {
// Ignore let and const for now #1783
if (varDecl.kind !== 'var') {
return;
}

var enclosingScope;
var scopeContents;
var previousNode;
Expand Down
12 changes: 11 additions & 1 deletion test/specs/rules/require-var-decl-first.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ describe('rules/require-var-decl-first', function() {
}
};

describe('VariableDeclaration kinds #1783', function() {
it('should not return errors for let', function() {
checker.checkString('let a;').isEmpty();
});

it('should not return errors for const', function() {
checker.checkString('const a;').isEmpty();
});
});

describe('statements without spaces or linebreaks', function() {
it('should not return errors for single var declaration at top of program scope', function() {
testDeclStatements(checker, 'var a;', 0);
Expand Down Expand Up @@ -135,7 +145,7 @@ describe('rules/require-var-decl-first', function() {
});

it('should return 2 errors for 2 var declarations not at the top of program scope', function() {
testDeclStatements(checker, 'var a;a=1;var b;const c=1;', 2);
testDeclStatements(checker, 'var a;a=1;var b;var c=1;', 2);
});
});

Expand Down

0 comments on commit 2199ca4

Please sign in to comment.