# bun/format

> Require code to be formatted the way `bun fmt` prints it

This rule compares each file with what `bun fmt` prints and reports every place where they differ. Formatting problems then show up next to your lint problems, in the terminal and in the editor.

It reads the same settings as `bun fmt`: your `.prettierrc`, `.editorconfig`, and the `[fmt]` section of `bunfig.toml`. It skips the files that `bun fmt` skips. The options and the messages are the same as for `prettier/prettier`, and you don't need Prettier installed.

If Bun can't format a file the way your config asks, for example because of a Prettier plugin that `bun fmt` doesn't have, the file gets one report that says why.

`--fix` formats the file.

{/* 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]
"bun/format" = "error" # or "warn"
```

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

## Examples

Reported:

{/* bad */}
```js
const user = {name:'Ada'}
```

Not reported:

{/* good */}
```js
const user = { name: "Ada" };
```

## Options

The first option is an object of formatting options, using the same names as in a `.prettierrc`. They override your config files.

```toml bunfig.toml
[lint.rules]
"bun/format" = ["error", { singleQuote = true, semi = false }]
```

{/* good {"options": [{"singleQuote": true, "semi": false}]} */}
```js
const user = { name: 'Ada' }
```

{/* bad {"options": [{"singleQuote": true, "semi": false}]} */}
```js
const user = { name: "Ada" };
```

The second option is an object with these keys:

| Option | Default | What it does |
| --- | --- | --- |
| `usePrettierrc` | `true` | Read config files such as `.prettierrc` and `.editorconfig`. |
| `fileInfoOptions` | `{}` | `ignorePath` names the ignore file or files to read. `withNodeModules: true` also checks files in `node_modules`. |

## When not to use it

If `bun fmt --check` already runs in CI, this rule does the same work a second time.
