DEV Community

Alex Spinov
Alex Spinov

Posted on

Biome Has a Free API That Replaces ESLint and Prettier in One Tool

Biome is a blazing-fast formatter and linter written in Rust. It replaces both ESLint and Prettier — and runs 35x faster.

Setup: Zero Config

npx @biomejs/biome init
Enter fullscreen mode Exit fullscreen mode

This creates biome.json:

{
  "$schema": "https://biomejs.dev/schemas/1.9.0/schema.json",
  "organizeImports": { "enabled": true },
  "linter": {
    "enabled": true,
    "rules": { "recommended": true }
  },
  "formatter": {
    "enabled": true,
    "indentStyle": "space",
    "indentWidth": 2
  }
}
Enter fullscreen mode Exit fullscreen mode

Format: 35x Faster Than Prettier

# Format files
biome format --write src/

# Check without writing
biome format src/

# Format specific files
biome format --write src/index.ts src/utils.ts
Enter fullscreen mode Exit fullscreen mode

Biome formats JavaScript, TypeScript, JSX, TSX, JSON, CSS, and GraphQL.

Lint: 300+ Rules

# Lint with auto-fix
biome lint --write src/

# Check only
biome check src/

# Both format + lint
biome check --write src/
Enter fullscreen mode Exit fullscreen mode

Configuration: Fine-Grained Control

{
  "linter": {
    "rules": {
      "suspicious": {
        "noExplicitAny": "error",
        "noDoubleEquals": "error"
      },
      "complexity": {
        "noForEach": "warn",
        "useFlatMap": "error"
      },
      "style": {
        "useConst": "error",
        "noNonNullAssertion": "warn"
      },
      "correctness": {
        "noUnusedVariables": "error",
        "noUnusedImports": "error"
      },
      "nursery": {
        "useSortedClasses": "warn"
      }
    }
  },
  "formatter": {
    "lineWidth": 100,
    "indentStyle": "tab"
  },
  "javascript": {
    "formatter": {
      "quoteStyle": "single",
      "semicolons": "asNeeded",
      "trailingCommas": "all"
    }
  },
  "json": {
    "formatter": {
      "trailingCommas": "none"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Import Sorting: Built-In

// Before
import { useState } from "react";
import axios from "axios";
import { Button } from "./components";
import type { User } from "./types";
import path from "node:path";

// After biome check --write
import path from "node:path";
import { useState } from "react";
import axios from "axios";
import { Button } from "./components";
import type { User } from "./types";
Enter fullscreen mode Exit fullscreen mode

VS Code Integration

// .vscode/settings.json
{
  "editor.defaultFormatter": "biomejs.biome",
  "editor.formatOnSave": true,
  "editor.codeActionsOnSave": {
    "source.organizeImports.biome": "explicit",
    "quickfix.biome": "explicit"
  }
}
Enter fullscreen mode Exit fullscreen mode

Per-File Overrides

{
  "overrides": [
    {
      "include": ["*.test.ts", "*.spec.ts"],
      "linter": {
        "rules": {
          "suspicious": { "noExplicitAny": "off" }
        }
      }
    },
    {
      "include": ["scripts/**"],
      "formatter": { "lineWidth": 120 }
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Benchmarks

Tool Format 1000 files
Biome 0.3s
Prettier 11s
ESLint + Prettier 15s

Clean code for scraping projects? My Apify tools follow strict code quality standards.

Custom tooling setup? Email spinov001@gmail.com

Top comments (0)