UNPKG

eslint-plugin-arrowsmith

Version:

Disallow arrow functions with block parentheses where they are not needed.

59 lines (36 loc) 1.36 kB
Arrow functions with a block body containing only a single return statement or a single expression statement can be simplified by removing the braces and, in the case of a return statement, the return keyword. This simplification can improve code readability. ### Rule Details This rule aims to report and fix arrow functions that can have their block body simplified. Examples of **incorrect** code for this rule: ```js /* eslint no-useless-arrow-block: "error" */ const foo = () => { return 5; }; const bar = (x) => { return x * 2; }; const baz = () => { console.log('Hello'); }; const qux = (a, b) => { return a + b; }; ``` Examples of **correct** code for this rule: ```js /* eslint no-useless-arrow-block: "error" */ const foo = () => 5; const bar = (x) => x * 2; const baz = () => console.log('Hello'); const qux = (a, b) => a + b; const complex = () => { doSomething(); return result; }; const multiLine = () => ( veryLongExpression + thatNeedsToBeWrapped ); class MyClass { static myMethod = () => { this.doSomething(); }; } ``` ### When Not To Use It If you prefer consistency in all arrow function bodies using blocks, you can disable this rule. Also, if you use arrow functions with a single statement that you prefer to keep in block form for potential future expansion, you might want to disable this rule.