Versions

arrow-spacing

Enforce consistent spacing before and after the arrow in arrow functions

🔧 Fixable

Some problems reported by this rule are automatically fixable by the --fix command line option

这条规则规范了箭头函数的箭头(=>)前后的间距样式。

/*eslint-env es6*/

// { "before": true, "after": true }
(a) => {}

// { "before": false, "after": false }
(a)=>{}

规则细节

这个规则接受对象参数,其中包含 beforeafter 属性,每个都是布尔值。

默认配置是 { "before": true, "after": true }

true 意味着应该有一个或多个空格false 意味着没有空格

使用此规则与默认 { "before": true, "after": true } 选项的错误示例:

Open in Playground
/*eslint arrow-spacing: "error"*/
/*eslint-env es6*/

()=> {};
() =>{};
(a)=> {};
(a) =>{};
a =>a;
a=> a;
()=> {'\n'};
() =>{'\n'};

使用此规则与默认 { "before": true, "after": true } 选项的正确示例:

Open in Playground
/*eslint arrow-spacing: "error"*/
/*eslint-env es6*/

() => {};
(a) => {};
a => a;
() => {'\n'};

使用此规则与 { "before": false, "after": false } 选项的错误示例:

Open in Playground
/*eslint arrow-spacing: ["error", { "before": false, "after": false }]*/
/*eslint-env es6*/

() =>{};
(a) => {};
()=> {'\n'};

使用此规则与 { "before": false, "after": false } 选项的正确示例:

Open in Playground
/*eslint arrow-spacing: ["error", { "before": false, "after": false }]*/
/*eslint-env es6*/

()=>{};
(a)=>{};
()=>{'\n'};

使用此规则与 { "before": false, "after": true } 选项的错误示例:

Open in Playground
/*eslint arrow-spacing: ["error", { "before": false, "after": true }]*/
/*eslint-env es6*/

() =>{};
(a) => {};
()=>{'\n'};

使用此规则与 { "before": false, "after": true } 选项的正确示例:

Open in Playground
/*eslint arrow-spacing: ["error", { "before": false, "after": true }]*/
/*eslint-env es6*/

()=> {};
(a)=> {};
()=> {'\n'};

Version

This rule was introduced in ESLint v1.0.0-rc-1.

Resources

更改语言