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

Commit 6571ebb

Browse files
markeloghzoo
authored andcommitted
Fix: disallowCommaBeforeLineBreak correctly handle empty object
Fixes #1841 Closes gh-1846
1 parent 3bcbab1 commit 6571ebb

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lib/rules/disallow-comma-before-line-break.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Disallows commas as last token on a line in lists.
33
*
4-
* Type: `Boolean`|`Object`
4+
* Type: `Boolean`, `Object`
55
*
66
* Values:
77
* - `true` for default behavior (strict mode, comma on the same line)
@@ -24,7 +24,7 @@
2424
* one: 1
2525
* , two: 2
2626
* };
27-
* var y = { three: 3, four: 4};
27+
* var y = {three: 3, four: 4};
2828
* ```
2929
*
3030
* ##### Invalid
@@ -87,7 +87,12 @@ module.exports.prototype = {
8787
return true;
8888
}
8989

90-
return exceptFunction && node.properties.some(function(property) {
90+
// See #1841
91+
if (!exceptFunction || !node.properties) {
92+
return false;
93+
}
94+
95+
return node.properties.some(function(property) {
9196
return property.value.type === 'FunctionExpression';
9297
});
9398
}

test/specs/rules/disallow-comma-before-line-break.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ describe('rules/disallow-comma-before-line-break', function() {
8686
checker.checkString('var a = {a:1,\nc:3};').getErrorCount() === 2
8787
);
8888
});
89+
90+
it('should handle empty objects', function() {
91+
assert(
92+
checker.checkString('var x = {}\n, t = 2;').isEmpty()
93+
);
94+
});
8995
});
9096
});
9197
});

0 commit comments

Comments
 (0)