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.
Configure#
Off by default. To turn it on:
[lint.rules]
"bun/format" = "error" # or "warn"Examples#
Reported:
const user = {name:'Ada'}Not reported:
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.
[lint.rules]
"bun/format" = ["error", { singleQuote = true, semi = false }]const user = { name: 'Ada' }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.