arrow-spacing
在箭头函数中的箭头前后强制执行一致的间距
此规则报告的一些问题可通过 --fix 命令行 选项自动修复
This rule was deprecated in ESLint v8.53.0. It will be removed in v11.0.0. Please use the corresponding rule in @stylistic/eslint-plugin.
此规则规范箭头函数的箭头(=>)前后的空格样式。
🌐 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 意味着 没有空格。
使用默认 { "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 中引入。