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

Commit

Permalink
Fix: disallowCommaBeforeLineBreak correctly handle empty object
Browse files Browse the repository at this point in the history
Fixes #1841
Closes gh-1846
  • Loading branch information
markelog authored and hzoo committed Oct 7, 2015
1 parent 3bcbab1 commit 6571ebb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/rules/disallow-comma-before-line-break.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Disallows commas as last token on a line in lists.
*
* Type: `Boolean`|`Object`
* Type: `Boolean`, `Object`
*
* Values:
* - `true` for default behavior (strict mode, comma on the same line)
Expand All @@ -24,7 +24,7 @@
* one: 1
* , two: 2
* };
* var y = { three: 3, four: 4};
* var y = {three: 3, four: 4};
* ```
*
* ##### Invalid
Expand Down Expand Up @@ -87,7 +87,12 @@ module.exports.prototype = {
return true;
}

return exceptFunction && node.properties.some(function(property) {
// See #1841
if (!exceptFunction || !node.properties) {
return false;
}

return node.properties.some(function(property) {
return property.value.type === 'FunctionExpression';
});
}
Expand Down
6 changes: 6 additions & 0 deletions test/specs/rules/disallow-comma-before-line-break.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ describe('rules/disallow-comma-before-line-break', function() {
checker.checkString('var a = {a:1,\nc:3};').getErrorCount() === 2
);
});

it('should handle empty objects', function() {
assert(
checker.checkString('var x = {}\n, t = 2;').isEmpty()
);
});
});
});
});
Expand Down

0 comments on commit 6571ebb

Please sign in to comment.