Skip to content

Commit 0d3fb75

Browse files
authored
Add docs for ESLint plugin settings and rule options (#28059)
This PR adds documentation for the new `rootDir` setting (#27918), and for `next/no-html-link-for-pages`. ## Documentation / Examples - [x] Make sure the linting passes
1 parent 9b09b92 commit 0d3fb75

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

docs/basic-features/eslint.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,25 @@ Next.js provides an ESLint plugin, [`eslint-plugin-next`](https://www.npmjs.com/
101101

102102
If you already have ESLint configured in your application, we recommend extending from this plugin directly instead of including `eslint-config-next` unless a few conditions are met. Refer to the [Recommended Plugin Ruleset](/docs/basic-features/eslint.md#recommended-plugin-ruleset) to learn more.
103103

104+
### Custom Settings
105+
106+
#### `rootDir`
107+
108+
If you're using `eslint-plugin-next` in a project where Next.js isn't installed in your root directory (such as a monorepo), you can tell `eslint-plugin-next` where to find your Next.js application using the `settings` property in your `.eslintrc`:
109+
110+
```json
111+
{
112+
"extends": "next",
113+
"settings": {
114+
"next": {
115+
"rootDir": "/packages/my-app/"
116+
}
117+
}
118+
}
119+
```
120+
121+
`rootDir` can be a path (relative or absolute), a glob (i.e. `"/packages/*/"`), or an array of paths and/or globs.
122+
104123
## Linting Custom Directories
105124

106125
By default, Next.js will run ESLint for all files in the `pages/`, `components/`, and `lib/` directories. However, you can specify which directories using the `dirs` option in the `eslint` config in `next.config.js` for production builds:

errors/no-html-link-for-pages.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,24 @@ function Home() {
4040
export default Home
4141
```
4242

43+
### Options
44+
45+
#### `pagesDir`
46+
47+
This rule can normally locate your `pages` directory automatically.
48+
49+
If you're working in a monorepo, we recommend configuring the [`rootDir`](/docs/basic-features/eslint.md#rootDir) setting in `eslint-plugin-next`, which `pagesDir` will use to locate your `pages` directory.
50+
51+
In some cases, you may also need to configure this rule directly by providing a `pages` directory. This can be a path or an array of paths.
52+
53+
```json
54+
{
55+
"rules": {
56+
"@next/next/no-html-link-for-pages": ["error", "/my-app/pages/"]
57+
}
58+
}
59+
```
60+
4361
### Useful Links
4462

4563
- [next/link API Reference](https://nextjs.org/docs/api-reference/next/link)

0 commit comments

Comments
 (0)