@nrwl/linter:eslint
ESLint Lint Target.
Options can be configured in project.json
when defining the executor, or when invoking it. Read more about how to configure targets and executors here: https://nx.dev/reference/project-configuration#targets.
Linter can be configured in multiple ways. The basic way is to provide only lintFilePatterns
, which is a mandatory property. This tells us where to look for files to lint.
project.json
:
"lint": {
"executor": "@nrwl/linter:eslint",
"options": {
"lintFilePatterns": ["apps/frontend/**/*.ts"]
}
}
Examples
Linter provides an automated way of fixing known issues. To ensure that those changes are properly cached, we need to add an outputs
property to the lint
target. Omitting the outputs
property would produce an invalid cache record. Both of these properties are set by default when scaffolding a new project.
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["apps/frontend/**/*.ts"]
}
}
With these settings, we can run the command with a --fix
flag:
nx run frontend:lint --fix
We can also set this flag via project configuration to always fix files when running lint:
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": ["apps/frontend/**/*.ts"],
"fix": true
}
}