Back to Biomejs

useRequiredScripts

src/content/docs/linter/rules/use-required-scripts.mdx

latest2.0 KB
Original Source

import { Tabs, TabItem } from '@astrojs/starlight/components';

<Tabs> <TabItem label="JSON (and super languages)" icon="seti:json"> :::caution This rule is part of the [nursery](/linter/#nursery) group. This means that it is experimental and the behavior can change at any time. ::: ## Summary - Rule available since: `v2.3.9` - Diagnostic Category: [`lint/nursery/useRequiredScripts`](/reference/diagnostics#diagnostic-category) - This rule doesn't have a fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). ## How to configure ```json title="biome.json" { "linter": { "rules": { "nursery": { "useRequiredScripts": "error" } } } }
## Description
Enforce the presence of required scripts in package.json.

This rule ensures that specified scripts are defined in the `scripts` section of a `package.json` file.
It's particularly useful in monorepo environments where consistency across workspaces is important.

Without required scripts configured, this rule doesn't do anything.

## Examples

### Invalid

```json title='biome.json'
{
	"linter": {
		"rules": {
			"nursery": {
				"useRequiredScripts": {
					"options": {
						"requiredScripts": [
							"test",
							"build"
						]
					}
				}
			}
		}
	}
}

json
{
    "scripts": {
        "test": "vitest"
    }
}

Valid

json
{
    "scripts": {
        "test": "vitest",
        "build": "tsc"
    }
}

Options

requiredScripts

An array of script names that must be present in the scripts section of package.json. Default: [] (no scripts required)

</TabItem> </Tabs>