space-infix-ops

中缀运算符周围需要间距

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

虽然格式偏好是非常个人化的,但许多样式指南需要在运算符周围留有空格,例如:

var sum = 1 + 2;

该规则的支持者认为,它使代码更易于阅读,并且可以更轻松地突出潜在错误,例如:

var sum = i+++2;

虽然这是有效的 JavaScript 语法,但很难确定作者的意图。

规则详情

fcnPMliMxA/yFQ0zjIsv0DUpn2iLKt39vb30YvyVSdDchyuT5vZqWdJb5S3GB+bGY5w/2pUFTF2oCFT2cCw07w==

选项

Gm9qi3W2wusKCtJAkBL8MqbwqMA6dHxcynfrNJ3xRdNuuykjoCKNBSEGlgSP+7jL6HtuZfJPiSccQ9wroWnx4A==

"space-infix-ops": ["error", { "int32Hint": false }]

int32Hint

5uIauZ99Ncs1Kraw6FJAq7YA1gFKxd8fTbeJKKzwppJQ1U0uuqqhp0KCemiBNgBBbXmM8R2tYpToJdVx6kN1XztRoqMXi7ZomSQoYKykFrcp9fvD0J8HjE5dm72TrIXY3y39LEw+64niR62g/Utz9Ap0KDsx17VM+Xd7FibeqpL3q19mrS30a72PgFJi50Wrmpy16Sy2P1c2cQsJrXEFhg==

var foo = bar|0; // `foo` is forced to be signed 32 bit integer

KIjVZ8jbyN1kWo441FXYIh3AmcQhCDgs/8OlFVGexGn4OCCKsdfcgNWXdLQQbb4u

/*eslint space-infix-ops: "error"*/
/*eslint-env es6*/

a+b

a+ b

a +b

a?b:c

const a={b:1};

var {a=0}=bar;

function foo(a=0) { }

AoqXtTV6Q8irP1mRQNh34rATVScSSkZAU175f14ev6145njeerHH1txMZ4OQcdup

/*eslint space-infix-ops: "error"*/
/*eslint-env es6*/

a + b

a       + b

a ? b : c

const a = {b:1};

var {a = 0} = bar;

function foo(a = 0) { }

何时不使用

VbhtQRAJpPlzy6JW+/kv62hwwbU4onGuPM2WfSGpPRU3coGl88ul9ESonJqWVCrhXXa6wE2PWYdIc/Hsl0wrv7+fmduUo45KjAR22Q6OZsbyPBbyDXbGTryRX7k0O/9U