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/f5e9fec627b440db699f to your computer and use it in GitHub Desktop.
Save davidwaterston/f5e9fec627b440db699f to your computer and use it in GitHub Desktop.
ESLint custom rule: Disallow first property of a multiple property object to be declared on first line (no-multi-object-properties-first-line)
/* global module */
"use strict";
module.exports = function (context) {
function checkObjectExpression(node) {
var numberOfProperties = node.properties.length;
var objHasMultipleProperties = (numberOfProperties > 1);
var propertyOnSameLineAsOpeningBrace;
if (objHasMultipleProperties) {
propertyOnSameLineAsOpeningBrace = (node.properties[0].loc.start.line === node.loc.start.line);
if (propertyOnSameLineAsOpeningBrace) {
context.report(node, "object property on same line as opening brace");
}
}
}
return {
"ObjectExpression": checkObjectExpression
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment