Assist
Assist actions tidy up your code, for example by sorting imports or the keys of an object. Unlike lint rules, they do not look for bugs or bad practices: every action comes with a fix, and the fix is safe to apply. Biome has 13 assist actions.
Apply assist actions
Section titled “Apply assist actions”biome check reports code that an enabled action would change, and fails if it finds any. Add --write to apply the actions:
npx biome check --writepnpm biome check --writebunx biome check --writedeno run -A npm:@biomejs/biome check --writeyarn biome check --writebiome check --writeTo apply only assist actions, without formatting or linting, disable the other tools for that run:
npx biome check --write --formatter-enabled=false --linter-enabled=falsepnpm biome check --write --formatter-enabled=false --linter-enabled=falsebunx biome check --write --formatter-enabled=false --linter-enabled=falsedeno run -A npm:@biomejs/biome check --write --formatter-enabled=false --linter-enabled=falseyarn biome check --write --formatter-enabled=false --linter-enabled=falsebiome check --write --formatter-enabled=false --linter-enabled=falseTo apply assist actions when you ask for them, without failing when they have not been applied, pass --enforce-assist=false:
npx biome check --enforce-assist=falsepnpm biome check --enforce-assist=falsebunx biome check --enforce-assist=falsedeno run -A npm:@biomejs/biome check --enforce-assist=falseyarn biome check --enforce-assist=falsebiome check --enforce-assist=falseSee the CLI reference for every option of the check command.
Sort imports
Section titled “Sort imports”The most common assist action is organizeImports. It is enabled by default, and it:
- Sorts imports and exports by how “far” their source is, from URLs and packages to relative paths.
- Merges imports from the same module.
- Sorts the names inside each import.
// Beforeimport { b, a } from "./utils";import fs from "node:fs";import { c } from "./utils";import React from "react";
// Afterimport fs from "node:fs";import React from "react";import { a, b, c } from "./utils";Biome never moves an import past other code. Imports separated by another statement, or by a comment followed by a blank line, are sorted separately, but a blank line alone does not split them. To customize the order, for example to put your own packages in a separate group, see the options of organizeImports.
Configure assist actions
Section titled “Configure assist actions”Assist actions are configured under assist.actions in your biome.json file, grouped the same way they appear in the list of assist actions. All current actions belong to the source group.
Enable an action
Section titled “Enable an action”Some actions, like organizeImports, are enabled by default. Set an action to "on" to enable it:
{ "assist": { "actions": { "source": { "useSortedKeys": "on" } } }}Disable an action
Section titled “Disable an action”Set an action to "off" to disable it:
{ "assist": { "actions": { "source": { "organizeImports": "off" } } }}Action options
Section titled “Action options”Some actions accept options. To set them, replace "on" with an object that has a level and an options field:
{ "assist": { "actions": { "source": { "useSortedKeys": { "level": "on", "options": { "sortOrder": "lexicographic" } } } } }}The documentation page of each action lists the options it supports.
Apply actions differently to some files
Section titled “Apply actions differently to some files”To configure actions differently for some files, use overrides. For example, a file that loads polyfills might need its imports to stay in their original order:
{ "overrides": [ { "includes": ["src/polyfills.ts"], "assist": { "actions": { "source": { "organizeImports": "off" } } } } ]}Apply actions to only some files
Section titled “Apply actions to only some files”To skip files that you do not want changed, such as generated code, exclude them with assist.includes:
{ "assist": { "includes": ["**", "!**/generated/**"] }}The formatter and the linter still process these files. To exclude a file from every tool, use files.includes instead.
Disable assist actions
Section titled “Disable assist actions”If another tool already sorts your imports, such as an ESLint or Prettier plugin, and you want to keep it for now, disable assist actions with assist.enabled:
{ "assist": { "enabled": false }}Biome then stops applying assist actions, both in the CLI and in your editor, while the formatter and the linter keep working.
Skip an action in part of a file
Section titled “Skip an action in part of a file”If an action should not apply to some code, such as an object whose keys are in a meaningful order, add a suppression comment above it:
// biome-ignore assist/source/useSortedKeys: keys follow the visual orderconst layout = { top: 0, right: 0, bottom: 0, left: 0 };The Suppressions guide covers every way to write these comments.
Coming from other tools
Section titled “Coming from other tools”Assist actions replace the rules that sort code in other tools, such as ESLint’s sort-imports and sort-keys, or the import ordering rules of eslint-plugin-import and eslint-plugin-perfectionist. To find the action that replaces a rule you use, check the action sources.
When you switch, turn off the rule in your previous tool, so that the two tools do not reorder the same code in different ways.
© 2023-present Biome developers and contributors.