• If the function body consists of a single statement returning an expression without side effects, omit the braces and use the implicit return. Otherwise, keep the braces and use a return statement. eslint: , arrow-body-style

    // good
    [1, 2, 3].map(number => A string containing the ${number}.);

    // good
    [1, 2, 3].map((number) => {
    const nextNumber = number + 1;
    return A string containing the ${nextNumber}.;
    });

    // good
    [1, 2, 3].map((number, index) => ({

  1. [index]: number,
  2. }));
  3. // No implicit return with side effects
  4. function foo(callback) {
  5. const val = callback();
  6. if (val === true) {
  7. // Do something if callback returns true
  8. }
  9. }
  10. let bool = false;
  11. // bad
  12. // good
  13. foo(() => {
  14. });
  15. ```

  • In case the expression spans over multiple lines, wrap it in parentheses for better readability.

  • 8.4 If your function takes a single argument and doesn’t use braces, omit the parentheses. Otherwise, always include parentheses around arguments for clarity and consistency. Note: it is also acceptable to always use parentheses, in which case use the for eslint. eslint: arrow-parens

    1. // bad
    2. [1, 2, 3].map((x) => x * x);
    3. // good
    4. [1, 2, 3].map(x => x * x);
    5. // good
    6. [1, 2, 3].map(number => (
    7. `A long string with the ${number}. Its so long that we dont want it to take up space on the .map line!`
    8. ));
    9. // bad
    10. [1, 2, 3].map(x => {
    11. const y = x + 1;
    12. return x * y;
    13. // good
    14. [1, 2, 3].map((x) => {
    15. const y = x + 1;
    16. return x * y;
    17. });

  • Avoid confusing arrow function syntax (=>) with comparison operators (<=, >=). eslint: no-confusing-arrow

  • 8.6 Enforce the location of arrow function bodies with implicit returns. eslint:

    1. // bad
    2. (foo) =>
    3. bar;
    4. (foo) =>
    5. (bar);
    6. // good
    7. (foo) => bar;
    8. (foo) => (bar);
    9. (foo) => (
    10. )