Last active
August 29, 2015 14:18
-
-
Save davidwaterston/56ee2edd9d51a66747aa to your computer and use it in GitHub Desktop.
ESLint custom rule: Disallow last property of a multiple property object to be declared on last line (no-multi-object-properties-last-line)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* global module */ | |
"use strict"; | |
module.exports = function (context) { | |
function checkObjectExpression(node) { | |
var numberOfProperties = node.properties.length; | |
var objHasMultipleProperties = (numberOfProperties > 1); | |
var propertyOnSameLineAsClosingBrace; | |
if (objHasMultipleProperties) { | |
propertyOnSameLineAsClosingBrace = (node.properties[node.properties.length - 1].loc.end.line === node.loc.end.line); | |
if (propertyOnSameLineAsClosingBrace) { | |
context.report( | |
node, | |
{ | |
line: node.properties[node.properties.length - 1].loc.end.line, | |
column: node.properties[node.properties.length - 1].loc.end.column | |
}, | |
"object property on same line as closing brace" | |
); | |
} | |
} | |
} | |
return { | |
"ObjectExpression": checkObjectExpression | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment