logo hsb.horse
← Back to snippets index

Snippets

Biome npm-scripts Configuration

Common patterns for npm-scripts when setting up Biome. Run lint and format using the check command.

Published: Updated:

This is the pattern for npm-scripts that you almost always set up when introducing Biome into a project. It handles both lint and format uniformly using the biome check command.

Basic Configuration

{
"scripts": {
"lint": "biome check .",
"format": "biome check . --write"
}
}

Grouping with Prefixes

In projects with many npm-scripts, grouping with prefixes makes organization easier.

{
"scripts": {
"code:lint": "biome check .",
"code:format": "biome check . --write"
}
}

Command Differences

CommandBehavior
biome check .Detects issues and reports them, exit code is non-zero on error
biome check . —writeFixes auto-fixable issues
biome format .Runs formatting only
biome lint .Runs linting only

check runs both lint and format. It’s common to use check . in CI and --write during development.

CI Usage Example

Example configuration in GitHub Actions:

- name: Check code
run: npm run lint
- name: Check formatting
run: npx biome format . --check

Or use check --changed to validate only changed files:

{
"scripts": {
"lint:changed": "biome check --changed ."
}
}

This allows you to target only the diff and reduce processing time.

Relationship with Configuration Files

Configure details in biome.json:

{
"formatter": {
"indentStyle": "space",
"indentWidth": 2
},
"linter": {
"enabled": true,
"rules": {
"recommended": true
}
}
}

It’s best to keep npm-scripts simple as entry points and delegate detailed configuration to the configuration file.