Pular para o conteúdo

Use in big projects

Este conteúdo não está disponível em sua língua ainda.

In big projects, such as monorepos or workspaces that contain multiple projects, each project often needs its own settings. Biome lets you use a configuration file per project, extend the root configuration, and share configuration files between folders.

Biome uses the nearest biome.json file. It starts in the folder you run it from and moves up through the parent folders until it finds one.

You can use this behavior to apply different settings to each project or folder. For example, take a project that contains a backend app and a frontend app:

  • Directoryapp
    • Directorybackend
      • biome.json
      • package.json
    • Directoryfrontend
      • biome.json
      • Directorylegacy-app
        • package.json
      • Directorynew-app
        • package.json

When you run Biome inside app/backend, Biome uses the configuration file app/backend/biome.json. When you run it from app/frontend/legacy-app or app/frontend/new-app, Biome uses the configuration file app/frontend/biome.json.

A monorepo is a repository that stores and maintains multiple packages. Each package can contain its own configuration.

Biome supports monorepos out of the box. The following steps set up a monorepo with three packages:

  • biome.json
  • Directorypackages
    • Directoryanalytics
      • biome.json
    • Directorygenerate
      • biome.json
    • Directorylogger
      • biome.json
  1. Create a biome.json file at the root of the monorepo. This one enables the recommended rules and customizes the formatter options:

    biome.json
    {
    "linter": {
    "enabled": true,
    "rules": {
    "preset": "recommended"
    }
    },
    "formatter": {
    "lineWidth": 120,
    "indentStyle": "space",
    "indentWidth": 4
    }
    }

    This file is the root configuration, and it sets the base options of the project. Nested configurations can choose whether to follow these options.

  2. Create a nested configuration file in each package that needs one. A nested configuration file must set the "root" field to false.

    To make a package follow the standards of the root configuration, use "extends": "//". It tells Biome to extend the root configuration, wherever the nested configuration is.

    The following files configure two packages. packages/logger disables noConsole, and packages/generate disables the formatter, because its files are generated:

    packages/logger/biome.json
    {
    "root": false,
    "extends": "//",
    "linter": {
    "rules": {
    "suspicious": {
    "noConsole": "off"
    }
    }
    }
    }
    packages/generate/biome.json
    {
    "root": false,
    "extends": "//",
    "formatter": {
    "enabled": false
    }
    }

    When you use "extends": "//", you can omit "root": false, because "//" already implies that the configuration is not a root configuration:

    packages/generate/biome.json
    {
    "root": false,
    "extends": "//",
    "formatter": {
    "enabled": false
    }
    }
  3. Configure a package that must not inherit the root options. In this example, a different team maintains packages/analytics and follows entirely different coding standards. Its configuration omits "extends": "//" and sets its own formatting options:

    packages/analytics/biome.json
    {
    "root": false,
    "formatter": {
    "lineWidth": 100
    }
    }
  4. Run biome commands from the root of the project or from a single package. Biome applies the settings of every configuration file in both cases.

The extends field splits your configuration across multiple files, so you can share common settings across different projects or folders. "extends": "//" is a shortcut to extend the root configuration from a nested configuration. For other setups, extends also accepts an array, where every value is the path to another configuration to extend.

For example, this configuration extends a common.json configuration file:

biome.json
{
"extends": ["./common.json"]
}

Biome resolves the entries of extends from the path of the biome.json file. It processes them in the order they are listed, and settings in later files override earlier ones.

Files that you extend can also extend other files.

Relative paths in a shared configuration are resolved from the directory containing the configuration that extends it, not from the directory containing the shared file. Plugin paths follow the same rule by default.

To load a plugin that ships with a shared configuration, see Load a plugin from a shared configuration.

For example, take a project with two directories, backend/ and frontend/. Each has its own biome.json, and both extend a common.json configuration in the root folder:

  • Directorybackend/
    • Directorysrc/
      • …
    • Directorytest/
      • …
    • biome.json
  • Directoryfrontend/
    • Directorysrc/
      • …
    • Directorytest/
      • …
    • biome.json
  • common.json
common.json
{
"files": {
"includes": ["src/**/*.js", "test/**/*.js"]
},
"linter": {
"includes": ["**", "!test/**"]
}
}
frontend/biome.json
{
"extends": ["../common.json"]
}
  • When you run Biome from the frontend/ folder, it formats all JavaScript files in the frontend/src/ and frontend/test/ folders, and only lints the files in the frontend/src/ folder. This works because Biome interprets the paths in common.json from the frontend/ folder, where the biome.json file is.
  • If backend/biome.json has the same content as frontend/biome.json, Biome behaves the same way, except that it interprets the paths from the backend/ folder.

In this setup, both frontend/biome.json and backend/biome.json are root configurations. You cannot run Biome from the root of the repository, unless you use the --config-path CLI option and point it at one of the configurations.

To share your configuration file across multiple projects, publish it as an npm package.