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

Commit

Permalink
Fix: Last method throw in requireObjectKeysOnNewLine
Browse files Browse the repository at this point in the history
Fixes #2224
Closes gh-2227
  • Loading branch information
qfox committed Apr 30, 2016
1 parent be0734f commit 80203a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/rules/require-object-keys-on-new-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@ module.exports.prototype = {
file.iterateNodesByType('ObjectExpression', function(node) {
var firstKeyToken;
var lastValueToken;
var lastProp;

if (isSameLine) {
if (node.properties.length > 1) {
firstKeyToken = file.getFirstNodeToken(node.properties[0].key);
lastValueToken = file.getLastNodeToken(node.properties[node.properties.length - 1].value);
lastProp = node.properties[node.properties.length - 1];
lastValueToken = file.getLastNodeToken(lastProp.value || lastProp.key);

if (firstKeyToken.getLoc().end.line === lastValueToken.getLoc().start.line) {
// It's ok, all keys and values are on the same line.
Expand Down
4 changes: 4 additions & 0 deletions test/specs/rules/require-object-keys-on-new-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,9 @@ describe('rules/require-object-keys-on-new-line', function() {
expect(checker.checkString('var a = {a: "b",c: "d",\ne: "f"\n};'))
.to.have.one.validation.error.from('requireObjectKeysOnNewLine');
});

it('should neither throw nor report last methods on the same line', function() {
expect(checker.checkString('var a = {a: "b", c: "d", method() {}};')).to.have.no.errors();
});
});
});

0 comments on commit 80203a1

Please sign in to comment.