davidwaterston
4/6/2015 - 10:45 AM

ESLint custom rule: Disallow first property of a multiple property object to be declared on first line (no-multi-object-properties-first-lin

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
    };

};