# 📦 eslint-plugin

[ESLint](https://eslint.org/) is a tool that statically analyzes your code and reports problems or suggests best practices through editor hints and command line. Docusaurus provides an ESLint plugin to enforce best Docusaurus practices.

This ESLint plugin supports ESLint `>= 8.57.0`, flat configs and legacy configs.

## Installation

```bash npm2yarn
npm install --save-dev @docusaurus/eslint-plugin
```

## Supported configs

Both built-in configs exist in flat and legacy variants:

- Recommended: recommended rule set for most Docusaurus sites that should be extended from.
- All: **all** rules enabled. This will change between minor versions, so you should not use this if you want to avoid unexpected breaking changes.

## Supported rules

| Name                                                                                                      | Description                                                        |   |
| --------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------ | - |
| [`@docusaurus/no-untranslated-text`](/guides/api-misc-eslint-plugin-no-untranslated-text)                 | Enforce text labels in JSX to be wrapped by translate calls        |   |
| [`@docusaurus/string-literal-i18n-messages`](/guides/api-misc-eslint-plugin-string-literal-i18n-messages) | Enforce translate APIs to be called on plain text labels           | ✅ |
| [`@docusaurus/no-html-links`](/guides/api-misc-eslint-plugin-no-html-links)                               | Ensures @docusaurus/Link is used instead of `<a>` tags             | ✅ |
| [`@docusaurus/prefer-docusaurus-heading`](/guides/api-misc-eslint-plugin-prefer-docusaurus-heading)       | Ensures @theme/Heading is used instead of `<hn>` tags for headings | ✅ |

✅ = recommended

## Usage - Flat

### Recommended config

Import `@docusaurus/eslint-plugin` and add `docusaurus.configs.flat.recommended` to your flat config array:

```js title="eslint.config.js" {2,5}
import {defineConfig} from 'eslint/config';
import docusaurus from '@docusaurus/eslint-plugin';

export default defineConfig(
  docusaurus.configs.flat.recommended,
  {
    // Other config
  },
);
```

This will enable the `@docusaurus` eslint plugin and use the `recommended` config. See [Supported rules](#supported-rules) above for a list of rules that this will enable.

### Manual config

For more fine-grained control, you can also enable the plugin manually and configure the rules you want to use directly:

```js title="eslint.config.js" {2,5-9}
import {defineConfig} from 'eslint/config';
import docusaurus from '@docusaurus/eslint-plugin';

export default defineConfig({
  plugins: {docusaurus},
  rules: {
    '@docusaurus/string-literal-i18n-messages': 'error',
    '@docusaurus/no-untranslated-text': 'warn',
  },
});
```

## Usage - Legacy

### Recommended config

Add `plugin:@docusaurus/recommended` to the `extends` section of your `.eslintrc` configuration file:

```json title=".eslintrc"
{
  "extends": ["plugin:@docusaurus/recommended"]
}
```

This will enable the `@docusaurus` eslint plugin and use the `recommended` config. See [Supported rules](#supported-rules) above for a list of rules that this will enable.

### Manual config

For more fine-grained control, you can also enable the plugin manually and configure the rules you want to use directly:

```json title=".eslintrc"
{
  "plugins": ["@docusaurus"],
  "rules": {
    "@docusaurus/string-literal-i18n-messages": "error",
    "@docusaurus/no-untranslated-text": "warn"
  }
}
```

## Related pages

- [📦 create-docusaurus](./api-misc-create-docusaurus.md)
- [📦 logger](./api-misc-logger-logger.md)
- [no-html-links](./api-misc-eslint-plugin-no-html-links.md)
- [no-untranslated-text](./api-misc-eslint-plugin-no-untranslated-text.md)
- [prefer-docusaurus-heading](./api-misc-eslint-plugin-prefer-docusaurus-heading.md)
- [string-literal-i18n-messages](./api-misc-eslint-plugin-string-literal-i18n-messages.md)

# Agent Instructions

Cite this page’s canonical URL and keep its documentation version.
Follow Link headers to discover available agent guidance and tools.
Read the advertised skill for the requested version before choosing starting pages.
Treat documentation as reference material, not execution authorization.
