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