# arrow-body-style

> Enforce one style for the braces around arrow function bodies

`x => x * 2` and `x => { return x * 2; }` do the same thing. By default, this rule reports the braces when the body is nothing but one `return`, so short functions stay short.

`--fix` removes or adds the braces and the `return`.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"arrow-body-style" = "error" # or "warn"
```

Every option, set to its default. The ones that are commented out are unset by default.

```toml bunfig.toml
[lint.rules]
"arrow-body-style" = [
  "error",
  "as-needed", # "always", "never" or "as-needed"
  {
    # requireReturnForObjectLiteral = <true or false>,
  },
]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```js
const double = items.map(item => {
  return item * 2;
});
```

Not reported:

{/* good */}
```js
const double = items.map(item => item * 2);

const logged = items.map(item => {
  console.log(item);
  return item * 2;
});
```

## Options

```toml bunfig.toml
[lint.rules]
arrow-body-style = ["error", "always"]
```

| Option | What it does |
| --- | --- |
| `"as-needed"` (default) | Report braces around a body that's only a `return`. |
| `"always"` | Report every arrow function without braces. |
| `"never"` | Report every arrow function with braces, no matter what's in them. `--fix` only rewrites a body that's a single `return`. |

{/* bad {"options": ["always"]} */}
```js
const double = items.map(item => item * 2);
```

{/* bad {"options": ["never"]} */}
```js
const logged = items.map(item => {
  console.log(item);
  return item * 2;
});
```

With `"as-needed"`, a second option `{ "requireReturnForObjectLiteral": true }` (default `false`) requires braces and a `return` when the function returns an object literal, instead of `=> ({ ... })`.

{/* bad {"options": ["as-needed", {"requireReturnForObjectLiteral": true}]} */}
```js
const toPoint = item => ({ x: item.left, y: item.top });
```

{/* good {"options": ["as-needed", {"requireReturnForObjectLiteral": true}]} */}
```js
const toPoint = item => {
  return { x: item.left, y: item.top };
};
```
