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

Commit 9c45089

Browse files
committed
maximumLineLength: some nodes might contain null values
Fixes #2107
1 parent 556c357 commit 9c45089

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

lib/rules/maximum-line-length.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ module.exports.prototype = {
135135
lines = lines.slice();
136136

137137
var removeLoc = function(tokenOrNode) {
138+
139+
// Just in case (See #2107 for example)
140+
if (!tokenOrNode) {
141+
return;
142+
}
143+
138144
for (var i = tokenOrNode.loc.start.line; i <= tokenOrNode.loc.end.line; i++) {
139145
lines[i - 1] = '';
140146
}
@@ -156,6 +162,9 @@ module.exports.prototype = {
156162

157163
if (this._allowFunctionSignature) {
158164
file.iterateNodesByType('FunctionDeclaration', function(node) {
165+
166+
// Need to remove the first line, because we can't be sure there's any id or params
167+
lines[node.loc.start.line - 1] = '';
159168
removeLoc(node.id);
160169
node.params.forEach(removeLoc);
161170
});
@@ -168,9 +177,7 @@ module.exports.prototype = {
168177

169178
// Need to remove the first line, because we can't be sure there's any id or params
170179
lines[node.loc.start.line - 1] = '';
171-
if (node.id) {
172-
removeLoc(node.id);
173-
}
180+
removeLoc(node.id);
174181
node.params.forEach(removeLoc);
175182
});
176183
}

test/specs/rules/maximum-line-length.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,14 @@ describe('rules/maximum-line-length', function() {
242242
var code = '// function myCoolFunction(argument) { }';
243243
expect(checker.checkString(code)).to.have.one.validation.error.from('maximumLineLength');
244244
});
245+
246+
it('should not break on export default function', function() {
247+
expect(checker.checkString('export default function() {}')).to.have.no.errors();
248+
});
249+
250+
it('should not break on export default function with params', function() {
251+
expect(checker.checkString('export default function(s) {}')).to.have.no.errors();
252+
});
245253
});
246254

247255
describe('allExcept["require"] option', function() {

0 commit comments

Comments
 (0)