Last active
August 29, 2015 14:18
-
-
Save davidwaterston/9772bf769125755b45f1 to your computer and use it in GitHub Desktop.
ESLint custom rule: Disallow object property values from appearing on a different line from their key
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 props = node.properties; | |
var numberOfProperties = props.length; | |
var i; | |
var nameAndValueAreOnDifferentLines; | |
for (i = 0; i < numberOfProperties; i++) { | |
nameAndValueAreOnDifferentLines = (props[i].key.loc.start.line !== props[i].value.loc.start.line); | |
if (nameAndValueAreOnDifferentLines) { | |
context.report( | |
node, | |
{ | |
line: props[i].key.loc.start.line, | |
column: props[i].key.loc.start.column | |
}, | |
"object property key '" + props[i].key.name + "' has its value on a different line" | |
); | |
} | |
} | |
} | |
return { | |
"ObjectExpression": checkObjectExpression | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment