Biome Toolchain

repository·main·Indexed 12 days ago

https://github.com/biomejs/biome

A high-performance toolchain for web projects providing unified formatting and linting for JavaScript, TypeScript, JSX, JSON, CSS, and GraphQL. Biome includes a CLI, a Language Server Protocol (LSP) interface for IDE integration, and a fault-tolerant deserialization framework designed for textual data.

Tokens
85.4K
Snippets
294
Records
430
Agent score
96%

What's inside Biome

  1. Overview of Biome toolchain

    main

    Biome is a high-performance toolchain for web projects designed to maintain project health. It provides:

    • Fast Formatter: Supports JavaScript, TypeScript, JSX, JSON, CSS, and GraphQL with ~97% compatibility with Prettier.
    • High-performance Linter: Supports JavaScript, TypeScript, JSX, CSS, and GraphQL with over 500 rules (including those from ESLint and typescript-eslint).
    • Editor Integration: Designed for interactive use with first-party extensions and excellent LSP support.

    Key characteristics:

    • No Node.js required: Biome can run without a Node.js runtime.
    • Unified Core: Uses a shared foundation for parsing, error reporting, parallel execution, caching, and configuration, combining functionality that previously required separate tools.
  2. What is Biome?

    main

    Biome is a high-performance web toolchain designed to maintain the health of web projects. It serves two primary roles:

    1. Fast Formatter: A formatter for JavaScript, TypeScript, JSX, JSON, CSS, and GraphQL, offering approximately 97% compatibility with Prettier.
    2. Efficient Linter: A linter for the same languages, featuring over 500 rules sourced from ESLint, typescript-eslint, and other providers. It provides detailed, contextual diagnostics to improve code quality.

    Key characteristics:

    • Editor Integration: Designed for interactive use in editors via LSP and first-party extensions.
    • Unified Toolchain: Combines previously separate tools into a single engine, providing a consistent experience for parsing, error recovery, caching, and configuration.
    • No Node.js Required: Biome does not require a Node.js runtime to function.
    • High Performance: Built for speed and high-quality error recovery.
  3. What is biome_cli?

    main
    The biome_cli crate provides the main binary distribution for Biome. It exposes the command line interface (CLI) and the language server protocol (LSP) interface. The LSP interface is used by the biome VSCode extension to provide IDE features like linting and formatting.
  4. How to use `// eslint-disable-next-line` with Biome

    main

    While Biome is a separate tool, it respects // eslint-disable-next-line comments in certain contexts, often appearing alongside // prettier-ignore in codebases that use both tools. However, Biome's primary mechanism for ignoring code is its own ignore comments.

    function HelloWorld(x) {
      // prettier-ignore
      // eslint-disable-next-line
      (x.a |
        x.b).call(null);
    }
  5. Use suppression comments in Biome

    main

    Biome supports suppression comments to ignore specific linting or formatting rules.

    • Recommended: Use // biome-ignore.
    • Deprecated: // rome-ignore is deprecated and should be replaced with the Biome syntax.
    // biome-ignore <rule-name>
    const x = 1;
  6. Formatting Explicit Resource Management (using/await using)

    main

    Biome supports the ES2024 Explicit Resource Management syntax (using and await using).

    Note that in some cases, such as when using escaped identifiers or specific comment placements, Biome's formatting may differ from Prettier. For example, Biome may escape certain characters in identifiers to ensure consistency:

    // Biome might transform this:
    await using ab = c;
    // To this:
    await using \u0061b = c;
    async function f() {
      await using \u0061b = c;
    }
  7. Use `overrides` to customize tool behavior for specific paths

    main

    The overrides option allows you to modify the behavior of the formatter, linter, or other tools for specific file patterns using the include key.

    Important: When both include and ignore are specified in a configuration, ignore takes precedence over include.

    {
      "formatter": {
        "lineWidth": 100
      },
      "overrides": [
        {
          "include": ["generated/**"],
          "formatter": {
            "lineWidth": 160
          },
          "javascript": {
            "formatter": {
              "quoteStyle": "single"
            }
          }
        },
        {
          "include": ["lib/**"],
          "linter": {
            "rules": {
              "suspicious": {
                "noDebugger": "off"
              }
            }
          }
        }
      ]
    }
  8. Formatting Loop Control Statements with Comments

    main

    Biome handles comments following continue and break statements within for loops. In certain edge cases involving labels and comments, Biome may reformat the structure to ensure the comment is correctly associated with the statement, sometimes moving the comment to a new line or adjusting the semicolon placement.

    label1: for (;;) continue label1; // comment
  9. How end-to-end tests work in Biome

    main

    End-to-end (e2e) tests in Biome are implemented as individual directories within the e2e-tests directory. Each directory represents a unique project configuration using Biome.

    To define a test, every directory must contain a shell script named test.sh. The test's success or failure is determined solely by the exit status of this script. The execution environment automatically sets the working directory to the directory containing the test.sh file.

    # Example test.sh content
    set -eu
    
    cargo run --bin biome -- lint src
  10. Linter rule behavior: useLiteralKeys and quoteProperties

    main

    The useLiteralKeys rule has been updated (in v1.8.1 and v1.8.2) to avoid conflicts with the formatter's quoteProperties option. The rule now ignores quoted member names that can be unquoted, preventing it from suggesting changes that contradict your formatting configuration.

    // The rule no longer reports these as needing changes if they can be unquoted
    const x = { "prop": 0 };