The ESLint plugin for Nx contains executors, generators and utilities used for linting JavaScript/TypeScript projects within an Nx workspace.
npx @tessl/cli install tessl/npm-nx--eslint@21.5.00
# @nx/eslint
1
2
@nx/eslint is an ESLint integration package for Nx workspaces that provides executors, generators, and utilities for linting JavaScript and TypeScript projects. It offers comprehensive linting capabilities with support for both legacy `.eslintrc` and modern flat config formats, along with automated setup and configuration management for monorepo environments.
3
4
## Package Information
5
6
- **Package Name**: @nx/eslint
7
- **Package Type**: npm
8
- **Language**: TypeScript
9
- **Installation**: `npm install @nx/eslint`
10
11
## Core Imports
12
13
```typescript
14
import { lintProjectGenerator, lintInitGenerator, Linter, LinterType } from '@nx/eslint';
15
import { hasRulesRequiringTypeChecking } from '@nx/eslint';
16
```
17
18
For plugin functionality:
19
20
```typescript
21
import { createNodes, createNodesV2, EslintPluginOptions } from '@nx/eslint/plugin';
22
```
23
24
## Basic Usage
25
26
### Adding Linting to a New Project
27
28
```typescript
29
import { Tree } from '@nx/devkit';
30
import { lintProjectGenerator } from '@nx/eslint';
31
32
// Add linting to a project
33
await lintProjectGenerator(tree, {
34
project: 'my-app',
35
linter: 'eslint',
36
eslintFilePatterns: ['src/**/*.ts'],
37
skipFormat: false
38
});
39
```
40
41
### Initializing ESLint in Workspace
42
43
```typescript
44
import { lintInitGenerator } from '@nx/eslint';
45
46
// Initialize ESLint in the workspace
47
await lintInitGenerator(tree, {
48
skipPackageJson: false,
49
addPlugin: true
50
});
51
```
52
53
### Checking for Type-Aware Rules
54
55
```typescript
56
import { hasRulesRequiringTypeChecking } from '@nx/eslint';
57
import type { Linter } from 'eslint';
58
59
const eslintConfig: Linter.Config = {
60
rules: {
61
'@typescript-eslint/no-unused-vars': 'error'
62
}
63
};
64
65
const requiresTypeInfo = hasRulesRequiringTypeChecking(eslintConfig);
66
// Returns: boolean indicating if config uses type-aware rules
67
```
68
69
## Architecture
70
71
@nx/eslint is built around several key components:
72
73
- **Generators**: Automated setup and configuration of ESLint for projects and workspaces
74
- **Executors**: Task runners for executing ESLint operations within Nx build system
75
- **Plugin System**: Nx plugin integration for automatic project inference and target creation
76
- **Utilities**: Helper functions for configuration management and rule analysis
77
- **Configuration Management**: Handling both legacy and flat config ESLint formats
78
79
## Capabilities
80
81
### Project Generators
82
83
Core generators for setting up and configuring ESLint in Nx projects and workspaces.
84
85
```typescript { .api }
86
function lintProjectGenerator(tree: Tree, options: LintProjectOptions): GeneratorCallback;
87
88
function lintInitGenerator(tree: Tree, options: LinterInitOptions): Promise<GeneratorCallback>;
89
90
interface LintProjectOptions {
91
project: string;
92
linter?: Linter | LinterType;
93
eslintFilePatterns?: string[];
94
tsConfigPaths?: string[];
95
skipFormat: boolean;
96
setParserOptionsProject?: boolean;
97
skipPackageJson?: boolean;
98
unitTestRunner?: string;
99
rootProject?: boolean;
100
keepExistingVersions?: boolean;
101
addPlugin?: boolean;
102
eslintConfigFormat?: 'mjs' | 'cjs';
103
}
104
105
interface LinterInitOptions {
106
skipPackageJson?: boolean;
107
keepExistingVersions?: boolean;
108
updatePackageScripts?: boolean;
109
}
110
```
111
112
[Project Generators](./generators.md)
113
114
### Nx Plugin Integration
115
116
Plugin functionality for automatic ESLint project inference and target creation within Nx workspaces.
117
118
```typescript { .api }
119
const createNodesV2: CreateNodesV2<EslintPluginOptions>;
120
121
const createNodes: CreateNodes<EslintPluginOptions>;
122
123
interface EslintPluginOptions {
124
targetName?: string;
125
extensions?: string[];
126
}
127
```
128
129
[Plugin Integration](./plugin.md)
130
131
### Lint Executor
132
133
Executor for running ESLint operations on projects with comprehensive configuration options.
134
135
```typescript { .api }
136
function run(options: Schema, context: ExecutorContext): Promise<{ success: boolean }>;
137
138
interface Schema {
139
eslintConfig?: string;
140
lintFilePatterns: string[];
141
format: 'stylish' | 'compact' | 'codeframe' | 'unix' | 'visualstudio' | 'table' | 'checkstyle' | 'html' | 'jslint-xml' | 'json' | 'json-with-metadata' | 'junit' | 'tap';
142
force: boolean;
143
silent: boolean;
144
fix: boolean;
145
cache: boolean;
146
cacheLocation?: string;
147
outputFile?: string;
148
maxWarnings: number;
149
quiet: boolean;
150
ignorePath?: string;
151
noEslintrc: boolean;
152
hasTypeAwareRules?: boolean;
153
cacheStrategy: 'metadata' | 'content';
154
rulesdir: string[];
155
resolvePluginsRelativeTo?: string;
156
reportUnusedDisableDirectives?: 'off' | 'warn' | 'error';
157
printConfig?: string;
158
errorOnUnmatchedPattern?: boolean;
159
}
160
```
161
162
[Lint Executor](./executor.md)
163
164
### Configuration Utilities
165
166
Utilities for analyzing and managing ESLint configurations, including type-aware rule detection.
167
168
```typescript { .api }
169
function hasRulesRequiringTypeChecking(eslintConfig: Linter.Config): boolean;
170
```
171
172
[Configuration Utilities](./utilities.md)
173
174
## Types
175
176
### Core Types
177
178
```typescript { .api }
179
type LinterType = 'eslint' | 'none';
180
181
enum Linter {
182
EsLint = 'eslint',
183
None = 'none'
184
}
185
186
interface GeneratorCallback {
187
(): void | Promise<void>;
188
}
189
190
interface Tree {
191
// Nx DevKit Tree interface for file system operations
192
}
193
194
interface ExecutorContext {
195
root: string;
196
projectName: string;
197
projectsConfigurations: {
198
projects: Record<string, any>;
199
};
200
}
201
```