Formatter
Цей контент ще не доступний вашою мовою.
Biome formats your code so that it looks the same no matter who wrote it. It works for every supported language, and its output is compatible with Prettier, so switching does not reformat your whole codebase.
Format your files
Section titled “Format your files”Run the format command to see which files are not formatted. Biome prints the difference between your code and the formatted output, without changing anything:
npx biome formatpnpm biome formatbunx biome formatdeno run -A npm:@biomejs/biome formatyarn biome formatbiome formatAdd --write to format the files in place:
npx biome format --writepnpm biome format --writebunx biome format --writedeno run -A npm:@biomejs/biome format --writeyarn biome format --writebiome format --writeYou can pass files and folders to format only part of your project, such as biome format --write ./src. To choose files with glob patterns, use formatter.includes instead, because your shell expands the globs you pass.
To format, lint, and sort imports in a single pass, use biome check instead.
See the CLI reference for every option of the format command.
Configure the formatter
Section titled “Configure the formatter”Biome works without configuration. Its defaults indent with tabs, wrap lines at 80 characters, and use double quotes in JavaScript.
To change them, add the options to your biome.json file. The editor extension and the CLI both read this file, so everyone on your team gets the same output:
{ "formatter": { "indentStyle": "space", "indentWidth": 2, "lineWidth": 100 }}Options under formatter apply to every language. Each language also has its own section, which overrides the general options for files in that language:
{ "formatter": { "indentStyle": "space" }, "javascript": { "formatter": { "quoteStyle": "single", "semicolons": "asNeeded" } }, "json": { "formatter": { "indentWidth": 4 } }}The most common options are:
indentStyle: indent with"tab"(default) or"space".indentWidth: the width of each indentation level. The default is2.lineWidth: the column at which Biome wraps code. The default is80.quoteStyle: use"double"(default) or"single"quotes in JavaScript and TypeScript.
The configuration reference lists every option and its default value.
Use your .editorconfig file
Section titled “Use your .editorconfig file”If your project already has an .editorconfig file, Biome can read its indentation and line settings. Enable it with useEditorconfig:
{ "formatter": { "useEditorconfig": true }}Settings in biome.json always take precedence over the ones in .editorconfig.
Format some files differently
Section titled “Format some files differently”To use different formatting options for some files, use overrides. For example, a legacy/ folder might keep the indentation it was written with:
{ "overrides": [ { "includes": ["legacy/**"], "formatter": { "indentStyle": "space", "indentWidth": 4 } } ]}Format only some files
Section titled “Format only some files”To skip files that you do not want formatted, such as generated code, exclude them with formatter.includes:
{ "formatter": { "includes": ["**", "!**/generated/**"] }}The linter and the other tools still process these files. To exclude a file from every tool, use files.includes instead.
Disable the formatter
Section titled “Disable the formatter”If you want to keep another formatter for now, such as Prettier, and only use Biome for linting, disable Biome’s formatter with formatter.enabled:
{ "formatter": { "enabled": false }}Biome then stops formatting your files, both in the CLI and in your editor, while the linter and assist actions keep working.
Keep part of a file as is
Section titled “Keep part of a file as is”Sometimes you have code that reads better with your own layout, like a matrix of numbers. Add a biome-ignore format comment above it, with a reason, and Biome leaves it untouched:
const matrix = // biome-ignore format: keep the matrix readable [ 1, 0, 0, 0, 1, 0, 0, 0, 1, ];To skip a whole file, put // biome-ignore-all format: <reason> at the very top of it. The Suppressions guide covers every way to write these comments.
Why Biome has few options
Section titled “Why Biome has few options”Biome is an opinionated formatter. Instead of asking your team to agree on dozens of style settings, it makes those decisions for you, so code reviews can focus on what the code does rather than how it looks.
Biome follows the same option philosophy as Prettier. The Biome team considers the set of options stable, and is unlikely to accept requests for new options.
Some options, such as bracketSameLine and arrowParentheses, exist only to match Prettier and make migrating easier. The Biome team treats them as legacy features, not as a reason to add more.
The formatting style itself can still improve over time, but changes apply to everyone rather than becoming new options.
Coming from Prettier
Section titled “Coming from Prettier”Biome’s formatter matches Prettier’s output in about 97% of cases, and the remaining differences are intentional. To convert your Prettier configuration file into a biome.json file, follow the migration guide. To see what output differs and why, read the formatting differences.
© 2023-present Biome developers and contributors.