Back to Biomejs

Getting Started

src/content/docs/guides/getting-started.mdx

latest5.9 KB
Original Source

title: Getting Started description: Learn how to set up a new project with Biome.

import { Code, TabItem, Tabs } from "@astrojs/starlight/components"; import DefaultConfiguration from "@/components/generated/DefaultConfiguration.mdx"; import PackageManagerBiomeCommand from "@/components/PackageManagerBiomeCommand.astro"; import PackageManagerCommand from "@/components/PackageManagerCommand.astro";

Biome is best installed as a development dependency of your projects, but it is also available as a standalone executable that doesn't require Node.js.

<PackageManagerCommand npm="i -D -E @biomejs/biome" pnpm="add -D -E @biomejs/biome" yarn="add -D -E @biomejs/biome" bun="add -D -E @biomejs/biome" deno="add -D npm:@biomejs/biome" />

:::note[Version pinning] -E ensures that the package manager pins the version of Biome. See the versioning page for more information about why pinning the version is important. :::

Configuration

Although Biome can run with zero configuration, you'll likely want to tweak some settings to suit your project's needs, in which case you can run the following command to generate a biome.json configuration file.

<PackageManagerBiomeCommand command="init"/>

Usage

Lets get a quick overview of how to use Biome in your project.

Command-line interface

Biome provides a command-line interface to format, lint, and check your code.

<Tabs syncKey="command"> <TabItem label="npm" icon="seti:npm"> <Code frame="none" code={` # Format all files npx @biomejs/biome format --write

Format specific files

npx @biomejs/biome format --write <files>

Lint files and apply safe fixes to all files

npx @biomejs/biome lint --write

Lint files and apply safe fixes to specific files

npx @biomejs/biome lint --write <files>

Format, lint, and organize imports of all files

npx @biomejs/biome check --write

Format, lint, and organize imports of specific files

npx @biomejs/biome check --write <files> } lang="bash" /> </TabItem> <TabItem label="pnpm" icon="pnpm"> <Code frame="none" code={

Format all files

pnpx @biomejs/biome format --write

Format specific files

pnpx @biomejs/biome format --write <files>

Lint and apply safe fixes to all files

pnpx @biomejs/biome lint --write

Lint files and apply safe fixes to specific files

pnpx @biomejs/biome lint --write <files>

Format, lint, and organize imports of all files

pnpx @biomejs/biome check --write

Format, lint, and organize imports of specific files

pnpx @biomejs/biome check --write <files> } lang="bash" /> </TabItem> <TabItem label="bun" icon="bun"> <Code frame="none" code={

Format all files

bunx --bun @biomejs/biome format --write

Format specific files

bunx --bun @biomejs/biome format --write <files>

Lint and apply safe fixes to all files

bunx --bun @biomejs/biome lint --write

Lint files and apply safe fixes to specific files

bunx --bun @biomejs/biome lint --write <files>

Format, lint, and organize imports of all files

bunx --bun @biomejs/biome check --write

Format, lint, and organize imports of specific files

bunx --bun @biomejs/biome check --write <files> } lang="bash" /> </TabItem> <TabItem label="deno" icon="deno"> <Code frame="none" code={

Format specific files

deno run -A npm:@biomejs/biome format --write <files>

Format all files

deno run -A npm:@biomejs/biome format --write

Lint files and apply safe fixes to all files

deno run -A npm:@biomejs/biome lint --write

Lint files and apply safe fixes to specific files

deno run -A npm:@biomejs/biome lint --write <files>

Format, lint, and organize imports of all files

deno run -A npm:@biomejs/biome check --write

Format, lint, and organize imports of specific files

deno run -A npm:@biomejs/biome check --write <files> } lang="bash" /> </TabItem> <TabItem label="yarn" icon="seti:yarn"> <Code frame="none" code={

Format all files

yarn exec biome format --write

Format specific files

yarn exec biome format --write <files>

Lint files and apply safe fixes to all files

yarn exec biome lint --write

Lint files and apply safe fixes to specific files

yarn exec biome lint --write <files>

Format, lint, and organize imports of all files

yarn exec biome check --write

Format, lint, and organize imports of specific files

yarn exec biome check --write <files> `} lang="bash" /> </TabItem> </Tabs>

Editor integrations

Biome is available as a first-party extension in your favorite editors.

There are also community extensions for other editors, such as Vim, Neovim, and Sublime Text, to name a few.

Continuous Integration

Run biome ci as part of your CI pipeline to enforce code quality and consistency across your team. It works just like the biome check command, but is optimized for CI environments.

See the Continuous Integration recipes for more examples.

Next Steps

Success! You're now ready to use Biome. 🥳