]>
Commit | Line | Data |
---|---|---|
eb39fafa DC |
1 | # enforce line breaks between arguments of a function call (function-call-argument-newline) |
2 | ||
3 | A number of style guides require or disallow line breaks between arguments of a function call. | |
4 | ||
5 | ## Rule Details | |
6 | ||
7 | This rule enforces line breaks between arguments of a function call. | |
8 | ||
9 | ## Options | |
10 | ||
11 | This rule has a string option: | |
12 | ||
13 | * `"always"` (default) requires line breaks between arguments | |
14 | * `"never"` disallows line breaks between arguments | |
15 | * `"consistent"` requires consistent usage of line breaks between arguments | |
16 | ||
17 | ||
18 | ### always | |
19 | ||
20 | Examples of **incorrect** code for this rule with the default `"always"` option: | |
21 | ||
22 | ```js | |
23 | /*eslint function-call-argument-newline: ["error", "always"]*/ | |
24 | ||
25 | foo("one", "two", "three"); | |
26 | ||
27 | bar("one", "two", { | |
28 | one: 1, | |
29 | two: 2 | |
30 | }); | |
31 | ||
32 | baz("one", "two", (x) => { | |
33 | console.log(x); | |
34 | }); | |
35 | ``` | |
36 | ||
37 | Examples of **correct** code for this rule with the default `"always"` option: | |
38 | ||
39 | ```js | |
40 | /*eslint function-call-argument-newline: ["error", "always"]*/ | |
41 | ||
42 | foo( | |
43 | "one", | |
44 | "two", | |
45 | "three" | |
46 | ); | |
47 | ||
48 | bar( | |
49 | "one", | |
50 | "two", | |
51 | { one: 1, two: 2 } | |
52 | ); | |
53 | // or | |
54 | bar( | |
55 | "one", | |
56 | "two", | |
57 | { | |
58 | one: 1, | |
59 | two: 2 | |
60 | } | |
61 | ); | |
62 | ||
63 | baz( | |
64 | "one", | |
65 | "two", | |
66 | (x) => { | |
67 | console.log(x); | |
68 | } | |
69 | ); | |
70 | ``` | |
71 | ||
72 | ||
73 | ### never | |
74 | ||
456be15e | 75 | Examples of **incorrect** code for this rule with the `"never"` option: |
eb39fafa DC |
76 | |
77 | ```js | |
78 | /*eslint function-call-argument-newline: ["error", "never"]*/ | |
79 | ||
80 | foo( | |
81 | "one", | |
82 | "two", "three" | |
83 | ); | |
84 | ||
85 | bar( | |
86 | "one", | |
87 | "two", { | |
88 | one: 1, | |
89 | two: 2 | |
90 | } | |
91 | ); | |
92 | ||
93 | baz( | |
94 | "one", | |
95 | "two", (x) => { | |
96 | console.log(x); | |
97 | } | |
98 | ); | |
99 | ``` | |
100 | ||
101 | Examples of **correct** code for this rule with the `"never"` option: | |
102 | ||
103 | ```js | |
104 | /*eslint function-call-argument-newline: ["error", "never"]*/ | |
105 | ||
106 | foo("one", "two", "three"); | |
107 | // or | |
108 | foo( | |
109 | "one", "two", "three" | |
110 | ); | |
111 | ||
112 | bar("one", "two", { one: 1, two: 2 }); | |
113 | // or | |
114 | bar("one", "two", { | |
115 | one: 1, | |
116 | two: 2 | |
117 | }); | |
118 | ||
119 | baz("one", "two", (x) => { | |
120 | console.log(x); | |
121 | }); | |
122 | ``` | |
123 | ||
124 | ### consistent | |
125 | ||
456be15e | 126 | Examples of **incorrect** code for this rule with the `"consistent"` option: |
eb39fafa DC |
127 | |
128 | ```js | |
129 | /*eslint function-call-argument-newline: ["error", "consistent"]*/ | |
130 | ||
131 | foo("one", "two", | |
132 | "three"); | |
133 | //or | |
134 | foo("one", | |
135 | "two", "three"); | |
136 | ||
137 | bar("one", "two", | |
138 | { one: 1, two: 2} | |
139 | ); | |
140 | ||
141 | baz("one", "two", | |
142 | (x) => { console.log(x); } | |
143 | ); | |
144 | ``` | |
145 | ||
456be15e | 146 | Examples of **correct** code for this rule with the `"consistent"` option: |
eb39fafa DC |
147 | |
148 | ```js | |
149 | /*eslint function-call-argument-newline: ["error", "consistent"]*/ | |
150 | ||
151 | foo("one", "two", "three"); | |
152 | // or | |
153 | foo( | |
154 | "one", | |
155 | "two", | |
156 | "three" | |
157 | ); | |
158 | ||
159 | bar("one", "two", { | |
160 | one: 1, | |
161 | two: 2 | |
162 | }); | |
163 | // or | |
164 | bar( | |
165 | "one", | |
166 | "two", | |
167 | { one: 1, two: 2 } | |
168 | ); | |
169 | // or | |
170 | bar( | |
171 | "one", | |
172 | "two", | |
173 | { | |
174 | one: 1, | |
175 | two: 2 | |
176 | } | |
177 | ); | |
178 | ||
179 | baz("one", "two", (x) => { | |
180 | console.log(x); | |
181 | }); | |
182 | // or | |
183 | baz( | |
184 | "one", | |
185 | "two", | |
186 | (x) => { | |
187 | console.log(x); | |
188 | } | |
189 | ); | |
190 | ``` | |
191 | ||
192 | ||
193 | ## When Not To Use It | |
194 | ||
195 | If you don't want to enforce line breaks between arguments, don't enable this rule. | |
196 | ||
197 | ## Related Rules | |
198 | ||
199 | * [function-paren-newline](function-paren-newline.md) | |
200 | * [func-call-spacing](func-call-spacing.md) | |
201 | * [object-property-newline](object-property-newline.md) | |
202 | * [array-element-newline](array-element-newline.md) |