This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Fix: `disallowCommaBeforeLineBreak` correctly handle empty object

Fixes #1841
Closes gh-1846
  • Loading branch information...
markelog authored and hzoo committed Oct 6, 2015
1 parent 3bcbab1 commit 6571ebbbf29e5b96be45ade585e4676de3c2817d
@@ -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)
@@ -24,7 +24,7 @@
* one: 1
* , two: 2
* };
* var y = { three: 3, four: 4};
* var y = {three: 3, four: 4};
* ```
*
* ##### Invalid
@@ -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';
});
}
@@ -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()
);
});
});
});
});

0 comments on commit 6571ebb

Please sign in to comment.