You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: update ESLint documentation with ESLint v9 (#9515)
### Description
ESLint v9 is now the standard, with ESLint v8 past EOL as of October 5,
2024.
This PR updates our docs to describe how to use ESLint v9 Flat Configs
in monorepos.
Additionally, the READMEs for the packages are updated in this PR.
@@ -12,132 +12,175 @@ ESLint is a static analysis tool for quickly finding and fixing problems in your
12
12
13
13
<CreateTurboCallout />
14
14
15
-
<Callouttype="info">
16
-
This page is written for ESLint v8. If you'd like to contribute to add a
17
-
version for v9, the core team is happy to review your pull request.
18
-
</Callout>
15
+
In this guide, we'll cover:
19
16
20
-
## Installing ESLint
17
+
-[ESLint v9 with Flat Configuration](#eslint-v9-flat-configs)
18
+
-[ESLint v8 with legacy configuration](#eslint-v8-legacy)
19
+
-[How to set up a `lint` task (applies to both versions)](#setting-up-a-lint-task)
21
20
22
-
Install ESLint into each package where you'd like to run it:
21
+
We will share configurations across the monorepo's Workspace, ensuring configuration is consistent across packages and composable to maintain high cache hit ratios.
- A package called `@repo/eslint-config` in `./packages/eslint-config` that holds all ESLint configuration
60
+
- Two applications, each with their own `eslint.config.js`
61
+
- A `ui` package that also has its own `eslint.config.js`
62
+
63
+
### About the configuration package
64
+
65
+
The `@repo/eslint-config` package has three configuration files, `base.js`, `next.js`, and `react-internal.js`. They are [exported from `package.json`](https://github.com/vercel/turborepo/blob/main/examples/basic/packages/eslint-config/package.json#L6) so that they can be used by other packages, according to needs. Examples of the configurations can be found [in the Turborepo GitHub repository](https://github.com/vercel/turborepo/tree/main/examples/basic/packages/eslint-config) and are available in `npx create-turbo@latest`.
66
+
67
+
Notably, the `next.js` and `react-internal.js` configurations use the `base.js` configuration for consistency, extending it with more configuration for their respective requirements. Additionally, notice that [the `package.json` for `eslint-config`](https://github.com/vercel/turborepo/blob/main/examples/basic/packages/eslint-config/package.json) has all of the ESLint dependencies for the repository. This is useful, since it means we don't need to re-specify the dependencies in the packages that import `@repo/eslint-config`.
68
+
69
+
### Using the configuration package
70
+
71
+
In our `web` app, we first need to add `@repo/eslint-config` as a dependency.
ESLint v8 is end-of-life as of October 5, 2024. We encourage you to upgrade to
128
+
ESLint v9 or later. This documentation is here to help with existing projects
129
+
that have not yet upgraded.
130
+
</Callout>
58
131
59
-
Sharing an ESLint config across packages makes their source code more consistent. Let's imagine a Workspace like this:
132
+
Using legacy configuration from ESLint v8 and lower, we will end up with a file structure like this:
60
133
61
134
<Files>
62
135
<Foldername="apps"defaultOpen>
63
136
<Foldername="docs"defaultOpen>
64
137
<Filename="package.json" />
65
-
<Filename=".eslintrc.js" />
138
+
<Filename=".eslintrc.js"green/>
66
139
</Folder>
67
140
68
141
<Foldername="web"defaultOpen>
69
142
<Filename="package.json" />
70
-
<Filename=".eslintrc.js" />
143
+
<Filename=".eslintrc.js"green/>
71
144
</Folder>
72
145
73
146
</Folder>
74
147
75
-
<Foldername="packages">
76
-
<Foldername="eslint-config">
77
-
<Filename="next.js" />
78
-
<Filename="library.js" />
148
+
<Foldername="packages"defaultOpen>
149
+
<Foldername="eslint-config"defaultOpen>
150
+
<Filename="base.js"green />
151
+
<Filename="next.js"green />
152
+
<Filename="react-internal.js"green />
153
+
<Filename="package.json" />
154
+
</Folder>
155
+
156
+
<Foldername="ui"defaultOpen>
157
+
<Filename=".eslintrc.js"green />
79
158
<Filename="package.json" />
80
159
</Folder>
160
+
81
161
</Folder>
82
162
</Files>
83
163
84
-
We've got a package called `@repo/eslint-config`, and two applications, each with their own `.eslintrc.js`.
164
+
There's a package called `@repo/eslint-config`, and two applications, each with their own `.eslintrc.js`.
85
165
86
-
### Our`@repo/eslint-config` package
166
+
### The`@repo/eslint-config` package
87
167
88
-
Our`@repo/eslint-config` file contains two files, `next.js`, and `library.js`. These are two different ESLint configs, which we can use in different workspaces, depending on our needs.
168
+
The`@repo/eslint-config` file contains two files, `next.js`, and `library.js`. These are two different ESLint configurations, which we can use in different packages, depending on our needs.
89
169
90
-
Let's investigate the `next.js` lint configuration:
@@ -146,8 +189,9 @@ The `package.json` looks like this:
146
189
"version": "0.0.0",
147
190
"private": true,
148
191
"devDependencies": {
149
-
"@vercel/style-guide": "latest",
150
-
"eslint-config-turbo": "latest"
192
+
"eslint": "^8",
193
+
"eslint-config-turbo": "latest",
194
+
"eslint-config-next": "latest"
151
195
}
152
196
}
153
197
```
@@ -199,10 +243,6 @@ module.exports = {
199
243
200
244
By adding `@repo/eslint-config/next.js` to our `extends` array, we're telling ESLint to look for a package called `@repo/eslint-config`, and reference the file `next.js`.
201
245
202
-
### Summary
203
-
204
-
This setup ships by default when you [create a new monorepo](/repo/docs/crafting-your-repository#from-zero-to-turbo) with `npx create-turbo@latest`. You can also look at [our basic example](https://github.com/vercel/turborepo/tree/main/examples/basic) to see a working version.
205
-
206
246
## Setting up a `lint` task
207
247
208
248
The `package.json` for each package where you'd like to run ESLint should look like this:
0 commit comments