agent-docs 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.cursor/plans/OPTIMISE.md +379 -0
- package/.cursor/plans/VERSIONING.md +207 -0
- package/.cursor/rules/IMPORTANT.mdc +97 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +13 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +17 -0
- package/.github/dependabot.yml +38 -0
- package/.github/pull_request_template.md +10 -0
- package/.github/workflows/format.yml +35 -0
- package/CODE_OF_CONDUCT.md +64 -0
- package/CONTRIBUTING.md +52 -0
- package/LICENSE.md +20 -0
- package/PLAN.md +707 -0
- package/README.md +133 -0
- package/SECURITY.md +21 -0
- package/docs/APEXANNOTATIONS.md +472 -0
- package/docs/APEXDOC.md +198 -0
- package/docs/CML.md +877 -0
- package/docs/CODEANALYZER.md +435 -0
- package/docs/CONTEXTDEFINITIONS.md +617 -0
- package/docs/ESLINT.md +827 -0
- package/docs/ESLINTJSDOC.md +520 -0
- package/docs/FIELDSERVICE.md +4452 -0
- package/docs/GRAPHBINARY.md +208 -0
- package/docs/GRAPHENGINE.md +616 -0
- package/docs/GRAPHML.md +337 -0
- package/docs/GRAPHSON.md +302 -0
- package/docs/GREMLIN.md +490 -0
- package/docs/GRYO.md +232 -0
- package/docs/HUSKY.md +106 -0
- package/docs/JEST.md +387 -0
- package/docs/JORJE.md +537 -0
- package/docs/JSDOC.md +621 -0
- package/docs/PMD.md +910 -0
- package/docs/PNPM.md +409 -0
- package/docs/PRETTIER.md +716 -0
- package/docs/PRETTIERAPEX.md +874 -0
- package/docs/REVENUETRANSACTIONMANAGEMENT.md +887 -0
- package/docs/TINKERPOP.md +252 -0
- package/docs/VITEST.md +706 -0
- package/docs/VSCODE.md +231 -0
- package/docs/XPATH31.md +213 -0
- package/package.json +32 -0
- package/postinstall.mjs +51 -0
- package/prettier.config.js +18 -0
package/docs/ESLINT.md
ADDED
|
@@ -0,0 +1,827 @@
|
|
|
1
|
+
# ESLint Reference
|
|
2
|
+
|
|
3
|
+
> **Version**: 1.0.0
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
ESLint: JS/TS/LWC static analysis. ESLint v8 and v9 support.
|
|
8
|
+
|
|
9
|
+
**typescript-eslint**: Parser (`@typescript-eslint/parser`) + 100+ rules
|
|
10
|
+
(`@typescript-eslint/eslint-plugin`) + type-aware linting + configs
|
|
11
|
+
(recommended/strict/stylistic) + Project Service.
|
|
12
|
+
|
|
13
|
+
## Prerequisites
|
|
14
|
+
|
|
15
|
+
**v9**: Node `^18.18.0|^20.9.0|>=21.1.0`+SSL | **v8**: Node
|
|
16
|
+
`^12.22.0|^14.17.0|^16.0.0|^18.0.0|^20.0.0`
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm init @eslint/config@latest # OR: npm i -D eslint @eslint/js && npx eslint .
|
|
22
|
+
# TypeScript: npm i -D eslint @eslint/js typescript typescript-eslint
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**eslint.config.mjs** (TS):
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
import eslint from '@eslint/js';
|
|
29
|
+
import tseslint from 'typescript-eslint';
|
|
30
|
+
export default tseslint.config(
|
|
31
|
+
eslint.configs.recommended,
|
|
32
|
+
tseslint.configs.recommended,
|
|
33
|
+
);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## ESLint Configuration
|
|
37
|
+
|
|
38
|
+
ESLint can be configured using flat config (v9) or legacy config (v8) formats.
|
|
39
|
+
|
|
40
|
+
## Config Formats
|
|
41
|
+
|
|
42
|
+
### Flat (v9) - `eslint.config.js`
|
|
43
|
+
|
|
44
|
+
```javascript
|
|
45
|
+
export default [
|
|
46
|
+
{
|
|
47
|
+
files: ['**/*.js'],
|
|
48
|
+
languageOptions: { ecmaVersion: 2022, sourceType: 'module' },
|
|
49
|
+
rules: { 'no-console': 'error' },
|
|
50
|
+
},
|
|
51
|
+
];
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Array-based, `files` matching, `languageOptions` replaces `parserOptions`+`env`,
|
|
55
|
+
no cascading.
|
|
56
|
+
|
|
57
|
+
### Flat TS Config
|
|
58
|
+
|
|
59
|
+
```javascript
|
|
60
|
+
import eslint from '@eslint/js';
|
|
61
|
+
import tseslint from 'typescript-eslint';
|
|
62
|
+
export default tseslint.config(
|
|
63
|
+
eslint.configs.recommended,
|
|
64
|
+
...tseslint.configs.recommended,
|
|
65
|
+
{
|
|
66
|
+
files: ['**/*.ts'],
|
|
67
|
+
rules: { '@typescript-eslint/no-explicit-any': 'warn' },
|
|
68
|
+
},
|
|
69
|
+
);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Legacy (v8) - `.eslintrc.json`
|
|
73
|
+
|
|
74
|
+
```json
|
|
75
|
+
{
|
|
76
|
+
"env": { "browser": true },
|
|
77
|
+
"extends": ["eslint:recommended"],
|
|
78
|
+
"parserOptions": { "ecmaVersion": 2021 },
|
|
79
|
+
"rules": { "no-console": "error" }
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Cascading, `extends`, `env`, `.eslintignore`.
|
|
84
|
+
|
|
85
|
+
### Legacy TS Config
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
{
|
|
89
|
+
"parser": "@typescript-eslint/parser",
|
|
90
|
+
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
|
|
91
|
+
"parserOptions": { "project": "./tsconfig.json" },
|
|
92
|
+
"plugins": ["@typescript-eslint"]
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
**Migration**: `npx @eslint/migrate-config` | Legacy files→v8, flat→v9
|
|
97
|
+
|
|
98
|
+
## Version Detection
|
|
99
|
+
|
|
100
|
+
ESLint v9 uses flat config by default. If `.eslintrc.*` files are present,
|
|
101
|
+
ESLint v8 is used.
|
|
102
|
+
|
|
103
|
+
## Config Merging
|
|
104
|
+
|
|
105
|
+
Array concat (flat) → object merge (later wins) → plugin version comparison
|
|
106
|
+
(higher wins) → your severity overrides.
|
|
107
|
+
|
|
108
|
+
## ESLint Process
|
|
109
|
+
|
|
110
|
+
Parse→AST → Traverse→rules visit nodes → Report→violations → Fix→`--fix`
|
|
111
|
+
|
|
112
|
+
## Rules
|
|
113
|
+
|
|
114
|
+
Severity: `off`/0, `warn`/1, `error`/2
|
|
115
|
+
|
|
116
|
+
```javascript
|
|
117
|
+
rules:{'no-console':'error','max-len':['error',{max:100}],'@typescript-eslint/no-explicit-any':['warn',{ignoreRestArgs:true}]}
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Severity mapping: `warn` (1) and `error` (2) are standard ESLint severity
|
|
121
|
+
levels.
|
|
122
|
+
|
|
123
|
+
## Bundled Rules
|
|
124
|
+
|
|
125
|
+
JS: Standard ESLint | TS: @typescript-eslint | LWC:
|
|
126
|
+
@salesforce/eslint-config-lwc + @lwc/eslint-plugin-lwc-platform | SLDS:
|
|
127
|
+
@salesforce-ux/eslint-plugin-slds
|
|
128
|
+
|
|
129
|
+
## Plugins
|
|
130
|
+
|
|
131
|
+
### Flat
|
|
132
|
+
|
|
133
|
+
```javascript
|
|
134
|
+
import plugin from 'eslint-plugin-name';
|
|
135
|
+
export default [{ plugins: { name: plugin }, rules: { 'name/rule': 'error' } }];
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Legacy
|
|
139
|
+
|
|
140
|
+
```json
|
|
141
|
+
{ "plugins": ["name"], "rules": { "name/rule": "error" } }
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Package: `eslint-plugin-{name}` → ref: `{name}` | Rule: `{plugin}/{rule}`
|
|
145
|
+
|
|
146
|
+
## Parser Config
|
|
147
|
+
|
|
148
|
+
### Flat
|
|
149
|
+
|
|
150
|
+
```javascript
|
|
151
|
+
import tsParser from '@typescript-eslint/parser';
|
|
152
|
+
export default [
|
|
153
|
+
{
|
|
154
|
+
files: ['**/*.ts'],
|
|
155
|
+
languageOptions: {
|
|
156
|
+
parser: tsParser,
|
|
157
|
+
parserOptions: { project: './tsconfig.json' },
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
];
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### TS Parser Options
|
|
164
|
+
|
|
165
|
+
```javascript
|
|
166
|
+
parserOptions:{
|
|
167
|
+
project:['./tsconfig.json'], // or projectService:true (recommended for large projects)
|
|
168
|
+
tsconfigRootDir:import.meta.dirname,
|
|
169
|
+
ecmaVersion:2022,sourceType:'module',
|
|
170
|
+
extraFileExtensions:['.vue'],
|
|
171
|
+
ecmaFeatures:{jsx:true}
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
**Project Service**: Auto-detects projects, better perf, monorepo support.
|
|
176
|
+
`projectService:true`
|
|
177
|
+
|
|
178
|
+
## Language Options
|
|
179
|
+
|
|
180
|
+
```javascript
|
|
181
|
+
languageOptions:{ecmaVersion:2022,sourceType:'module',globals:{console:'readonly'},parser:p,parserOptions:{ecmaFeatures:{jsx:true}}}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
Use `globals` pkg: `...globals.browser`, `...globals.node`
|
|
185
|
+
|
|
186
|
+
## Ignores
|
|
187
|
+
|
|
188
|
+
**Flat**: `export default [{ignores:['dist/**','node_modules/**']}];`
|
|
189
|
+
**Legacy**: `.eslintignore` file. Glob syntax, `!` negation.
|
|
190
|
+
|
|
191
|
+
## Inline Comments
|
|
192
|
+
|
|
193
|
+
```javascript
|
|
194
|
+
// eslint-disable-next-line rule
|
|
195
|
+
/* eslint-disable rule */
|
|
196
|
+
/* eslint-enable rule */
|
|
197
|
+
// eslint-disable-next-line r1,r2 -- reason
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## SLDS Rules
|
|
201
|
+
|
|
202
|
+
`@salesforce-ux/eslint-plugin-slds`: `enforce-bem-usage`,
|
|
203
|
+
`no-deprecated-classes-slds2`, `modal-close-button-issue` Disable:
|
|
204
|
+
`disable_slds_base_config:true`
|
|
205
|
+
|
|
206
|
+
## LWC Rules
|
|
207
|
+
|
|
208
|
+
`@lwc/eslint-plugin-lwc` (v3+: ESLint v9 only) **Base**:
|
|
209
|
+
`no-api-reassignments`,`no-deprecated`,`no-document-query`,`valid-api/track/wire`
|
|
210
|
+
**Best**: `no-async-operation`,`no-inner-html`,`no-leaky-event-listeners`
|
|
211
|
+
**Compat**: `no-async-await`,`no-for-of` (IE11) | **SSR**:
|
|
212
|
+
`ssr-no-restricted-browser-globals` Disable: `disable_lwc_base_config:true`
|
|
213
|
+
|
|
214
|
+
## TypeScript ESLint
|
|
215
|
+
|
|
216
|
+
### Configs
|
|
217
|
+
|
|
218
|
+
```javascript
|
|
219
|
+
tseslint.configs.recommended; // balanced
|
|
220
|
+
tseslint.configs.strict; // + opinionated bug-catching
|
|
221
|
+
tseslint.configs.stylistic; // consistent style
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Combine:
|
|
225
|
+
`tseslint.config(eslint.configs.recommended,...tseslint.configs.recommended,...tseslint.configs.strict)`
|
|
226
|
+
|
|
227
|
+
### Rule Metadata
|
|
228
|
+
|
|
229
|
+
🔧fixable | 💡suggestions | 💭type-checked | 🧱extension | 💀deprecated
|
|
230
|
+
|
|
231
|
+
### Extension Rules
|
|
232
|
+
|
|
233
|
+
Disable base when using TS version:
|
|
234
|
+
|
|
235
|
+
```javascript
|
|
236
|
+
rules:{'no-unused-vars':'off','@typescript-eslint/no-unused-vars':'error'}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
## Typed Linting
|
|
240
|
+
|
|
241
|
+
### Setup
|
|
242
|
+
|
|
243
|
+
```javascript
|
|
244
|
+
export default tseslint.config(
|
|
245
|
+
{
|
|
246
|
+
files: ['**/*.ts'],
|
|
247
|
+
languageOptions: {
|
|
248
|
+
parserOptions: {
|
|
249
|
+
project: ['./tsconfig.json'],
|
|
250
|
+
tsconfigRootDir: import.meta.dirname,
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
...tseslint.configs.recommendedTypeChecked,
|
|
255
|
+
);
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
Or use Project Service: `parserOptions:{projectService:true}`
|
|
259
|
+
|
|
260
|
+
### Type-Aware Rules
|
|
261
|
+
|
|
262
|
+
`no-unsafe-assignment`,`no-unsafe-call`,`no-unsafe-member-access`,`no-unsafe-return`,`no-floating-promises`,`await-thenable`
|
|
263
|
+
|
|
264
|
+
## TypeScript ESLint Rules Reference
|
|
265
|
+
|
|
266
|
+
Complete reference of all `@typescript-eslint/eslint-plugin` rules. Rules are
|
|
267
|
+
organized alphabetically with metadata indicators:
|
|
268
|
+
|
|
269
|
+
- ✅ **recommended**: Included in `tseslint.configs.recommended`
|
|
270
|
+
- 🔒 **strict**: Included in `tseslint.configs.strict`
|
|
271
|
+
- 🎨 **stylistic**: Included in `tseslint.configs.stylistic`
|
|
272
|
+
- 🔧 **fixable**: Supports `--fix` auto-fix
|
|
273
|
+
- 💡 **suggestions**: Provides fix suggestions
|
|
274
|
+
- 💭 **type-checked**: Requires type information (`project` or `projectService`)
|
|
275
|
+
- 🧱 **extension**: Extends a core ESLint rule (disable base rule)
|
|
276
|
+
- 💀 **deprecated**: Rule is deprecated and will be removed
|
|
277
|
+
|
|
278
|
+
### Rules List
|
|
279
|
+
|
|
280
|
+
| Rule | Config | Metadata | Description |
|
|
281
|
+
| ----------------------------------------------------------------- | ------ | -------- | ----------------------------------------------------------------------------------------------------------------------- |
|
|
282
|
+
| `@typescript-eslint/adjacent-overload-signatures` | 🎨 | | Require that function overload signatures be consecutive |
|
|
283
|
+
| `@typescript-eslint/array-type` | 🎨 | 🔧 | Require consistently using either `T[]` or `Array<T>` for arrays |
|
|
284
|
+
| `@typescript-eslint/await-thenable` | ✅ | 💡💭 | Disallow awaiting a value that is not a Thenable |
|
|
285
|
+
| `@typescript-eslint/ban-ts-comment` | ✅ | 💡 | Disallow `@ts-<directive>` comments or require descriptions after directives |
|
|
286
|
+
| `@typescript-eslint/ban-tslint-comment` | 🎨 | 🔧 | Disallow `// tslint:<rule-flag>` comments |
|
|
287
|
+
| `@typescript-eslint/class-literal-property-style` | 🎨 | 💡 | Enforce that literals on classes are exposed in a consistent style |
|
|
288
|
+
| `@typescript-eslint/class-methods-use-this` | 🧱 | | Enforce that class methods utilize `this` |
|
|
289
|
+
| `@typescript-eslint/consistent-generic-constructors` | 🎨 | 🔧 | Enforce specifying generic type arguments on type annotation or constructor name |
|
|
290
|
+
| `@typescript-eslint/consistent-indexed-object-style` | 🎨 | 🔧💡 | Require or disallow the `Record` type |
|
|
291
|
+
| `@typescript-eslint/consistent-return` | 💭🧱 | | Require return statements to either always or never specify values |
|
|
292
|
+
| `@typescript-eslint/consistent-type-assertions` | 🎨 | 🔧💡 | Enforce consistent usage of type assertions |
|
|
293
|
+
| `@typescript-eslint/consistent-type-definitions` | 🎨 | 🔧 | Enforce type definitions to consistently use either `interface` or `type` |
|
|
294
|
+
| `@typescript-eslint/consistent-type-exports` | | 🔧💭 | Enforce consistent usage of type exports |
|
|
295
|
+
| `@typescript-eslint/consistent-type-imports` | | 🔧 | Enforce consistent usage of type imports |
|
|
296
|
+
| `@typescript-eslint/default-param-last` | 🧱 | | Enforce default parameters to be last |
|
|
297
|
+
| `@typescript-eslint/dot-notation` | 🎨 | 💡💭🧱 | Enforce dot notation whenever possible |
|
|
298
|
+
| `@typescript-eslint/explicit-function-return-type` | | | Require explicit return types on functions and class methods |
|
|
299
|
+
| `@typescript-eslint/explicit-member-accessibility` | | | Require explicit accessibility modifiers on class properties and methods |
|
|
300
|
+
| `@typescript-eslint/explicit-module-boundary-types` | | | Require explicit return and argument types on exported functions' and classes' public class methods |
|
|
301
|
+
| `@typescript-eslint/init-declarations` | 🧱 | | Require or disallow initialization in variable declarations |
|
|
302
|
+
| `@typescript-eslint/max-params` | 🧱 | | Enforce a maximum number of parameters in function definitions |
|
|
303
|
+
| `@typescript-eslint/member-ordering` | | | Enforce members of a class to be declared in a particular order |
|
|
304
|
+
| `@typescript-eslint/method-signature-style` | 🎨 | 🔧 | Enforce using a particular method signature syntax |
|
|
305
|
+
| `@typescript-eslint/naming-convention` | | | Enforce naming conventions for everything across a codebase |
|
|
306
|
+
| `@typescript-eslint/no-array-constructor` | 🧱 | 🔧 | Disallow generic `Array` constructors |
|
|
307
|
+
| `@typescript-eslint/no-array-delete` | | 💡💭 | Disallow deleting computed property keys |
|
|
308
|
+
| `@typescript-eslint/no-base-to-string` | | 💡💭 | Require `.toString()` to only be called on objects which provide useful information when stringified |
|
|
309
|
+
| `@typescript-eslint/no-confusing-non-null-assertion` | 🎨 | 💡 | Disallow non-null assertion in locations that may be confusing |
|
|
310
|
+
| `@typescript-eslint/no-confusing-void-expression` | 🎨 | 💡💭 | Disallow returning a value from a function with the return type `void` |
|
|
311
|
+
| `@typescript-eslint/no-deprecated` | | 💡💭 | Disallow using deprecated APIs |
|
|
312
|
+
| `@typescript-eslint/no-dupe-class-members` | 🧱 | | Disallow duplicate class members |
|
|
313
|
+
| `@typescript-eslint/no-duplicate-enum-values` | | | Disallow duplicate enum member values |
|
|
314
|
+
| `@typescript-eslint/no-duplicate-type-constituents` | | 💡💭 | Disallow duplicate constituents of union or intersection types |
|
|
315
|
+
| `@typescript-eslint/no-dynamic-delete` | | 🔧💡 | Disallow using the `delete` operator on computed key expressions |
|
|
316
|
+
| `@typescript-eslint/no-empty-function` | 🧱 | | Disallow empty functions |
|
|
317
|
+
| `@typescript-eslint/no-empty-interface` | ✅ | 🔧 | Disallow the declaration of empty interfaces |
|
|
318
|
+
| `@typescript-eslint/no-empty-object-type` | | 🔧💡 | Disallow empty object types |
|
|
319
|
+
| `@typescript-eslint/no-explicit-any` | ✅ | | Disallow the `any` type |
|
|
320
|
+
| `@typescript-eslint/no-extra-non-null-assertion` | ✅ | 🔧 | Disallow extra non-null assertions |
|
|
321
|
+
| `@typescript-eslint/no-extraneous-class` | | 🔧💡 | Disallow classes used as namespaces |
|
|
322
|
+
| `@typescript-eslint/no-floating-promises` | ✅ | 💡💭 | Require Promise-like values to be handled appropriately |
|
|
323
|
+
| `@typescript-eslint/no-for-in-array` | ✅ | 💡💭 | Disallow iterating over an array with a for-in loop |
|
|
324
|
+
| `@typescript-eslint/no-implied-eval` | 🧱 | 💡 | Disallow the use of `eval()`-like methods |
|
|
325
|
+
| `@typescript-eslint/no-import-type-side-effects` | | 💡💭 | Enforce the use of top-level import type qualifier when an import only has specifiers with inline type qualifiers |
|
|
326
|
+
| `@typescript-eslint/no-inferrable-types` | ✅ | 🔧 | Disallow explicit type annotations for variables or parameters initialized to a number, string, or boolean |
|
|
327
|
+
| `@typescript-eslint/no-invalid-this` | 🧱 | | Disallow `this` keywords outside of classes or class-like objects |
|
|
328
|
+
| `@typescript-eslint/no-invalid-void-type` | | | Disallow `void` type outside of generic or return types |
|
|
329
|
+
| `@typescript-eslint/no-loop-func` | 🧱 | | Disallow function declarations that contain unsafe references inside loop statements |
|
|
330
|
+
| `@typescript-eslint/no-loss-of-precision` | 🧱 | | Disallow literal numbers that lose precision |
|
|
331
|
+
| `@typescript-eslint/no-magic-numbers` | | | Disallow magic numbers |
|
|
332
|
+
| `@typescript-eslint/no-meaningless-void-operator` | 🎨 | 🔧💡 | Disallow the `void` operator except when used to discard a value |
|
|
333
|
+
| `@typescript-eslint/no-misused-new` | ✅ | | Enforce valid definition of `new` and `constructor` |
|
|
334
|
+
| `@typescript-eslint/no-misused-promises` | ✅ | 💡💭 | Disallow Promises in places not designed to handle them |
|
|
335
|
+
| `@typescript-eslint/no-misused-spread` | | 💡💭 | Disallow `...rest` parameters that are actually a tuple type |
|
|
336
|
+
| `@typescript-eslint/no-mixed-enums` | | 🔧💡 | Disallow enums from having both number and string members |
|
|
337
|
+
| `@typescript-eslint/no-namespace` | ✅ | 🔧 | Disallow TypeScript namespaces |
|
|
338
|
+
| `@typescript-eslint/no-non-null-asserted-nullish-coalescing` | ✅ | 💡💭 | Disallow non-null assertions in the left operand of a nullish coalescing operator |
|
|
339
|
+
| `@typescript-eslint/no-non-null-asserted-optional-chain` | ✅ | 💡 | Disallow non-null assertions after an optional chain expression |
|
|
340
|
+
| `@typescript-eslint/no-non-null-assertion` | ✅ | 💡 | Disallow non-null assertions using the `!` postfix operator |
|
|
341
|
+
| `@typescript-eslint/no-redeclare` | 🧱 | | Disallow variable redeclaration |
|
|
342
|
+
| `@typescript-eslint/no-redundant-type-constituents` | | 🔧💡💭 | Disallow members of unions and intersections that do nothing or override type information |
|
|
343
|
+
| `@typescript-eslint/no-require-imports` | | | Disallow invocation of `require()` |
|
|
344
|
+
| `@typescript-eslint/no-restricted-imports` | 🧱 | | Disallow specified modules when loaded by `import` or `require` |
|
|
345
|
+
| `@typescript-eslint/no-restricted-types` | | | Disallow certain types |
|
|
346
|
+
| `@typescript-eslint/no-shadow` | 🧱 | | Disallow variable declarations from shadowing variables declared in the outer scope |
|
|
347
|
+
| `@typescript-eslint/no-this-alias` | | | Disallow aliasing `this` |
|
|
348
|
+
| `@typescript-eslint/no-type-alias` | | | Disallow type aliases |
|
|
349
|
+
| `@typescript-eslint/no-unnecessary-boolean-literal-compare` | 🎨 | 🔧💡💭 | Disallow unnecessary equality comparisons against boolean literals |
|
|
350
|
+
| `@typescript-eslint/no-unnecessary-condition` | | 💡💭 | Disallow conditionals where the type is always truthy or always falsy |
|
|
351
|
+
| `@typescript-eslint/no-unnecessary-parameter-property-assignment` | | 💡💭 | Disallow unnecessary parameter property assignments |
|
|
352
|
+
| `@typescript-eslint/no-unnecessary-qualifier` | 🎨 | 🔧💡💭 | Disallow unnecessary namespace qualifiers |
|
|
353
|
+
| `@typescript-eslint/no-unnecessary-template-expression` | 🎨 | 🔧💡 | Disallow unnecessary template expressions |
|
|
354
|
+
| `@typescript-eslint/no-unnecessary-type-arguments` | 🎨 | 🔧💡💭 | Disallow unnecessary generic type arguments |
|
|
355
|
+
| `@typescript-eslint/no-unnecessary-type-assertion` | ✅ | 🔧💡💭 | Disallow type assertions that are unnecessary |
|
|
356
|
+
| `@typescript-eslint/no-unnecessary-type-constraint` | 🎨 | 🔧💡💭 | Disallow unnecessary constraints on generic types |
|
|
357
|
+
| `@typescript-eslint/no-unnecessary-type-conversion` | 🎨 | 🔧💡💭 | Disallow unnecessary type conversions |
|
|
358
|
+
| `@typescript-eslint/no-unnecessary-type-parameters` | 🎨 | 🔧💡💭 | Disallow unnecessary type parameters |
|
|
359
|
+
| `@typescript-eslint/no-unsafe-argument` | ✅ | 💡💭 | Disallow calling a function with a value with type `any` |
|
|
360
|
+
| `@typescript-eslint/no-unsafe-assignment` | ✅ | 💡💭 | Disallow assigning a value with type `any` to variables and properties |
|
|
361
|
+
| `@typescript-eslint/no-unsafe-call` | ✅ | 💡💭 | Disallow calling a value with type `any` |
|
|
362
|
+
| `@typescript-eslint/no-unsafe-declaration-merging` | | 💡💭 | Disallow unsafe declaration merging |
|
|
363
|
+
| `@typescript-eslint/no-unsafe-enum-comparison` | | 💡💭 | Disallow comparing an enum value with a non-enum value |
|
|
364
|
+
| `@typescript-eslint/no-unsafe-function-type` | | 💡💭 | Disallow function types that are unsafe |
|
|
365
|
+
| `@typescript-eslint/no-unsafe-member-access` | ✅ | 💡💭 | Disallow member access on a value with type `any` |
|
|
366
|
+
| `@typescript-eslint/no-unsafe-return` | ✅ | 💡💭 | Disallow returning a value with type `any` from a function |
|
|
367
|
+
| `@typescript-eslint/no-unsafe-type-assertion` | | 💡💭 | Disallow type assertions that are unsafe |
|
|
368
|
+
| `@typescript-eslint/no-unsafe-unary-minus` | | 💡💭 | Disallow unary minus operator on non-numeric types |
|
|
369
|
+
| `@typescript-eslint/no-unused-expressions` | 🧱 | | Disallow unused expressions |
|
|
370
|
+
| `@typescript-eslint/no-unused-private-class-members` | | | Disallow unused private class members |
|
|
371
|
+
| `@typescript-eslint/no-unused-vars` | ✅ | 🧱 | Disallow unused variables |
|
|
372
|
+
| `@typescript-eslint/no-use-before-define` | 🧱 | | Disallow the use of variables before they are defined |
|
|
373
|
+
| `@typescript-eslint/no-useless-constructor` | 🧱 | 🔧 | Disallow unnecessary constructors |
|
|
374
|
+
| `@typescript-eslint/no-useless-default-assignment` | | 🔧💡💭 | Disallow useless default assignments |
|
|
375
|
+
| `@typescript-eslint/no-useless-empty-export` | | 🔧 | Disallow empty exports that don't change anything in a module file |
|
|
376
|
+
| `@typescript-eslint/no-var-requires` | ✅ | | Disallow `require` statements except in import statements |
|
|
377
|
+
| `@typescript-eslint/no-wrapper-object-types` | | 🔧💡💭 | Disallow using wrapper objects (String, Number, Boolean) as types |
|
|
378
|
+
| `@typescript-eslint/non-nullable-type-assertion-style` | 🎨 | 🔧💡💭 | Enforce non-null assertions over explicit type assertions |
|
|
379
|
+
| `@typescript-eslint/only-throw-error` | 🔒 | 💡💭 | Enforce throwing only `Error` objects |
|
|
380
|
+
| `@typescript-eslint/parameter-properties` | | | Require or disallow parameter properties in class constructors |
|
|
381
|
+
| `@typescript-eslint/prefer-as-const` | ✅ | 🔧 | Require `as const` for literal expressions that are never reassigned |
|
|
382
|
+
| `@typescript-eslint/prefer-destructuring` | 🧱 | 💡 | Require destructuring from arrays and/or objects |
|
|
383
|
+
| `@typescript-eslint/prefer-enum-initializers` | | 🔧💡 | Require each enum member value to be explicitly initialized |
|
|
384
|
+
| `@typescript-eslint/prefer-find` | 🎨 | 🔧💡💭 | Enforce using `Array.find()` instead of `Array.filter()[0]` |
|
|
385
|
+
| `@typescript-eslint/prefer-for-of` | 🎨 | | Enforce the use of `for-of` loops over the standard `for` loop where possible |
|
|
386
|
+
| `@typescript-eslint/prefer-function-type` | 🎨 | 🔧 | Enforce using function types instead of interfaces with call signatures |
|
|
387
|
+
| `@typescript-eslint/prefer-includes` | 🎨 | 🔧💡💭 | Enforce using `String#includes()` instead of `String#indexOf()` or `String#search()` |
|
|
388
|
+
| `@typescript-eslint/prefer-literal-enum-member` | | | Require all enum members to be literal values |
|
|
389
|
+
| `@typescript-eslint/prefer-namespace-keyword` | ✅ | 🔧 | Require using `namespace` keyword instead of `module` keyword to declare custom TypeScript modules |
|
|
390
|
+
| `@typescript-eslint/prefer-nullish-coalescing` | 🎨 | 🔧💡💭 | Enforce using the nullish coalescing operator instead of logical chaining |
|
|
391
|
+
| `@typescript-eslint/prefer-optional-chain` | 🎨 | 🔧💡💭 | Enforce using concise optional chain expressions instead of chained logical ands, negated logical ors, or empty objects |
|
|
392
|
+
| `@typescript-eslint/prefer-promise-reject-errors` | ✅ | 💭🧱 | Require using Error objects as Promise rejection reasons |
|
|
393
|
+
| `@typescript-eslint/prefer-readonly` | | 🔧💭 | Require private members to be marked as `readonly` if they're never modified outside of the constructor |
|
|
394
|
+
| `@typescript-eslint/prefer-readonly-parameter-types` | | 💭 | Require function parameters to be typed as `readonly` to prevent accidental mutation of inputs |
|
|
395
|
+
| `@typescript-eslint/prefer-reduce-type-parameter` | 🔒 | 🔧💭 | Enforce using type parameter when calling `Array#reduce` instead of using a type assertion |
|
|
396
|
+
| `@typescript-eslint/prefer-regexp-exec` | 🎨 | 🔧💭 | Enforce `RegExp#exec` over `String#match` if no global flag is provided |
|
|
397
|
+
| `@typescript-eslint/prefer-return-this-type` | 🔒 | 🔧💭 | Enforce that `this` is used when only `this` type is returned |
|
|
398
|
+
| `@typescript-eslint/prefer-string-starts-ends-with` | 🎨 | 🔧💭 | Enforce using `String#startsWith` and `String#endsWith` over other equivalent methods of checking substrings |
|
|
399
|
+
| `@typescript-eslint/prefer-ts-expect-error` | | 🔧💀 | Enforce using `@ts-expect-error` over `@ts-ignore` |
|
|
400
|
+
| `@typescript-eslint/promise-function-async` | | 🔧💭 | Require any function or method that returns a Promise to be marked `async` |
|
|
401
|
+
| `@typescript-eslint/related-getter-setter-pairs` | 🔒 | 💭 | Enforce that `get()` types should be assignable to their equivalent `set()` type |
|
|
402
|
+
| `@typescript-eslint/require-array-sort-compare` | | 💭 | Require `Array#sort` and `Array#toSorted` calls to always provide a `compareFunction` |
|
|
403
|
+
| `@typescript-eslint/require-await` | ✅ | 💡💭🧱 | Disallow async functions which do not return promises and have no `await` expression |
|
|
404
|
+
| `@typescript-eslint/restrict-plus-operands` | ✅ | 💭 | Require both operands of addition to be the same type and be `bigint`, `number`, or `string` |
|
|
405
|
+
| `@typescript-eslint/restrict-template-expressions` | ✅ | 💭 | Enforce template literal expressions to be of string type |
|
|
406
|
+
| `@typescript-eslint/return-await` | 🔒 | 🔧💡💭 | Enforce consistent awaiting of returned promises |
|
|
407
|
+
| `@typescript-eslint/sort-type-constituents` | | 🔧💡💀 | Enforce constituents of a type union/intersection to be sorted alphabetically |
|
|
408
|
+
| `@typescript-eslint/strict-boolean-expressions` | | 💡💭 | Disallow certain types in boolean expressions |
|
|
409
|
+
| `@typescript-eslint/switch-exhaustiveness-check` | | 💡💭 | Require switch-case statements to be exhaustive |
|
|
410
|
+
| `@typescript-eslint/triple-slash-reference` | ✅ | | Disallow certain triple slash directives in favor of ES6-style import declarations |
|
|
411
|
+
| `@typescript-eslint/typedef` | | 💀 | Require type annotations in certain places |
|
|
412
|
+
| `@typescript-eslint/unbound-method` | ✅ | 💭 | Enforce unbound methods are called with their expected scope |
|
|
413
|
+
| `@typescript-eslint/unified-signatures` | 🔒 | | Disallow two overloads that could be unified into one with a union or an optional/rest parameter |
|
|
414
|
+
| `@typescript-eslint/use-unknown-in-catch-callback-variable` | 🔒 | 💡💭 | Enforce typing arguments in Promise rejection callbacks as `unknown` |
|
|
415
|
+
|
|
416
|
+
### Commonly Used Rules
|
|
417
|
+
|
|
418
|
+
#### Type Safety Rules
|
|
419
|
+
|
|
420
|
+
**`@typescript-eslint/no-explicit-any`** (✅)
|
|
421
|
+
|
|
422
|
+
- Disallows the use of `any` type
|
|
423
|
+
- Options: `fixToUnknown`, `ignoreRestArgs`
|
|
424
|
+
- Example: `const x: any = 1;` ❌ → `const x: unknown = 1;` ✅
|
|
425
|
+
|
|
426
|
+
**`@typescript-eslint/no-unsafe-assignment`** (✅💡💭)
|
|
427
|
+
|
|
428
|
+
- Disallows assigning values with `any` type
|
|
429
|
+
- Requires type checking
|
|
430
|
+
- Example: `const x: string = anyValue;` ❌
|
|
431
|
+
|
|
432
|
+
**`@typescript-eslint/no-unsafe-call`** (✅💡💭)
|
|
433
|
+
|
|
434
|
+
- Disallows calling functions with `any` type
|
|
435
|
+
- Requires type checking
|
|
436
|
+
- Example: `anyFunction();` ❌
|
|
437
|
+
|
|
438
|
+
**`@typescript-eslint/no-unsafe-member-access`** (✅💡💭)
|
|
439
|
+
|
|
440
|
+
- Disallows accessing members on `any` type
|
|
441
|
+
- Requires type checking
|
|
442
|
+
- Example: `anyValue.property;` ❌
|
|
443
|
+
|
|
444
|
+
**`@typescript-eslint/no-unsafe-return`** (✅💡💭)
|
|
445
|
+
|
|
446
|
+
- Disallows returning `any` type from functions
|
|
447
|
+
- Requires type checking
|
|
448
|
+
- Example: `return anyValue;` ❌
|
|
449
|
+
|
|
450
|
+
#### Promise Handling Rules
|
|
451
|
+
|
|
452
|
+
**`@typescript-eslint/no-floating-promises`** (✅💡💭)
|
|
453
|
+
|
|
454
|
+
- Requires Promise-like values to be handled
|
|
455
|
+
- Options: `ignoreVoid`, `ignoreIIFE`
|
|
456
|
+
- Example: `promiseFunction();` ❌ → `await promiseFunction();` ✅
|
|
457
|
+
|
|
458
|
+
**`@typescript-eslint/await-thenable`** (✅💡💭)
|
|
459
|
+
|
|
460
|
+
- Disallows awaiting non-Thenable values
|
|
461
|
+
- Requires type checking
|
|
462
|
+
- Example: `await 42;` ❌
|
|
463
|
+
|
|
464
|
+
**`@typescript-eslint/no-misused-promises`** (✅💡💭)
|
|
465
|
+
|
|
466
|
+
- Disallows Promises in places not designed to handle them
|
|
467
|
+
- Options: `checksConditionals`, `checksVoidReturn`, `checksSpreads`
|
|
468
|
+
- Example: `if (promise) { ... }` ❌
|
|
469
|
+
|
|
470
|
+
#### Code Quality Rules
|
|
471
|
+
|
|
472
|
+
**`@typescript-eslint/ban-ts-comment`** (✅💡)
|
|
473
|
+
|
|
474
|
+
- Controls `@ts-ignore`, `@ts-expect-error`, `@ts-nocheck`, `@ts-check`
|
|
475
|
+
- Options: `ts-expect-error`, `ts-ignore`, `ts-nocheck`, `ts-check`,
|
|
476
|
+
`minimumDescriptionLength`
|
|
477
|
+
- Example: `// @ts-ignore` ❌ → `// @ts-expect-error: reason` ✅
|
|
478
|
+
|
|
479
|
+
**`@typescript-eslint/no-unused-vars`** (✅🧱)
|
|
480
|
+
|
|
481
|
+
- Disallows unused variables
|
|
482
|
+
- Options: `args`, `varsIgnorePattern`, `caughtErrors`,
|
|
483
|
+
`destructuredArrayIgnorePattern`
|
|
484
|
+
- Example: `const unused = 1;` ❌
|
|
485
|
+
|
|
486
|
+
**`@typescript-eslint/explicit-function-return-type`**
|
|
487
|
+
|
|
488
|
+
- Requires explicit return types on functions
|
|
489
|
+
- Options: `allowExpressions`, `allowTypedFunctionExpressions`,
|
|
490
|
+
`allowHigherOrderFunctions`, `allowDirectConstAssertionInArrowFunctions`
|
|
491
|
+
- Example: `function foo() { return 1; }` ❌ →
|
|
492
|
+
`function foo(): number { return 1; }` ✅
|
|
493
|
+
|
|
494
|
+
#### Style Rules
|
|
495
|
+
|
|
496
|
+
**`@typescript-eslint/array-type`** (🎨🔧)
|
|
497
|
+
|
|
498
|
+
- Enforces consistent array type syntax
|
|
499
|
+
- Options: `default`, `readonly`
|
|
500
|
+
- Values: `array`, `array-simple`, `generic`, `array-simple`
|
|
501
|
+
- Example: `Array<number>` vs `number[]`
|
|
502
|
+
|
|
503
|
+
**`@typescript-eslint/consistent-type-definitions`** (🎨🔧)
|
|
504
|
+
|
|
505
|
+
- Enforces `interface` or `type` consistently
|
|
506
|
+
- Options: `prefer` (`interface` or `type`)
|
|
507
|
+
- Example: `type Foo = {}` vs `interface Foo {}`
|
|
508
|
+
|
|
509
|
+
**`@typescript-eslint/prefer-nullish-coalescing`** (🎨🔧💡💭)
|
|
510
|
+
|
|
511
|
+
- Enforces `??` over `||` for null/undefined
|
|
512
|
+
- Options: `ignoreConditionalTests`, `ignoreMixedLogicalExpressions`
|
|
513
|
+
- Example: `x || y` ❌ → `x ?? y` ✅
|
|
514
|
+
|
|
515
|
+
**`@typescript-eslint/prefer-optional-chain`** (🎨🔧💡💭)
|
|
516
|
+
|
|
517
|
+
- Enforces `?.` over `&&` chains
|
|
518
|
+
- Example: `obj && obj.prop` ❌ → `obj?.prop` ✅
|
|
519
|
+
|
|
520
|
+
### Extension Rules
|
|
521
|
+
|
|
522
|
+
These rules extend core ESLint rules with TypeScript support. **Disable the base
|
|
523
|
+
rule** when using the TypeScript version:
|
|
524
|
+
|
|
525
|
+
```javascript
|
|
526
|
+
rules: {
|
|
527
|
+
// Disable base rule
|
|
528
|
+
'no-unused-vars': 'off',
|
|
529
|
+
'no-shadow': 'off',
|
|
530
|
+
'no-use-before-define': 'off',
|
|
531
|
+
// Enable TS version
|
|
532
|
+
'@typescript-eslint/no-unused-vars': 'error',
|
|
533
|
+
'@typescript-eslint/no-shadow': 'error',
|
|
534
|
+
'@typescript-eslint/no-use-before-define': 'error',
|
|
535
|
+
}
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
Extension rules: `class-methods-use-this`, `consistent-return`,
|
|
539
|
+
`default-param-last`, `dot-notation`, `init-declarations`, `max-params`,
|
|
540
|
+
`no-array-constructor`, `no-dupe-class-members`, `no-empty-function`,
|
|
541
|
+
`no-implied-eval`, `no-invalid-this`, `no-loop-func`, `no-loss-of-precision`,
|
|
542
|
+
`no-redeclare`, `no-restricted-imports`, `no-shadow`, `no-unused-expressions`,
|
|
543
|
+
`no-unused-vars`, `no-use-before-define`, `no-useless-constructor`,
|
|
544
|
+
`prefer-destructuring`, `prefer-promise-reject-errors`, `require-await`
|
|
545
|
+
|
|
546
|
+
### Deprecated Rules
|
|
547
|
+
|
|
548
|
+
- `@typescript-eslint/prefer-ts-expect-error` (💀) - Use `ban-ts-comment`
|
|
549
|
+
instead
|
|
550
|
+
- `@typescript-eslint/sort-type-constituents` (💀) - Will be removed in future
|
|
551
|
+
version
|
|
552
|
+
- `@typescript-eslint/typedef` (💀) - Use `explicit-function-return-type` and
|
|
553
|
+
similar rules
|
|
554
|
+
|
|
555
|
+
### Rule Configuration Examples
|
|
556
|
+
|
|
557
|
+
```javascript
|
|
558
|
+
// Type safety
|
|
559
|
+
rules: {
|
|
560
|
+
'@typescript-eslint/no-explicit-any': ['error', { ignoreRestArgs: true }],
|
|
561
|
+
'@typescript-eslint/no-unsafe-assignment': 'error',
|
|
562
|
+
'@typescript-eslint/no-unsafe-call': 'error',
|
|
563
|
+
'@typescript-eslint/no-unsafe-member-access': 'error',
|
|
564
|
+
'@typescript-eslint/no-unsafe-return': 'error',
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// Promise handling
|
|
568
|
+
rules: {
|
|
569
|
+
'@typescript-eslint/no-floating-promises': ['error', { ignoreVoid: true }],
|
|
570
|
+
'@typescript-eslint/await-thenable': 'error',
|
|
571
|
+
'@typescript-eslint/no-misused-promises': ['error', {
|
|
572
|
+
checksConditionals: true,
|
|
573
|
+
checksVoidReturn: true,
|
|
574
|
+
}],
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
// Code quality
|
|
578
|
+
rules: {
|
|
579
|
+
'@typescript-eslint/ban-ts-comment': ['error', {
|
|
580
|
+
'ts-expect-error': 'allow-with-description',
|
|
581
|
+
'ts-ignore': true,
|
|
582
|
+
'ts-nocheck': true,
|
|
583
|
+
'ts-check': false,
|
|
584
|
+
minimumDescriptionLength: 10,
|
|
585
|
+
}],
|
|
586
|
+
'@typescript-eslint/no-unused-vars': ['error', {
|
|
587
|
+
argsIgnorePattern: '^_',
|
|
588
|
+
varsIgnorePattern: '^_',
|
|
589
|
+
}],
|
|
590
|
+
'@typescript-eslint/explicit-function-return-type': ['warn', {
|
|
591
|
+
allowExpressions: true,
|
|
592
|
+
allowTypedFunctionExpressions: true,
|
|
593
|
+
}],
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
// Style
|
|
597
|
+
rules: {
|
|
598
|
+
'@typescript-eslint/array-type': ['error', { default: 'array-simple' }],
|
|
599
|
+
'@typescript-eslint/consistent-type-definitions': ['error', 'interface'],
|
|
600
|
+
'@typescript-eslint/prefer-nullish-coalescing': 'error',
|
|
601
|
+
'@typescript-eslint/prefer-optional-chain': 'error',
|
|
602
|
+
}
|
|
603
|
+
```
|
|
604
|
+
|
|
605
|
+
## Migration v8→v9
|
|
606
|
+
|
|
607
|
+
| v8 | v9 |
|
|
608
|
+
| --------------- | ------------------------------- |
|
|
609
|
+
| `.eslintrc.*` | `eslint.config.js` |
|
|
610
|
+
| Cascading | No cascading |
|
|
611
|
+
| `.eslintignore` | `ignores` prop |
|
|
612
|
+
| `env` | `languageOptions.globals` |
|
|
613
|
+
| `parserOptions` | `languageOptions.parserOptions` |
|
|
614
|
+
| `extends` | Import+spread |
|
|
615
|
+
| `overrides` | Multiple config objects |
|
|
616
|
+
|
|
617
|
+
Tool: `npx @eslint/migrate-config`
|
|
618
|
+
|
|
619
|
+
## CLI
|
|
620
|
+
|
|
621
|
+
```bash
|
|
622
|
+
eslint [opts] [file|dir|glob]*
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
| Opt | Desc |
|
|
626
|
+
| -------------------- | ----------------------------------- |
|
|
627
|
+
| `--fix` | Auto-fix |
|
|
628
|
+
| `--fix-dry-run` | Preview |
|
|
629
|
+
| `--format <f>` | stylish,json,compact,unix,tap,junit |
|
|
630
|
+
| `--config <p>` | Config path |
|
|
631
|
+
| `--cache` | Cache |
|
|
632
|
+
| `--quiet` | Errors only |
|
|
633
|
+
| `--print-config <f>` | Debug |
|
|
634
|
+
| `--debug` | Verbose |
|
|
635
|
+
|
|
636
|
+
Exit: 0=ok, 1=errors, 2=fatal
|
|
637
|
+
|
|
638
|
+
## Formatters
|
|
639
|
+
|
|
640
|
+
Built-in: stylish(default),compact,json,unix,tap,junit Custom:
|
|
641
|
+
`module.exports=(results,data)=>results.map(r=>`${r.filePath}:${r.messages.length}`).join('\n');`
|
|
642
|
+
|
|
643
|
+
## Bulk Suppressions
|
|
644
|
+
|
|
645
|
+
```json
|
|
646
|
+
{ "suppressions": [{ "ruleId": "no-console", "files": ["legacy/**/*.js"] }] }
|
|
647
|
+
```
|
|
648
|
+
|
|
649
|
+
## Integrations
|
|
650
|
+
|
|
651
|
+
Editors: VSCode,WebStorm,Sublime,Vim,Emacs | Build:
|
|
652
|
+
Webpack,Rollup,Vite,Gulp,Grunt | CI: GH Actions,GitLab,Jenkins | Pre-commit:
|
|
653
|
+
Husky
|
|
654
|
+
|
|
655
|
+
## Debugging
|
|
656
|
+
|
|
657
|
+
```bash
|
|
658
|
+
eslint --print-config file.js # merged config
|
|
659
|
+
eslint --debug src/ # verbose
|
|
660
|
+
pnpm ls eslint-plugin-name # verify install
|
|
661
|
+
```
|
|
662
|
+
|
|
663
|
+
| Issue | Fix |
|
|
664
|
+
| ---------------------- | ------------------------------------------- |
|
|
665
|
+
| Config not found | Check path,auto_discover,filename |
|
|
666
|
+
| Plugin conflicts | Disable base configs,check versions |
|
|
667
|
+
| Rules not applying | Check extensions,names,patterns |
|
|
668
|
+
| Type-aware not working | Add project/projectService to parserOptions |
|
|
669
|
+
| Slow linting | Use projectService:true |
|
|
670
|
+
|
|
671
|
+
| Error | Fix |
|
|
672
|
+
| ------------------------------------ | ------------------------------------ |
|
|
673
|
+
| Cannot find module 'eslint-plugin-x' | `npm i -D eslint-plugin-x` |
|
|
674
|
+
| Parsing error | Check parser,ecmaVersion |
|
|
675
|
+
| Rule not defined | Check name,plugin loaded |
|
|
676
|
+
| context.getScope not function | Use `sourceCode.getScope(node)` (v9) |
|
|
677
|
+
| Parser requires project | Add project/projectService |
|
|
678
|
+
|
|
679
|
+
## Extending
|
|
680
|
+
|
|
681
|
+
### Custom Rule
|
|
682
|
+
|
|
683
|
+
```javascript
|
|
684
|
+
module.exports = {
|
|
685
|
+
meta: {
|
|
686
|
+
type: 'problem',
|
|
687
|
+
docs: { description: '...' },
|
|
688
|
+
fixable: 'code',
|
|
689
|
+
schema: [],
|
|
690
|
+
messages: { msg: '{{p}} err' },
|
|
691
|
+
},
|
|
692
|
+
create(ctx) {
|
|
693
|
+
return {
|
|
694
|
+
'CallExpr[callee.name="x"]'(n) {
|
|
695
|
+
ctx.report({ node: n, messageId: 'msg', data: { p: 'v' } });
|
|
696
|
+
},
|
|
697
|
+
};
|
|
698
|
+
},
|
|
699
|
+
};
|
|
700
|
+
```
|
|
701
|
+
|
|
702
|
+
### TS-Aware Rule
|
|
703
|
+
|
|
704
|
+
```javascript
|
|
705
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
706
|
+
const createRule = ESLintUtils.RuleCreator((n) => `url/${n}`);
|
|
707
|
+
export default createRule({
|
|
708
|
+
name: 'rule',
|
|
709
|
+
meta: {
|
|
710
|
+
type: 'problem',
|
|
711
|
+
docs: { description: '...', requiresTypeChecking: true },
|
|
712
|
+
messages: { e: 'err' },
|
|
713
|
+
schema: [],
|
|
714
|
+
},
|
|
715
|
+
defaultOptions: [],
|
|
716
|
+
create(ctx) {
|
|
717
|
+
const svc = ESLintUtils.getParserServices(ctx);
|
|
718
|
+
const chk = svc.program.getTypeChecker();
|
|
719
|
+
return {};
|
|
720
|
+
},
|
|
721
|
+
});
|
|
722
|
+
```
|
|
723
|
+
|
|
724
|
+
### Test Rules
|
|
725
|
+
|
|
726
|
+
```javascript
|
|
727
|
+
import { RuleTester } from '@typescript-eslint/rule-tester';
|
|
728
|
+
new RuleTester({
|
|
729
|
+
languageOptions: {
|
|
730
|
+
parser: '@typescript-eslint/parser',
|
|
731
|
+
parserOptions: { project: './tsconfig.json' },
|
|
732
|
+
},
|
|
733
|
+
}).run('rule', rule, { valid: [], invalid: [] });
|
|
734
|
+
```
|
|
735
|
+
|
|
736
|
+
### Processors
|
|
737
|
+
|
|
738
|
+
```javascript
|
|
739
|
+
module.exports = {
|
|
740
|
+
processors: {
|
|
741
|
+
'.md': {
|
|
742
|
+
preprocess(t, f) {
|
|
743
|
+
return [];
|
|
744
|
+
},
|
|
745
|
+
postprocess(m, f) {
|
|
746
|
+
return m[0];
|
|
747
|
+
},
|
|
748
|
+
supportsAutofix: true,
|
|
749
|
+
},
|
|
750
|
+
},
|
|
751
|
+
};
|
|
752
|
+
```
|
|
753
|
+
|
|
754
|
+
### Shareable Configs
|
|
755
|
+
|
|
756
|
+
Package: `eslint-config-{name}` → ref: `{name}`
|
|
757
|
+
|
|
758
|
+
```javascript
|
|
759
|
+
export default [{ rules: { 'no-console': 'error' } }];
|
|
760
|
+
```
|
|
761
|
+
|
|
762
|
+
## Node.js API
|
|
763
|
+
|
|
764
|
+
```javascript
|
|
765
|
+
import { ESLint } from 'eslint';
|
|
766
|
+
const e = new ESLint({ fix: true });
|
|
767
|
+
const r = await e.lintFiles(['src/**/*.js']);
|
|
768
|
+
await ESLint.outputFixes(r);
|
|
769
|
+
console.log((await e.loadFormatter('json')).format(r));
|
|
770
|
+
```
|
|
771
|
+
|
|
772
|
+
| Opt | Type | Desc |
|
|
773
|
+
| ---------- | ---- | ----------- |
|
|
774
|
+
| cwd | str | Working dir |
|
|
775
|
+
| baseConfig | obj | Base config |
|
|
776
|
+
| fix | bool | Apply fixes |
|
|
777
|
+
| cache | bool | Caching |
|
|
778
|
+
|
|
779
|
+
Methods: `lintFiles(patterns)→LintResult[]` | `lintText(code,{filePath})` |
|
|
780
|
+
`loadFormatter(name)` | `calculateConfigForFile(path)` | `isPathIgnored(path)` |
|
|
781
|
+
`ESLint.outputFixes(results)`
|
|
782
|
+
|
|
783
|
+
### LintResult
|
|
784
|
+
|
|
785
|
+
`{filePath,messages[],errorCount,warningCount,fixableErrorCount,fixableWarningCount}`
|
|
786
|
+
|
|
787
|
+
### Message
|
|
788
|
+
|
|
789
|
+
`{ruleId,severity:1|2,message,line,column,endLine?,endColumn?,fix?:{range,text}}`
|
|
790
|
+
|
|
791
|
+
## MCP Server
|
|
792
|
+
|
|
793
|
+
`npm i -g @eslint/mcp-server` — AI tool protocol for ESLint.
|
|
794
|
+
|
|
795
|
+
## Feature Flags
|
|
796
|
+
|
|
797
|
+
`ESLINT_FEATURE_FLAG=name eslint .` — experimental features.
|
|
798
|
+
|
|
799
|
+
## Packages
|
|
800
|
+
|
|
801
|
+
**Core**: `@typescript-eslint/eslint-plugin`(rules) |
|
|
802
|
+
`@typescript-eslint/parser` | `typescript-eslint`(main) **Dev**:
|
|
803
|
+
`@typescript-eslint/utils`(RuleCreator,getParserServices) |
|
|
804
|
+
`@typescript-eslint/rule-tester` **Infra**: `scope-manager` |
|
|
805
|
+
`typescript-estree`(AST) | `tsconfig-utils` | `type-utils` | `project-service`
|
|
806
|
+
**Migration**: `@typescript-eslint/eslint-plugin-tslint`
|
|
807
|
+
|
|
808
|
+
## TypeScript ESTree AST
|
|
809
|
+
|
|
810
|
+
Additional nodes:
|
|
811
|
+
`TSInterfaceDeclaration`,`TSTypeAliasDeclaration`,`TSEnumDeclaration`,`TSModuleDeclaration`,`TSDecorator`,`TSTypeParameter`
|
|
812
|
+
Spec: typescript-eslint.io/packages/typescript-estree/ast-spec
|
|
813
|
+
|
|
814
|
+
## Glossary
|
|
815
|
+
|
|
816
|
+
AST=code tree | Rule=pattern checker | Plugin=rules+processors+configs |
|
|
817
|
+
Parser=source→AST | Processor=extract JS from non-JS | Formatter=output format |
|
|
818
|
+
Severity=off/warn/error | Flat Config=v9 array | Legacy Config=v8 .eslintrc |
|
|
819
|
+
Extension Rule=TS replacing base | Type-Checked=needs type info | Project
|
|
820
|
+
Service=auto project detection | ESTree=JS AST format | TS ESTree=TS AST in
|
|
821
|
+
ESTree format
|
|
822
|
+
|
|
823
|
+
## Refs
|
|
824
|
+
|
|
825
|
+
eslint.org/docs | typescript-eslint.io | typescript-eslint.io/rules |
|
|
826
|
+
typescript-eslint.io/getting-started/typed-linting |
|
|
827
|
+
typescript-eslint.io/users/shared-configs
|