Skip to content

Instantly share code, notes, and snippets.

@davidwaterston
Last active August 29, 2015 14:18
Show Gist options
  • Save davidwaterston/56ee2edd9d51a66747aa to your computer and use it in GitHub Desktop.
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)
/* 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