ESLint
ESLint is a static analysis tool for quickly finding and fixing problems in your JavaScript code.
Good to know:
This guide assumes you're using create-turbo or a repository with a similar structure.This page is written for ESLint v8. If you'd like to contribute to add a version for v9, the core team is happy to review your pull request.
Installing ESLint
Install ESLint into each package where you'd like to run it:
Good to know:
You can keep ESLint versions in sync using a tool like syncpack.
Sharing configuration
Sharing an ESLint config across packages makes their source code more consistent. Let's imagine a Workspace like this:
We've got a package called @repo/eslint-config
, and two applications, each with their own .eslintrc.js
.
Our @repo/eslint-config
package
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.
Let's investigate the next.js
lint configuration:
It's a typical ESLint config that extends the Vercel style guide, nothing fancy.
The package.json
looks like this:
Note that the ESLint dependencies are all listed here. This is useful, since it means we don't need to re-specify the dependencies inside the apps which import @repo/eslint-config
.
How to use the @repo/eslint-config
package
In our web
app, we first need to add @repo/eslint-config
as a dependency.
We can then import the config like this:
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
.
Summary
This setup ships by default when you create a new monorepo with npx create-turbo@latest
. You can also look at our basic example to see a working version.
Setting up a lint
task
The package.json
for each package where you'd like to run ESLint should look like this:
With your scripts prepared, you can then create your Turborepo task:
You can now run turbo lint
with global turbo
or create a script in your root package.json
:
Was this helpful?