Back to Biomejs

noBiomeFirstException

src/content/docs/linter/rules/no-biome-first-exception.mdx

latest2.2 KB
Original Source

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

<Tabs> <TabItem label="JSON (and super languages)" icon="seti:json"> ## Summary - Rule available since: `v2.2.0` - Diagnostic Category: [`lint/suspicious/noBiomeFirstException`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule has a [**safe**](/linter/#safe-fixes) fix. - The default severity of this rule is [**error**](/reference/diagnostics#error). ## How to configure ```json title="biome.json" { "linter": { "rules": { "suspicious": { "noBiomeFirstException": "error" } } } }
## Description
Prevents the misuse of glob patterns inside the `files.includes` field.

## Leading of negated patterns

If the first pattern of `files.includes` starts with the leading `!`, Biome won't have any file to crawl. Generally,
it is a good practice to declare the files/folders to include first, and then the files/folder to ignore.

Check the [official documentation](https://biomejs.dev/guides/configure-biome/#exclude-files-via-configuration) for more examples.

### Examples

#### Invalid

```json
{
    "files": {
        "includes": ["!dist"]
    }
}

Valid

json
{
    "files": {
        "includes": ["src/**", "!dist"]
    }
}

Leading with catch-all **

If the user configuration file extends from other sources (other configuration files or libraries), and those files contain the catch-all glob ** in files.includes, the rule will trigger a violation if also the user configuration file has a **.

Invalid

jsonc
// biome.json
{
    "extends": ["./base.json"],
    "files": {
        "includes": ["**", "!**/test"]
    }
}
jsonc
// base.json
{
    "files": {
        "includes": ["**", "!**/dist"]
    }
}
</TabItem> </Tabs>