1.1.0 • Published 11 months ago

eslint-plugin-arrowsmith v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

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:

/* 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:

/* 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.

1.1.0

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago