Aller au contenu

Use Biome in big projects

Ce contenu n’est pas encore disponible dans votre langue.

Biome can provide some tools that can help you to use it properly in big projects, such as monorepo or workspaces that contain multiple projects.

Use multiple configuration files

Section titled Use multiple configuration files

When you use Biome’s features - either with the CLI or LSP - the tool looks for the nearest configuration file using the current working directory.

If Biome doesn’t find the configuration file there, it starts walking upwards the directories of the file system, until it finds one.

You can leverage this feature to apply different settings based on the project/folder.

Let’s suppose we have a project that contains a backend app and new frontend app.

  • Répertoireapp
    • Répertoirebackend
      • biome.json
      • package.json
    • Répertoirefrontend
      • biome.json
      • Répertoirelegacy-app
        • package.json
      • Répertoirenew-app
        • package.json

This means that when you run a script from the file app/backend/package.json, Biome will use the configuration file app/backend/biome.json.

When you run a script from app/frontend/legacy-app/package.json or app/frontend/new-app/package.json, Biome will use the configuration file app/frontend/biome.json.

It’s possible to use the extends configuration option to breakdown options across files.

Let’s assume that we have these requirements:

  • legacy-app have to format using spaces;
  • backend and new-app have to format using tabs;
  • all apps have to format using line width 120;
  • backend app needs some extra linting;

We start by creating a new configuration file at app/biome.json, and put there the shared options:

app/biome.json
{
"formatter": {
"enabled": true,
"lineWidth": 120
}
}

Now let’s move app/frontend/biome.json to app/frontend/legacy-app/, because that’s where we need to use a different formatting.

app/frontend/legacy-app/biome.json
{
"formatter": {
"indentStyle": "space"
}
}

Then, we tell Biome to inherit all the options from the main app/biome.json file, using the extends property:

app/frontend/legacy-app/biome.json
{
"extends": ["../../biome.json"],
"formatter": {
"indentStyle": "space"
}
}

Let’s jump to app/backend/biome.json, where we need to enable the linting:

app/backend/biome.json
{
"extends": ["../biome.json"],
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
}
}

Monorepos are particular repositories where multiple libraries are stored and maintained in one big repository. Each library represents a self-contained project, which can contain different configurations.

Biome doesn’t support monorepos very well due to some limitations in resolving nested configuration files, you help and follow the relative issue.

In order to have the best developer experience despite the current limitation, it’s advised to have a biome.json at the root of the monorepo, and use the overrides configuration to change the behaviour of Biome in certain packages.

In the following example we disable the rule suspicious/noConsoleLog inside the package packages/logger.

biome.jsonc
{
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
},
"overrides": [{
"include": ["packages/logger/**"],
"linter": {
"rules": {
"suspicious": {
"noConsoleLog": "off"
}
}
}
}]
}