1 # Disallow empty functions (no-empty-function)
3 Empty functions can reduce readability because readers need to guess whether it's intentional or not.
4 So writing a clear comment for empty functions is a good practice.
12 Especially, the empty block of arrow functions might be confusing developers.
13 It's very similar to an empty object literal.
16 list.map(() => {}); // This is a block, would return undefined.
17 list.map(() => ({})); // This is an empty object.
22 This rule is aimed at eliminating empty functions.
23 A function will not be considered a problem if it contains a comment.
25 Examples of **incorrect** code for this rule:
28 /*eslint no-empty-function: "error"*/
33 var foo = function() {};
39 var foo = function*() {};
72 static set foo(value) {}
76 Examples of **correct** code for this rule:
79 /*eslint no-empty-function: "error"*/
86 var foo = function() {
87 // any clear comments.
98 var foo = function*() {
161 static set foo(value) {
169 This rule has an option to allow specific kinds of functions to be empty.
171 * `allow` (`string[]`) - A list of kind to allow empty functions. List items are some of the following strings. An empty array (`[]`) by default.
172 * `"functions"` - Normal functions.
173 * `"arrowFunctions"` - Arrow functions.
174 * `"generatorFunctions"` - Generator functions.
175 * `"methods"` - Class methods and method shorthands of object literals.
176 * `"generatorMethods"` - Class methods and method shorthands of object literals with generator.
177 * `"getters"` - Getters.
178 * `"setters"` - Setters.
179 * `"constructors"` - Class constructors.
180 * `"asyncFunctions"` - Async functions.
181 * `"asyncMethods"` - Async class methods and method shorthands of object literals.
185 Examples of **correct** code for the `{ "allow": ["functions"] }` option:
188 /*eslint no-empty-function: ["error", { "allow": ["functions"] }]*/
192 var foo = function() {};
199 ### allow: arrowFunctions
201 Examples of **correct** code for the `{ "allow": ["arrowFunctions"] }` option:
204 /*eslint no-empty-function: ["error", { "allow": ["arrowFunctions"] }]*/
210 ### allow: generatorFunctions
212 Examples of **correct** code for the `{ "allow": ["generatorFunctions"] }` option:
215 /*eslint no-empty-function: ["error", { "allow": ["generatorFunctions"] }]*/
220 var foo = function*() {};
229 Examples of **correct** code for the `{ "allow": ["methods"] }` option:
232 /*eslint no-empty-function: ["error", { "allow": ["methods"] }]*/
245 ### allow: generatorMethods
247 Examples of **correct** code for the `{ "allow": ["generatorMethods"] }` option:
250 /*eslint no-empty-function: ["error", { "allow": ["generatorMethods"] }]*/
265 Examples of **correct** code for the `{ "allow": ["getters"] }` option:
268 /*eslint no-empty-function: ["error", { "allow": ["getters"] }]*/
283 Examples of **correct** code for the `{ "allow": ["setters"] }` option:
286 /*eslint no-empty-function: ["error", { "allow": ["setters"] }]*/
295 static set foo(value) {}
299 ### allow: constructors
301 Examples of **correct** code for the `{ "allow": ["constructors"] }` option:
304 /*eslint no-empty-function: ["error", { "allow": ["constructors"] }]*/
312 ### allow: asyncFunctions
314 Examples of **correct** code for the `{ "allow": ["asyncFunctions"] }` options:
317 /*eslint no-empty-function: ["error", { "allow": ["asyncFunctions"] }]*/
318 /*eslint-env es2017*/
323 ### allow: asyncMethods
325 Examples of **correct** code for the `{ "allow": ["asyncMethods"] }` options:
328 /*eslint no-empty-function: ["error", { "allow": ["asyncMethods"] }]*/
329 /*eslint-env es2017*/
337 static async foo() {}
341 ## When Not To Use It
343 If you don't want to be notified about empty functions, then it's safe to disable this rule.
347 * [no-empty](./no-empty.md)