Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidwaterston/83982fb75c9b8ea27333 to your computer and use it in GitHub Desktop.
Save davidwaterston/83982fb75c9b8ea27333 to your computer and use it in GitHub Desktop.
ESLint custom rule: Disallow multiple object properties to be declared on one line (no-multi-object-properties-one-line)
/* global module */
"use strict";
module.exports = function (context) {
function checkObjectExpression(node) {
var multiplePropertiesOnOneLine;
var numberOfLines;
var numberOfProperties = node.properties.length;
var objHasMultipleProperties = (numberOfProperties > 1);
if (objHasMultipleProperties) {
numberOfLines = ((node.properties[node.properties.length - 1].loc.start.line) - node.properties[0].loc.start.line) + 1;
multiplePropertiesOnOneLine = (numberOfLines < numberOfProperties);
if (multiplePropertiesOnOneLine) {
context.report(node, "multiple object properties on one line");
}
}
}
return {
"ObjectExpression": checkObjectExpression
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment