arrow-spacing
在箭头函数中的箭头前后强制执行一致的间距
此规则报告的一些问题可通过 --fix
命令行 选项自动修复
This rule was deprecated in ESLint v8.53.0. Please use the corresponding rule in @stylistic/eslint-plugin-js.
此规则规范了箭头函数的箭头(=>
)之前/之后的间距样式。
¥This rule normalize style of spacing before/after an arrow function’s arrow(=>
).
// { "before": true, "after": true }
(a) => {}
// { "before": false, "after": false }
(a)=>{}
规则详情
¥Rule Details
此规则采用具有 before
和 after
属性的对象参数,每个属性都有一个布尔值。
¥This rule takes an object argument with before
and after
properties, each with a Boolean value.
默认配置为 { "before": true, "after": true }
。
¥The default configuration is { "before": true, "after": true }
.
true
表示应该有一个或多个空格,false
表示没有空格。
¥true
means there should be one or more spaces and false
means no spaces.
使用默认 { "before": true, "after": true }
选项的此规则的错误代码示例:
¥Examples of incorrect code for this rule with the default { "before": true, "after": true }
option:
/*eslint arrow-spacing: "error"*/
()=> {};
() =>{};
(a)=> {};
(a) =>{};
a =>a;
a=> a;
()=> {'\n'};
() =>{'\n'};
使用默认 { "before": true, "after": true }
选项的此规则的正确代码示例:
¥Examples of correct code for this rule with the default { "before": true, "after": true }
option:
/*eslint arrow-spacing: "error"*/
() => {};
(a) => {};
a => a;
() => {'\n'};
使用 { "before": false, "after": false }
选项的此规则的错误代码示例:
¥Examples of incorrect code for this rule with the { "before": false, "after": false }
option:
/*eslint arrow-spacing: ["error", { "before": false, "after": false }]*/
() =>{};
(a) => {};
()=> {'\n'};
使用 { "before": false, "after": false }
选项的此规则的正确代码示例:
¥Examples of correct code for this rule with the { "before": false, "after": false }
option:
/*eslint arrow-spacing: ["error", { "before": false, "after": false }]*/
()=>{};
(a)=>{};
()=>{'\n'};
使用 { "before": false, "after": true }
选项的此规则的错误代码示例:
¥Examples of incorrect code for this rule with the { "before": false, "after": true }
option:
/*eslint arrow-spacing: ["error", { "before": false, "after": true }]*/
() =>{};
(a) => {};
()=>{'\n'};
使用 { "before": false, "after": true }
选项的此规则的正确代码示例:
¥Examples of correct code for this rule with the { "before": false, "after": true }
option:
/*eslint arrow-spacing: ["error", { "before": false, "after": true }]*/
()=> {};
(a)=> {};
()=> {'\n'};
版本
此规则是在 ESLint v1.0.0-rc-1 中引入。