no-multi-spaces

禁止多个空格

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

一行中的多个不用于缩进的空格通常是错误的。例如:


if(foo  === "bar") {}

很难说,但是 foo=== 之间有两个空格。像这样的多个空格通常不赞成单个空格:


if(foo === "bar") {}

规则详情

该规则旨在禁止在逻辑表达式、条件表达式、声明、数组元素、对象属性、序列和函数参数周围出现多个空格。

KIjVZ8jbyN1kWo441FXYIh3AmcQhCDgs/8OlFVGexGn4OCCKsdfcgNWXdLQQbb4u

/*eslint no-multi-spaces: "error"*/

var a =  1;

if(foo   === "bar") {}

a <<  b

var arr = [1,  2];

a ?  b: c

AoqXtTV6Q8irP1mRQNh34rATVScSSkZAU175f14ev6145njeerHH1txMZ4OQcdup

/*eslint no-multi-spaces: "error"*/

var a = 1;

if(foo === "bar") {}

a << b

var arr = [1, 2];

a ? b: c

选项

6e1kFYAYojTUea7VgfHwIaucpS1BvGRDKDsdg5sYhQOfUJR2IlHN1IRYc/QlfAebis75dRfDfkI1NdePQSNayw==

    2E63PxWXZgwghie8srJGmPJdEcEWkW9LboLxD8dPSJhhtJ1+rjGRuaZHgTLYWuLD+5nwXLC7pgFTsUVFr0T+tK68jyeFsDNGJpq6jfdO1paIZoI0sqvSW8wirEmFQ/v/dBsoczCjm3mGOBvG0lfFqlRcCTfVSW3irc7szvI7ULrtjRhL3D2jIV2kGRPTphrjhgLbhWkwSLFC8vhHbMxY76tJjAfrSd6L5QbRAtAHYL73KIhMrJO0UEVPvFse2OPDgkIG3s+1r4Hp6iE/917Adjd4t3LbE42xOm4Uy2emj+Su7cPeoXAjJ7WzphhMz74cA7FmIQdK5ixUrAie1pozNRTj9XKsG/jMnkI/bXDNzHc=

ignoreEOLComments

wXU98SjUaQEBgUtrEm0JELa4x9G4nL5AxaN5WOh1tyMdBiHHchnSK2VYM5/uShy9qRA0DB7Rzw35AaBAkhyhAVOSYkqdsoDAT0kKE8MRq5Jvh1F82YedDi1Oe2yVQxC/M9zUDAn9XOin7l6PB/cGUA==

/*eslint no-multi-spaces: ["error", { ignoreEOLComments: false }]*/

var x = 5;      // comment
var x = 5;      /* multiline
 * comment
 */

wXU98SjUaQEBgUtrEm0JELa4x9G4nL5AxaN5WOh1tyMdBiHHchnSK2VYM5/uShy9qRA0DB7Rzw35AaBAkhyhAVOSYkqdsoDAT0kKE8MRq5JLnDHac3eSNq6p1jJ6Z5zhwl/VHzsxT5YhIWNPFhSLWQ==

/*eslint no-multi-spaces: ["error", { ignoreEOLComments: false }]*/

var x = 5; // comment
var x = 5; /* multiline
 * comment
 */

dnC4C79+++7hmkZ7ssvw8xqaj1TrLzWShPPlp8QQ8cYjTo6AHq7lUrDDaIT9Qvqh1MlItTPjdqgyyhzfniEfEochUQohRF5B6ietEeMbRtpS/A98YcRxfgL6tdtGiwSJ

/*eslint no-multi-spaces: ["error", { ignoreEOLComments: true }]*/

var x = 5; // comment
var x = 5;      // comment
var x = 5; /* multiline
 * comment
 */
var x = 5;      /* multiline
 * comment
 */

exceptions

/GxdfV/l0xmQHc60oQgxg1YSHnjJm6mUJoc0QaqNDHz7dOPEgez1lDqNCQazfhnuZmEOCf37GVmqZLZ6cVDNYT0JWz6/jG/Nt1lWKrFx82oXEkWASxia35ckUqsP9WiyP6TjiATlZN3xbOZc1NEj3a3RyLW7wY0avEDjCEFDUnqOWn0mEiMwbVBLdzot/46s

TdioEzSUohgxEENIzoL8HDp/x0vkG6ej4nqZMg1c1O+G+FepsBLRPRuFpPH5tovs47R4cigeg74coVaihiQ0gQZcyc3Oub2s/kBHdO7tRzcXYA8K26/dynpWtRRqvDZbl0eJI8hk7ITRTnF8TEpAUI57BiP/ZODIiJnGEHWQA4XiaQ7AGb/7CCaTqBRP4eW7k3lGuloNb+W78zjWGLSSAjC3xkzB11z95pAwloCyxrooL/QbU5cJLaQYg9PSHaxQwZzwCy8AGnvbV3171ajE7Hh/LWJv9Wqly3CPVyFvceY/7SLGsccNn5Iq8dFmqMDyP/NaMHtbugNuWpWw4k/4eztaOyKx0UgEvrGE4Bh8WeeuJL+yFJdc89NXUn7j6GR8CmC6QseWbdr2+0w0l4Ii22XoCSQfuQjzTE3XsZsGMOw=

Ba7IWdbGkE2Tnq20h5etKVCPYdoNWDRbcb6fAIgcQVbdmEjXVnUL3nWk+s+kn6vlItp67BSMQndvPfCOFYkXxMc+to96+/a059oI6zgxwBygdLKnrw1KFJDJvhl4fLtvXr3XehLZOHSiY6UUc5+wmMq5cLGHvvm/kYMT+bSRoCep9TyaRLNhXHw9Nuvq87Wwg+GqxTitJ9aZwUan4EkxQZA6VVjUnQ74tyk0JTJmHGbxWTjTzapehqCzH4owLoni7OSDOAtHcISdxeptr+Hr57uVhDT6RDvxWZRVfElU+Pw=

k45yN2KjoieGpfUlY2aOAJ/UddhhxYP/rUNXGJ1X3l7G2qGgtQ5KEeUcxY2IqBKrpprbyfkJS95ibwH8jOSCXAfTnse2n1tfUjmcO1OUuL4jUy5vpo2JbzF3Md5hz99S

/*eslint no-multi-spaces: "error"*/
/*eslint key-spacing: ["error", { align: "value" }]*/

var obj = {
    first:  "first",
    second: "second"
};

eInm3HApdRgdKk35GdoE4A0u9ughDDZDHzILIuQvNRI0ImkwHCXj28Bk2q7qjmmTS48Hzbmp4OIkaPqMWNYZ0d4l3r2mHX6QkIl0tGMRvmI=

/*eslint no-multi-spaces: ["error", { exceptions: { "Property": false } }]*/
/*eslint key-spacing: ["error", { align: "value" }]*/

var obj = {
    first:  "first",
    second: "second"
};

eInm3HApdRgdKk35GdoE4LOI0nKqQ7j4ZYXOyNptOQy5s9IEyBNLRp1E/lVktbtRQsmZ9HbXtpQa7CxPuitsvr7O3dK1bbnzfS8R4M240U3XLY6nM2IxIXBGzHTRCz1M

/*eslint no-multi-spaces: ["error", { exceptions: { "BinaryExpression": true } }]*/

var a = 1  *  2;

eInm3HApdRgdKk35GdoE4AbizykFXRLkK4kmEBelxrC3o3Li3/TyhGItKO8+MYwCdYMIovASRrb8A8h1qmt5tSx6FTjco+4jsJYrSjnhzC42Qpw4XQIkYNaNE67W4lDD

/*eslint no-multi-spaces: ["error", { exceptions: { "VariableDeclarator": true } }]*/

var someVar      = 'foo';
var someOtherVar = 'barBaz';

eInm3HApdRgdKk35GdoE4HQnr3W4ZM0Km1mtUWv+w2OOFJ1CyDOIrV5vZSCu9S0dVkIzD7ksv73X9UHtCRY8kKIH7fQBDDVyHLmiW4Ep2zpVTHImzRWSFZUyYS2Vs+41

/*eslint no-multi-spaces: ["error", { exceptions: { "ImportDeclaration": true } }]*/

import mod          from 'mod';
import someOtherMod from 'some-other-mod';

何时不使用

VUPoE9Nq6d7iihsKAqbqYw2l2l9+8X542XRPKqXu2wGaP8yeF5rU9xoNgqKUoQeqxJp+BRiq0pzFoROqIw1fjX6BxiennGwLrwmCvs4MUxw=