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

Commit 2199ca4

Browse files
committed
Fix: requireVarDeclFirst - ignore let/const
Fixes #1783
1 parent ae65ec3 commit 2199ca4

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/rules/require-var-decl-first.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,11 @@ module.exports.prototype = {
234234
});
235235

236236
file.iterateNodesByType(['VariableDeclaration'], function(varDecl) {
237+
// Ignore let and const for now #1783
238+
if (varDecl.kind !== 'var') {
239+
return;
240+
}
241+
237242
var enclosingScope;
238243
var scopeContents;
239244
var previousNode;

test/specs/rules/require-var-decl-first.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ describe('rules/require-var-decl-first', function() {
3636
}
3737
};
3838

39+
describe('VariableDeclaration kinds #1783', function() {
40+
it('should not return errors for let', function() {
41+
checker.checkString('let a;').isEmpty();
42+
});
43+
44+
it('should not return errors for const', function() {
45+
checker.checkString('const a;').isEmpty();
46+
});
47+
});
48+
3949
describe('statements without spaces or linebreaks', function() {
4050
it('should not return errors for single var declaration at top of program scope', function() {
4151
testDeclStatements(checker, 'var a;', 0);
@@ -135,7 +145,7 @@ describe('rules/require-var-decl-first', function() {
135145
});
136146

137147
it('should return 2 errors for 2 var declarations not at the top of program scope', function() {
138-
testDeclStatements(checker, 'var a;a=1;var b;const c=1;', 2);
148+
testDeclStatements(checker, 'var a;a=1;var b;var c=1;', 2);
139149
});
140150
});
141151

0 commit comments

Comments
 (0)