array-element-newline

在每个数组元素后强制换行

一些该规则报告的问题可以通过 --fix 命令行选项 自动修复

许多样式指南要求或不允许在数组元素之间换行。

规则详情

此规则强制在数组元素之间换行。

选项

此规则有一个字符串选项:

    QWqMp2YEiEN2EoNjBDcBL4XzGksmdPJNCbcEKyT4TNO4A4DJUPVSsgAVNfxaotD4En/ihvbj3HANKqyWSGcwx5VnMkt7H9BNxLlRekRpLFQmWyKXWfqfgmZidG+A0/xztiO7xRnpksKMNXhdCNRBSIKkaC7sTZ5S5LMf6EHWhuiyhsNPddpgnb9qeteNWo2z3X7Yia02Dh5lndftXvNCkgwrkXBIFswPWZqhtknQcLc1DPGv9hKDfa3LFJlL5bO8JwgUREzQHlYljUjUyPQRAG35wbuGwguwEjDM1B4vgRl3YbtX1jNbqQjqqqMZfHDk

XOM+GeqxQe13NTP+xWEbO6n+zartN6sl991f0aJT5BNbT0W9tm9AeqmI9TH0H+MEx49fVPg5EdYXARBV5odM5Lm+m9Jui0M5ZYTTOwdTBgkXgVuHWkhmUvtDY3jMQxgNTXQww3B7DF/A8cRf1r00qA==

    elGcz8r1agsvLCAJNB7ZdevsMT/kYzvlkfjVjqKT186+asYpJIbvDbA8MccQISDNoO9fsYdzc6RslzuTHW5mGUQU2TB5bCGFduCzuVGYWMnDzZkW0cFM6D6hI/IGZspgKjLalvvewfizpNi4geN/zx5eTkWl+QC9P3P2HeiRhXCAkwvhyjaTLhqW205yhArgSyYmMI70hpjWzLYa+h/LDrEyi27xSGjCMpWEnkcCjVgn5sqxTLODAaKH/iebSpvYL1DUKMDF9rAVlWCKRJJt6etLAqVkj1TQVUrlXlPFML1WUN9CuirVg0rMG/aLuTNzOLqhMRewxQX8DWF//ZQyaIleT+9ChSAK1plb8+vIv/oKSFQjMavMitYGuibu7XucSu2K54woEr2HF/cIwB0eRIpPz+hHotu0PETaHbF2Ztx31j1akOnEHihKRlIZz1PNQMi1l2qEyziDQo0VvQIYm36pE8TAiQA4KgHpkSkepKC6sdNejl+fUd7sHDK8+OCNHleyC9sviVIDzlf3Xd4g1Udugb81aBE0RIiw+FZlXnQ=

pfwSpnC0eBhHJYpH1tuXv9pjTqqeUF22AZPoDkegIt0x6yI2xy2z55VNmMfInxZ9NHY1gDyXkQ2KPvEFQo01bQOOi8xdum1SBNd98BxYfwA=

{
    "array-element-newline": ["error", {
        "ArrayExpression": "consistent",
        "ArrayPattern": { "minItems": 3 },
    }]
}
    p6K3+1x/CK5tVpPph/V5iiltpaz4tWUjCq4z3652NVBPM0C3gTXNGaGTnlw2ZeG7OhCsLi4njh5BZdyww2V4JkHgHvY802o/sIwHVkyGEjutX9nyyMfoZSsEOgxuWZSmhTF/OlF6zaDQtQdUWXZ64NWy22TFLraOGZFQ7U/91wXTSF+Y+hsDffo2j7CvBLMqpx4uOqoxgh+E1rhSV3FvtXwAYX5EBKgmZlQkm3LmxvIZQWseWyUMYu5gEUpbVi75u0jX7u4FNVjbEV+BoaQmbG2Kmk84VAoMenTvrDrvCwd9GISSTxM1+RuY9PYN3lgCI0csbOUPwe+yrrCW85dAWnqWiYrhCnJF4YU4OddOPfc=

always

6OjE+A1hvEglXN51x/s/8uZtOgB+xUuBU8wX5Pw6bMlgFgYyiCngBbb9IXR0IzxRqvgTUPD6/Z3CWcx8D3ijpAwjZYsueQ3Vhvdcqf+mHdY=

/*eslint array-element-newline: ["error", "always"]*/

var c = [1, 2];
var d = [1, 2, 3];
var e = [1, 2, 3
];
var f = [
  1, 2, 3
];
var g = [
    function foo() {
        dosomething();
    }, function bar() {
        dosomething();
    }
];

6OjE+A1hvEglXN51x/s/8uZtOgB+xUuBU8wX5Pw6bMlgFgYyiCngBbb9IXR0IzxRqM2u9+zXH+sOX5Zvln60C1/4tETr3VM+M2ewWx+mdgs=

/*eslint array-element-newline: ["error", "always"]*/

var a = [];
var b = [1];
var c = [1,
    2];
var d = [1,
    2,
    3];
var d = [
  1, 
  2, 
  3
];
var e = [
    function foo() {
        dosomething();
    },
    function bar() {
        dosomething();
    }
];

never

7xDYtjDnSQq8pZ502SNO6iSbSSgf88JvINV+VW/7mjjjFiN9kgk1SZeCsyIjd2Dk8k6MmZcA+2HbZXyreFXjTqy/sqwbdiiEliJLfZHfH0U=

/*eslint array-element-newline: ["error", "never"]*/

var c = [
    1,
    2
];
var d = [
    1,
    2,
    3
];
var e = [
    function foo() {
        dosomething();
    },
    function bar() {
        dosomething();
    }
];

7xDYtjDnSQq8pZ502SNO6iSbSSgf88JvINV+VW/7mjglYsFdA9pWHwqRpV9joLGkNKHwlcyw6ZkK4XHAI0leF18G96W/FEOjyH7wSDDTYP0=

/*eslint array-element-newline: ["error", "never"]*/

var a = [];
var b = [1];
var c = [1, 2];
var d = [1, 2, 3];
var e = [
    1, 2, 3];
var f = [
  1, 2, 3
];
var g = [
    function foo() {
        dosomething();
    }, function bar() {
        dosomething();
    }
];

consistent

7xDYtjDnSQq8pZ502SNO6hPXG5S4UaAf7yMtpTDvFZWh1IjNfv1evYKh2riEOrOakKdyN4Gp9PC4rrftIMXJnuk+R67+T3/t6AU/HFU3saE=

/*eslint array-element-newline: ["error", "consistent"]*/

var a = [
    1, 2,
    3
];
var b = [
    function foo() {
        dosomething();
    }, function bar() {
        dosomething();
    },
    function baz() {
        dosomething();
    }
];

7xDYtjDnSQq8pZ502SNO6hPXG5S4UaAf7yMtpTDvFZWh1IjNfv1evYKh2riEOrOaMwwu/R9NRy0mzN1n5FZVDPUdKLjr/jqZeme7/TUp8jU=

/*eslint array-element-newline: ["error", "consistent"]*/

var a = [];
var b = [1];
var c = [1, 2];
var d = [1, 2, 3];
var e = [
    1,
    2
];
var f = [
    1,
    2,
    3
];
var g = [
    function foo() {
        dosomething();
    }, function bar() {
        dosomething();
    }, function baz() {
        dosomething();
    }
];
var h = [
    function foo() {
        dosomething();
    },
    function bar() {
        dosomething();
    },
    function baz() {
        dosomething();
    }
];

multiline

7xDYtjDnSQq8pZ502SNO6q7Z0ywh8gBbeKcXOWsg0k7qiOUWs1bVC4w3Lh2f/+c2hlGArb1BGsB76IsBaeCQqIw9/6NXqyJ6N4yl/MCmbWfy6DK6FV0peKKl35Y9aOBr

/*eslint array-element-newline: ["error", { "multiline": true }]*/

var d = [1,
    2, 3];
var e = [
    function foo() {
        dosomething();
    }, function bar() {
        dosomething();
    }
];

7xDYtjDnSQq8pZ502SNO6q7Z0ywh8gBbeKcXOWsg0k7qiOUWs1bVC4w3Lh2f/+c2o9GatLt8TDI7B+xMhz0D0PPC1lSS6LoAAQnrjzshsi1rgzqp26LezReyuquuCROc

/*eslint array-element-newline: ["error", { "multiline": true }]*/

var a = [];
var b = [1];
var c = [1, 2];
var d = [1, 2, 3];
var e = [
    function foo() {
        dosomething();
    },
    function bar() {
        dosomething();
    }
];

minItems

7xDYtjDnSQq8pZ502SNO6pHfQo8T+okXgCrw2rRqzOV8X4m5PCnrQwd/mNAMLiTfDhFVB9G5nxHOSfYaIkV07mxZQFpJUGrLj3V8aQiMpAM=

/*eslint array-element-newline: ["error", { "minItems": 3 }]*/

var c = [1,
    2];
var d = [1, 2, 3];
var e = [
    function foo() {
        dosomething();
    },
    function bar() {
        dosomething();
    }
];

7xDYtjDnSQq8pZ502SNO6pHfQo8T+okXgCrw2rRqzOV8X4m5PCnrQwd/mNAMLiTf9Mif48yYL7TqnE4y6fm09jlkVrNVYX1Y9f45bxq7dGQ=

/*eslint array-element-newline: ["error", { "minItems": 3 }]*/

var a = [];
var b = [1];
var c = [1, 2];
var d = [1,
    2,
    3];
var e = [
    function foo() {
        dosomething();
    }, function bar() {
        dosomething();
    }
];

multiline 和 minItems

7xDYtjDnSQq8pZ502SNO6q7Z0ywh8gBbeKcXOWsg0k7znIrfds9DuI75Pr8VP+kMgY2DfRqXI4CA5mNjQp9SKjCWU8YiSmkYm0YoA1cH37hbFnJxa+NoRIgXk8Yz6kql1I8wqBV0clFt4siGyyMViw==

/*eslint array-element-newline: ["error", { "multiline": true, "minItems": 3 }]*/

var c = [1,
2];
var d = [1, 2, 3];
var e = [
    function foo() {
        dosomething();
    }, function bar() {
        dosomething();
    }
];

7xDYtjDnSQq8pZ502SNO6q7Z0ywh8gBbeKcXOWsg0k7znIrfds9DuI75Pr8VP+kMgY2DfRqXI4CA5mNjQp9SKos1K58weREEiza4T3jd+OSUDmiQ6esAmoijL0QDTpjdbcxoHTD/EbGUM1AOLqukZA==

/*eslint array-element-newline: ["error", { "multiline": true, "minItems": 3 }]*/

var a = [];
var b = [1];
var c = [1, 2];
var d = [1,
    2,
    3];
var e = [
    function foo() {
        dosomething();
    },
    function bar() {
        dosomething();
    }
];

ArrayExpression 和 ArrayPattern

7xDYtjDnSQq8pZ502SNO6lY7bVlSH4nxET1JWHJfuEq5Y8ennioLxRk0ZbSccELwf9MSL4OeeoitIEcfSMP4IbC2IrCukwK/M38KjpX9qCY2DijEVVZwt2vu6u6o0w6aKRfZoC2pl4nUG23MN6xzS1B5/tnsQdbPAIU3Oh5nPc0=

/*eslint array-element-newline: ["error", { "ArrayExpression": "always", "ArrayPattern": "never" }]*/

var a = [1, 2];
var b = [1, 2, 3];
var c = [
    function foo() {
        dosomething();
    }, function bar() {
        dosomething();
    }
];

var [d,
    e] = arr;
var [f,
    g,
    h] = arr;
var [i = function foo() {
  dosomething()
},
j = function bar() {
  dosomething()
}] = arr

7xDYtjDnSQq8pZ502SNO6lY7bVlSH4nxET1JWHJfuEq5Y8ennioLxRk0ZbSccELwf9MSL4OeeoitIEcfSMP4IbC2IrCukwK/M38KjpX9qCZ1CmajNc7r6FvSx6/dkVGGHVdCw/QoHrHVIViL9KOm5watxihZcGCodVDytfBGWEQ=

/*eslint array-element-newline: ["error", { "ArrayExpression": "always", "ArrayPattern": "never" }]*/

var a = [1,
    2];
var b = [1,
    2,
    3];
var c = [
    function foo() {
        dosomething();
    },
    function bar() {
        dosomething();
    }
];

var [d, e] = arr
var [f, g, h] = arr
var [i = function foo() {
    dosomething()
}, j = function bar() {
    dosomething()
}] = arr

何时不使用

LlvfTlGNiqWwT39ynjGQIfzc7uWY4oT+ixv1SCNPdnm6ZXupO2PeQlWRQ8fG+uswu+FypEm8Ae6t6VXpVWGOzoaOO/Wyylma+UNzfafzkv4=

兼容性

    V0QOsqqMGL+OBNItGtHgQEyNadtujPpY1/jdNqdyB12LanuFtv/lqSdhZfx9n6OvujUsCvv7cq7M8cHRWek7lFxCkZNxOEgs7dS+84q2e4kTlC+2UUHtbVUBIWxqzBMXnYyGrZ01dTIT7MlSuBKXp++q1knICSAjh2SEdNnBwn8=