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

Commit f4bc106

Browse files
committed
requireAlignedMultilineParams: do not throw on function without body
Fixes #1988
1 parent 9c9d16a commit f4bc106

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

lib/rules/require-aligned-multiline-params.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,20 @@ module.exports.prototype = {
9999

100100
var currentLine = params[0].loc.start.line;
101101
var referenceColumn;
102+
var body;
103+
102104
if (_this._alignWithFirstParam) {
103105
referenceColumn = params[0].loc.start.column;
104106
} else {
105-
referenceColumn = node.body.body[0].loc.start.column + _this._indentationLevel;
107+
108+
body = node.body.body[0];
109+
110+
// If function doesn't have a body just bail out (#1988)
111+
if (!body) {
112+
return;
113+
}
114+
115+
referenceColumn = body.loc.start.column + _this._indentationLevel;
106116
}
107117

108118
params.forEach(function(param) {

test/specs/rules/require-aligned-multiline-params.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ describe('rules/require-aligned-multiline-params', function() {
4343
expect(checker.checkString(noParamFunction)).to.have.no.errors();
4444
});
4545

46+
it('should validate a function without body properly', function() {
47+
var noParamFunction = 'var noBody = function(a) {};';
48+
49+
expect(checker.checkString(noParamFunction)).to.have.no.errors();
50+
});
51+
4652
it('should validate a function with a single line of params properly', function() {
4753
var singleLineFunction = 'var singleLineFunction = function(a, b, c) { \n' +
4854
' console.log(a + b + c);\n' +
@@ -72,6 +78,15 @@ describe('rules/require-aligned-multiline-params', function() {
7278
'requireAlignedMultilineParams');
7379
});
7480

81+
it('should bail out with function without a body', function() {
82+
var unalignedFunction = 'var unalignedFunction = function(a,\n' +
83+
' b, c,\n' +
84+
' d, e) {\n' +
85+
'};';
86+
87+
expect(checker.checkString(unalignedFunction)).to.have.no.errors();
88+
});
89+
7590
it('should validate a function with two unaligned params properly', function() {
7691
var unalignedFunction = 'var unalignedFunction = function(a,\n' +
7792
' b, c,\n' +

0 commit comments

Comments
 (0)