@nx/eslint - Executors
The @nx/eslint plugin provides various executors to help you create and configure eslint projects within your Nx workspace. Below is a complete reference for all available executors and their options.
lint
ESLint Lint Target.
Linter can be configured in multiple ways. The basic way is to provide only lintFilePatterns
, which tells us where to look for files to lint. If not specified, it defaults to ['{projectRoot}']
.
project.json
:
"lint": { "executor": "@nx/eslint:lint", "options": { "lintFilePatterns": ["apps/frontend/**/*.ts"] }}
Examples
{% tabs %} {% tab label=“Fixing linter issues” %}
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": "@nx/eslint:lint", "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": "@nx/eslint:lint", "outputs": ["{options.outputFile}"], "options": { "lintFilePatterns": ["apps/frontend/**/*.ts"], "fix": true }}
{% /tab %} {% tab label=“Custom output format” %}
ESLint executor uses the stylish
output format by default. You can change this by specifying the format
property:
"lint": { "executor": "@nx/eslint:lint", "outputs": ["{options.outputFile}"], "options": { "lintFilePatterns": ["apps/frontend/**/*.ts"], "format": "compact" }}
{% /tab %} {% tab label=“Silence warnings” %}
Migrated or legacy projects tend to have an overwhelming amount of lint errors. We might want to change those temporarily to be warnings so they don’t block the development. But they would still clutter the report. We can run the command with --quiet
to hide warning (errors would still break the lint):
nx run frontend:lint --quiet
We can also set this via project configuration as a default option.
"lint": { "executor": "@nx/eslint:lint", "outputs": ["{options.outputFile}"], "options": { "lintFilePatterns": ["apps/frontend/**/*.ts"], "quiet": true }}
{% /tab %} {% tab label=“Flat Config file” %}
ESLint
provides several ways of specifying the configuration. The default one is using .eslintrc.json
but you can override it by setting the eslintConfig
flag. The new Flat Config
is now also supported:
"lint": { "executor": "@nx/eslint:lint", "outputs": ["{options.outputFile}"], "options": { "lintFilePatterns": ["apps/frontend/**/*.ts"], "eslintConfig": "eslint.config.cjs" }}
Note: In contrast to other configuration formats, the Flat Config
requires that all configuration files are converted to eslint.config.cjs
. Built-in migrations and generators support only .eslintrc.json
at the moment.
{% /tab %} {% /tabs %}
Options
Option | Type | Description | Default |
---|---|---|---|
cache | boolean | Only check changed files. | false |
cacheLocation | string | Path to the cache file or directory. | |
cacheStrategy | string | Strategy to use for detecting changed files in the cache. | "metadata" |
errorOnUnmatchedPattern | boolean | When set to false, equivalent of the --no-error-on-unmatched-pattern flag on the ESLint CLI. | true |
eslintConfig | string | The name of the ESLint configuration file. | |
fix | boolean | Fixes linting errors (may overwrite linted files). | false |
force | boolean | Succeeds even if there was linting errors. | false |
format | string | ESLint Output formatter (https://eslint.org/docs/user-guide/formatters). | "stylish" |
hasTypeAwareRules | boolean | When set to true , the linter will invalidate its cache when any of its dependencies changes. | |
ignorePath | string | The path of the .eslintignore file. Not supported for Flat Config. | |
lintFilePatterns | array | One or more files/dirs/globs to pass directly to ESLint’s lintFiles() method. | ["{projectRoot}"] |
maxWarnings | number | Number of warnings to trigger nonzero exit code - default: -1 . | -1 |
noEslintrc | boolean | The equivalent of the --no-eslintrc flag on the ESLint CLI, it is false by default. | false |
outputFile | string | File to write report to. | |
printConfig | string | The equivalent of the --print-config flag on the ESLint CLI. | |
quiet | boolean | Report errors only - default: false . | false |
reportUnusedDisableDirectives | string | The equivalent of the --report-unused-disable-directives flag on the ESLint CLI. | |
resolvePluginsRelativeTo | string | The equivalent of the --resolve-plugins-relative-to flag on the ESLint CLI. Not supported for Flat Config. | |
rulesdir | array | The equivalent of the --rulesdir flag on the ESLint CLI. | [] |
silent | boolean | Hide output text. | false |