The ESLint plugin contains executors, generator, plugin and utilities used for linting JavaScript/TypeScript projects within an Nx workspace.
Setting Up ESLint
Installation
Keep Nx Package Versions In SyncMake sure to install the @nx/eslint
version that matches the version of nx
in your repository. If the version numbers get out of sync, you can encounter some difficult to debug errors. You can fix Nx version mismatches with this recipe.
In any Nx workspace, you can install @nx/eslint
by running the following command:
❯
npm i -D @nx/eslint
Enable Inferred Tasks
Inferred TasksIn Nx version 17.3, the @nx/eslint
plugin can create inferred tasks for projects that have an ESLint configuration file present. This means you can run nx lint my-project
for that project, even if there is no lint
task defined in package.json
or project.json
.
To enable inferred tasks, add @nx/eslint/plugin
to the plugins
array in nx.json
.
1{
2 "plugins": [
3 {
4 "plugin": "@nx/eslint/plugin",
5 "options": {
6 "targetName": "lint"
7 }
8 }
9 ]
10}
11
Task Inference Process
Identify Valid Projects
The @nx/eslint
plugin will create a task for any project that has an ESLint configuration file present. Any of the following files will be recognized as an ESLint configuration file:
.eslintrc
.eslintrc.js
.eslintrc.cjs
.eslintrc.yaml
.eslintrc.yml
.eslintrc.json
eslint.config.js
Name the Inferred Task
Once an ESLint configuration file has been identified, the task is created with the name you specify under targetName
in the nx.json
plugins
array. The default name for inferred tasks is lint
.
View and Edit Inferred Tasks
To view inferred tasks for a project, open the project details view in Nx Console or run nx show project my-project
in the command line. Nx Console also provides a quick way to override the settings of an inferred task.
Lint
You can lint an application or a library with the following command:
❯
nx lint my-project
Utils
- convert-to-flat-config - Converts the workspace's ESLint configs to the new Flat Config
ESLint plugin
Read about our dedicated ESLint plugin - eslint-plugin-nx.