]>
Commit | Line | Data |
---|---|---|
8f9d1d4d DC |
1 | --- |
2 | title: arrow-spacing | |
8f9d1d4d DC |
3 | rule_type: layout |
4 | --- | |
5 | ||
6 | ||
eb39fafa DC |
7 | |
8 | This rule normalize style of spacing before/after an arrow function's arrow(`=>`). | |
9 | ||
10 | ```js | |
11 | /*eslint-env es6*/ | |
12 | ||
13 | // { "before": true, "after": true } | |
14 | (a) => {} | |
15 | ||
16 | // { "before": false, "after": false } | |
17 | (a)=>{} | |
18 | ``` | |
19 | ||
20 | ## Rule Details | |
21 | ||
22 | This rule takes an object argument with `before` and `after` properties, each with a Boolean value. | |
23 | ||
24 | The default configuration is `{ "before": true, "after": true }`. | |
25 | ||
26 | `true` means there should be **one or more spaces** and `false` means **no spaces**. | |
27 | ||
28 | Examples of **incorrect** code for this rule with the default `{ "before": true, "after": true }` option: | |
29 | ||
8f9d1d4d DC |
30 | :::incorrect |
31 | ||
eb39fafa DC |
32 | ```js |
33 | /*eslint arrow-spacing: "error"*/ | |
34 | /*eslint-env es6*/ | |
35 | ||
36 | ()=> {}; | |
37 | () =>{}; | |
38 | (a)=> {}; | |
39 | (a) =>{}; | |
40 | a =>a; | |
41 | a=> a; | |
42 | ()=> {'\n'}; | |
43 | () =>{'\n'}; | |
44 | ``` | |
45 | ||
8f9d1d4d DC |
46 | ::: |
47 | ||
eb39fafa DC |
48 | Examples of **correct** code for this rule with the default `{ "before": true, "after": true }` option: |
49 | ||
8f9d1d4d DC |
50 | :::correct |
51 | ||
eb39fafa DC |
52 | ```js |
53 | /*eslint arrow-spacing: "error"*/ | |
54 | /*eslint-env es6*/ | |
55 | ||
56 | () => {}; | |
57 | (a) => {}; | |
58 | a => a; | |
59 | () => {'\n'}; | |
60 | ``` | |
61 | ||
8f9d1d4d DC |
62 | ::: |
63 | ||
eb39fafa DC |
64 | Examples of **incorrect** code for this rule with the `{ "before": false, "after": false }` option: |
65 | ||
8f9d1d4d DC |
66 | :::incorrect |
67 | ||
eb39fafa DC |
68 | ```js |
69 | /*eslint arrow-spacing: ["error", { "before": false, "after": false }]*/ | |
70 | /*eslint-env es6*/ | |
71 | ||
72 | () =>{}; | |
73 | (a) => {}; | |
74 | ()=> {'\n'}; | |
75 | ``` | |
76 | ||
8f9d1d4d DC |
77 | ::: |
78 | ||
eb39fafa DC |
79 | Examples of **correct** code for this rule with the `{ "before": false, "after": false }` option: |
80 | ||
8f9d1d4d DC |
81 | :::correct |
82 | ||
eb39fafa DC |
83 | ```js |
84 | /*eslint arrow-spacing: ["error", { "before": false, "after": false }]*/ | |
85 | /*eslint-env es6*/ | |
86 | ||
87 | ()=>{}; | |
88 | (a)=>{}; | |
89 | ()=>{'\n'}; | |
90 | ``` | |
91 | ||
8f9d1d4d DC |
92 | ::: |
93 | ||
eb39fafa DC |
94 | Examples of **incorrect** code for this rule with the `{ "before": false, "after": true }` option: |
95 | ||
8f9d1d4d DC |
96 | :::incorrect |
97 | ||
eb39fafa DC |
98 | ```js |
99 | /*eslint arrow-spacing: ["error", { "before": false, "after": true }]*/ | |
100 | /*eslint-env es6*/ | |
101 | ||
102 | () =>{}; | |
103 | (a) => {}; | |
104 | ()=>{'\n'}; | |
105 | ``` | |
106 | ||
8f9d1d4d DC |
107 | ::: |
108 | ||
eb39fafa DC |
109 | Examples of **correct** code for this rule with the `{ "before": false, "after": true }` option: |
110 | ||
8f9d1d4d DC |
111 | :::correct |
112 | ||
eb39fafa DC |
113 | ```js |
114 | /*eslint arrow-spacing: ["error", { "before": false, "after": true }]*/ | |
115 | /*eslint-env es6*/ | |
116 | ||
117 | ()=> {}; | |
118 | (a)=> {}; | |
119 | ()=> {'\n'}; | |
120 | ``` | |
8f9d1d4d DC |
121 | |
122 | ::: |