Created
April 6, 2015 10:45
-
-
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)
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 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