eslint-plugin-traceability 1.8.0 → 1.8.2
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/CHANGELOG.md +5 -5
- package/README.md +28 -29
- package/SECURITY.md +135 -0
- package/lib/src/index.d.ts +6 -35
- package/lib/src/index.js +8 -5
- package/lib/src/maintenance/cli.js +12 -16
- package/lib/src/maintenance/detect.js +28 -1
- package/lib/src/rules/helpers/require-story-io.d.ts +2 -2
- package/lib/src/rules/helpers/require-story-io.js +13 -13
- package/lib/src/rules/helpers/valid-annotation-format-internal.d.ts +2 -2
- package/lib/src/rules/helpers/valid-annotation-format-internal.js +3 -3
- package/lib/src/rules/helpers/valid-annotation-utils.d.ts +5 -0
- package/lib/src/rules/helpers/valid-annotation-utils.js +43 -5
- package/lib/src/rules/helpers/valid-implements-utils.d.ts +11 -11
- package/lib/src/rules/helpers/valid-implements-utils.js +11 -11
- package/lib/src/rules/helpers/valid-story-reference-helpers.js +19 -0
- package/lib/src/rules/prefer-implements-annotation.d.ts +7 -7
- package/lib/src/rules/prefer-implements-annotation.js +21 -21
- package/lib/src/rules/valid-annotation-format.js +50 -24
- package/lib/src/rules/valid-req-reference.js +9 -9
- package/lib/src/utils/annotation-checker.js +3 -1
- package/lib/src/utils/reqAnnotationDetection.d.ts +2 -2
- package/lib/src/utils/reqAnnotationDetection.js +28 -28
- package/lib/tests/config/flat-config-presets-integration.test.d.ts +1 -0
- package/lib/tests/config/flat-config-presets-integration.test.js +75 -0
- package/lib/tests/maintenance/batch.test.js +11 -11
- package/lib/tests/maintenance/cli.test.js +34 -27
- package/lib/tests/maintenance/report.test.js +7 -7
- package/lib/tests/plugin-default-export-and-configs.test.js +0 -2
- package/lib/tests/rules/prefer-implements-annotation.test.js +48 -15
- package/lib/tests/rules/require-branch-annotation.test.js +15 -36
- package/lib/tests/rules/require-req-annotation.test.js +31 -104
- package/lib/tests/rules/require-story-annotation.test.js +3 -3
- package/lib/tests/rules/require-story-io-behavior.test.js +2 -7
- package/lib/tests/rules/require-story-io.edgecases.test.js +2 -7
- package/lib/tests/rules/require-story-visitors-edgecases.test.js +8 -8
- package/lib/tests/rules/valid-annotation-format.test.js +23 -23
- package/lib/tests/rules/valid-req-reference.test.js +9 -9
- package/lib/tests/rules/valid-story-reference.test.js +4 -43
- package/lib/tests/utils/annotation-checker.test.js +2 -6
- package/lib/tests/utils/fsTestHelpers.d.ts +7 -0
- package/lib/tests/utils/fsTestHelpers.js +26 -0
- package/lib/tests/utils/ioTestHelpers.d.ts +7 -0
- package/lib/tests/utils/ioTestHelpers.js +24 -0
- package/lib/tests/utils/temp-dir-helpers.d.ts +14 -0
- package/lib/tests/utils/temp-dir-helpers.js +61 -0
- package/package.json +8 -7
- package/user-docs/api-reference.md +37 -20
- package/user-docs/eslint-9-setup-guide.md +89 -6
- package/user-docs/migration-guide.md +37 -21
- package/docs/ci-cd-pipeline.md +0 -224
- package/docs/cli-integration.md +0 -22
- package/docs/code-quality-refactor-opportunities-2025-12-03.md +0 -78
- package/docs/config-presets.md +0 -38
- package/docs/conventional-commits-guide.md +0 -185
- package/docs/custom-rules-development-guide.md +0 -659
- package/docs/decisions/0001-allow-dynamic-require-for-built-plugins.md +0 -26
- package/docs/decisions/001-typescript-for-eslint-plugin.accepted.md +0 -111
- package/docs/decisions/002-jest-for-eslint-testing.accepted.md +0 -137
- package/docs/decisions/003-code-quality-ratcheting-plan.md +0 -48
- package/docs/decisions/004-automated-version-bumping-for-ci-cd.md +0 -196
- package/docs/decisions/005-github-actions-validation-tooling.accepted.md +0 -144
- package/docs/decisions/006-semantic-release-for-automated-publishing.accepted.md +0 -227
- package/docs/decisions/007-github-releases-over-changelog.accepted.md +0 -216
- package/docs/decisions/008-ci-audit-flags.accepted.md +0 -60
- package/docs/decisions/009-security-focused-lint-rules.accepted.md +0 -64
- package/docs/decisions/010-implements-annotation-for-multi-story-requirements.proposed.md +0 -184
- package/docs/decisions/adr-0001-console-usage-for-cli-guards.md +0 -190
- package/docs/decisions/adr-accept-dev-dep-risk-glob.md +0 -40
- package/docs/decisions/adr-commit-branch-tests.md +0 -54
- package/docs/decisions/adr-maintenance-cli-interface.md +0 -140
- package/docs/decisions/adr-pre-push-parity.md +0 -112
- package/docs/decisions/code-quality-ratcheting-plan.md +0 -53
- package/docs/dependency-health.md +0 -238
- package/docs/eslint-9-setup-guide.md +0 -517
- package/docs/eslint-plugin-development-guide.md +0 -487
- package/docs/functionality-coverage-2025-12-03.md +0 -250
- package/docs/jest-testing-guide.md +0 -100
- package/docs/rules/prefer-implements-annotation.md +0 -219
- package/docs/rules/require-branch-annotation.md +0 -71
- package/docs/rules/require-req-annotation.md +0 -203
- package/docs/rules/require-story-annotation.md +0 -159
- package/docs/rules/valid-annotation-format.md +0 -418
- package/docs/rules/valid-req-reference.md +0 -153
- package/docs/rules/valid-story-reference.md +0 -120
- package/docs/security-incidents/2025-11-17-glob-cli-incident.md +0 -45
- package/docs/security-incidents/2025-11-18-brace-expansion-redos.md +0 -45
- package/docs/security-incidents/2025-11-18-bundled-dev-deps-accepted-risk.md +0 -93
- package/docs/security-incidents/2025-11-18-tar-race-condition.md +0 -43
- package/docs/security-incidents/2025-12-03-dependency-health-review.md +0 -58
- package/docs/security-incidents/SECURITY-INCIDENT-2025-11-18-semantic-release-bundled-npm.known-error.md +0 -104
- package/docs/security-incidents/SECURITY-INCIDENT-TEMPLATE.md +0 -37
- package/docs/security-incidents/dependency-override-rationale.md +0 -57
- package/docs/security-incidents/dev-deps-high.json +0 -116
- package/docs/security-incidents/handling-procedure.md +0 -54
- package/docs/stories/001.0-DEV-PLUGIN-SETUP.story.md +0 -92
- package/docs/stories/002.0-DEV-ESLINT-CONFIG.story.md +0 -82
- package/docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md +0 -112
- package/docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md +0 -153
- package/docs/stories/005.0-DEV-ANNOTATION-VALIDATION.story.md +0 -138
- package/docs/stories/006.0-DEV-FILE-VALIDATION.story.md +0 -144
- package/docs/stories/007.0-DEV-ERROR-REPORTING.story.md +0 -163
- package/docs/stories/008.0-DEV-AUTO-FIX.story.md +0 -150
- package/docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md +0 -117
- package/docs/stories/010.0-DEV-DEEP-VALIDATION.story.md +0 -124
- package/docs/stories/010.1-DEV-CONFIGURABLE-PATTERNS.story.md +0 -149
- package/docs/stories/010.2-DEV-MULTI-STORY-SUPPORT.story.md +0 -216
- package/docs/stories/010.3-DEV-MIGRATE-TO-IMPLEMENTS.story.md +0 -236
- package/docs/stories/developer-story.map.md +0 -120
- package/docs/ts-jest-presets-guide.md +0 -548
|
@@ -1,517 +0,0 @@
|
|
|
1
|
-
# ESLint 9 Setup Guide
|
|
2
|
-
|
|
3
|
-
This guide shows how to properly set up ESLint 9 with flat configuration format. ESLint 9 uses flat config by default and has several important changes from previous versions.
|
|
4
|
-
|
|
5
|
-
## Table of Contents
|
|
6
|
-
|
|
7
|
-
- [Quick Setup](#quick-setup)
|
|
8
|
-
- [Configuration File Format](#configuration-file-format)
|
|
9
|
-
- [Common Configuration Patterns](#common-configuration-patterns)
|
|
10
|
-
- [Package.json Scripts](#packagejson-scripts)
|
|
11
|
-
- [TypeScript Integration](#typescript-integration)
|
|
12
|
-
- [Common Issues and Solutions](#common-issues-and-solutions)
|
|
13
|
-
- [Working Example](#working-example)
|
|
14
|
-
|
|
15
|
-
## Quick Setup
|
|
16
|
-
|
|
17
|
-
### 1. Install Dependencies
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
# Core ESLint v9
|
|
21
|
-
npm install --save-dev eslint@^9.39.1
|
|
22
|
-
|
|
23
|
-
# Recommended configurations
|
|
24
|
-
npm install --save-dev @eslint/js@^9.39.1
|
|
25
|
-
|
|
26
|
-
# For TypeScript projects
|
|
27
|
-
npm install --save-dev @typescript-eslint/parser@^8.0.0
|
|
28
|
-
npm install --save-dev @typescript-eslint/utils@^8.0.0
|
|
29
|
-
|
|
30
|
-
# For testing (if using Jest)
|
|
31
|
-
npm install --save-dev @types/eslint@^9.0.0
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
### 2. Create Configuration File
|
|
35
|
-
|
|
36
|
-
Create `eslint.config.js` (not `.eslintrc.*`):
|
|
37
|
-
|
|
38
|
-
```javascript
|
|
39
|
-
import js from "@eslint/js";
|
|
40
|
-
|
|
41
|
-
export default [
|
|
42
|
-
js.configs.recommended,
|
|
43
|
-
{
|
|
44
|
-
files: ["**/*.js", "**/*.mjs"],
|
|
45
|
-
rules: {
|
|
46
|
-
// Your custom rules here
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
];
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### 3. Add Scripts to package.json
|
|
53
|
-
|
|
54
|
-
```json
|
|
55
|
-
{
|
|
56
|
-
"scripts": {
|
|
57
|
-
"lint": "eslint .",
|
|
58
|
-
"lint:fix": "eslint . --fix"
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
### 4. Enable Traceability Plugin
|
|
64
|
-
|
|
65
|
-
To integrate the traceability plugin, update your `eslint.config.js` to include its recommended configuration:
|
|
66
|
-
|
|
67
|
-
```javascript
|
|
68
|
-
import js from "@eslint/js";
|
|
69
|
-
import traceability from "eslint-plugin-traceability";
|
|
70
|
-
|
|
71
|
-
export default [js.configs.recommended, traceability.configs.recommended];
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
## Configuration File Format
|
|
75
|
-
|
|
76
|
-
### Key Changes from ESLintRC
|
|
77
|
-
|
|
78
|
-
- **File name**: `eslint.config.js` (not `.eslintrc.*`)
|
|
79
|
-
- **Format**: Array of configuration objects (not single object)
|
|
80
|
-
- **Import style**: ES modules by default
|
|
81
|
-
- **No extends**: Use imports and spread syntax instead
|
|
82
|
-
|
|
83
|
-
### Basic Structure
|
|
84
|
-
|
|
85
|
-
```javascript
|
|
86
|
-
// eslint.config.js
|
|
87
|
-
import js from "@eslint/js";
|
|
88
|
-
|
|
89
|
-
export default [
|
|
90
|
-
// Apply to all files
|
|
91
|
-
js.configs.recommended,
|
|
92
|
-
|
|
93
|
-
// Specific configuration objects
|
|
94
|
-
{
|
|
95
|
-
files: ["**/*.js"], // File patterns
|
|
96
|
-
languageOptions: {
|
|
97
|
-
ecmaVersion: 2024,
|
|
98
|
-
sourceType: "module",
|
|
99
|
-
},
|
|
100
|
-
rules: {
|
|
101
|
-
// Rule configurations
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
|
|
105
|
-
// Ignore patterns
|
|
106
|
-
{
|
|
107
|
-
ignores: ["dist/**", "build/**", "node_modules/**"],
|
|
108
|
-
},
|
|
109
|
-
];
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
## Common Configuration Patterns
|
|
113
|
-
|
|
114
|
-
### 1. JavaScript Only Project
|
|
115
|
-
|
|
116
|
-
```javascript
|
|
117
|
-
// eslint.config.js
|
|
118
|
-
import js from "@eslint/js";
|
|
119
|
-
|
|
120
|
-
export default [
|
|
121
|
-
js.configs.recommended,
|
|
122
|
-
{
|
|
123
|
-
files: ["**/*.js", "**/*.mjs"],
|
|
124
|
-
languageOptions: {
|
|
125
|
-
ecmaVersion: 2024,
|
|
126
|
-
sourceType: "module",
|
|
127
|
-
},
|
|
128
|
-
rules: {
|
|
129
|
-
"no-unused-vars": "error",
|
|
130
|
-
"no-console": "warn",
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
ignores: ["dist/**", "build/**"],
|
|
135
|
-
},
|
|
136
|
-
];
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
### 2. TypeScript Project
|
|
140
|
-
|
|
141
|
-
```javascript
|
|
142
|
-
// eslint.config.js
|
|
143
|
-
import js from "@eslint/js";
|
|
144
|
-
import typescriptParser from "@typescript-eslint/parser";
|
|
145
|
-
|
|
146
|
-
export default [
|
|
147
|
-
js.configs.recommended,
|
|
148
|
-
{
|
|
149
|
-
files: ["**/*.ts", "**/*.tsx"],
|
|
150
|
-
languageOptions: {
|
|
151
|
-
parser: typescriptParser,
|
|
152
|
-
parserOptions: {
|
|
153
|
-
project: "./tsconfig.json",
|
|
154
|
-
tsconfigRootDir: import.meta.dirname,
|
|
155
|
-
ecmaVersion: 2024,
|
|
156
|
-
sourceType: "module",
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
rules: {
|
|
160
|
-
"@typescript-eslint/no-unused-vars": "error",
|
|
161
|
-
},
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
files: ["**/*.js", "**/*.mjs"],
|
|
165
|
-
languageOptions: {
|
|
166
|
-
ecmaVersion: 2024,
|
|
167
|
-
sourceType: "module",
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
];
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
### 3. Node.js Configuration Files (CommonJS)
|
|
174
|
-
|
|
175
|
-
```javascript
|
|
176
|
-
// eslint.config.js
|
|
177
|
-
export default [
|
|
178
|
-
{
|
|
179
|
-
// Config files that use CommonJS
|
|
180
|
-
files: ["*.config.js", "*.config.mjs", "jest.config.js"],
|
|
181
|
-
languageOptions: {
|
|
182
|
-
ecmaVersion: 2024,
|
|
183
|
-
sourceType: "commonjs",
|
|
184
|
-
globals: {
|
|
185
|
-
require: "readonly",
|
|
186
|
-
module: "readonly",
|
|
187
|
-
exports: "readonly",
|
|
188
|
-
__dirname: "readonly",
|
|
189
|
-
__filename: "readonly",
|
|
190
|
-
console: "readonly",
|
|
191
|
-
process: "readonly",
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
},
|
|
195
|
-
];
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
### 4. Test Files (Jest/Vitest)
|
|
199
|
-
|
|
200
|
-
```javascript
|
|
201
|
-
// eslint.config.js
|
|
202
|
-
export default [
|
|
203
|
-
{
|
|
204
|
-
files: [
|
|
205
|
-
"**/*.test.{js,ts}",
|
|
206
|
-
"**/__tests__/**/*.{js,ts}",
|
|
207
|
-
"**/tests/**/*.{js,ts}",
|
|
208
|
-
],
|
|
209
|
-
languageOptions: {
|
|
210
|
-
globals: {
|
|
211
|
-
describe: "readonly",
|
|
212
|
-
it: "readonly",
|
|
213
|
-
test: "readonly",
|
|
214
|
-
expect: "readonly",
|
|
215
|
-
beforeEach: "readonly",
|
|
216
|
-
afterEach: "readonly",
|
|
217
|
-
beforeAll: "readonly",
|
|
218
|
-
afterAll: "readonly",
|
|
219
|
-
jest: "readonly",
|
|
220
|
-
vi: "readonly", // for Vitest
|
|
221
|
-
},
|
|
222
|
-
},
|
|
223
|
-
},
|
|
224
|
-
];
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
## Package.json Scripts
|
|
228
|
-
|
|
229
|
-
### Recommended Scripts
|
|
230
|
-
|
|
231
|
-
```json
|
|
232
|
-
{
|
|
233
|
-
"scripts": {
|
|
234
|
-
"lint": "eslint .",
|
|
235
|
-
"lint:fix": "eslint . --fix",
|
|
236
|
-
"lint:check": "eslint . --max-warnings 0"
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
### For Plugin Development (with Build Step)
|
|
242
|
-
|
|
243
|
-
```json
|
|
244
|
-
{
|
|
245
|
-
"scripts": {
|
|
246
|
-
"prelint": "npm run build",
|
|
247
|
-
"build": "tsc",
|
|
248
|
-
"lint": "eslint .",
|
|
249
|
-
"lint:fix": "eslint . --fix"
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
## TypeScript Integration
|
|
255
|
-
|
|
256
|
-
### Parser Configuration
|
|
257
|
-
|
|
258
|
-
```javascript
|
|
259
|
-
// eslint.config.js
|
|
260
|
-
import typescriptParser from "@typescript-eslint/parser";
|
|
261
|
-
|
|
262
|
-
export default [
|
|
263
|
-
{
|
|
264
|
-
files: ["**/*.ts", "**/*.tsx"],
|
|
265
|
-
languageOptions: {
|
|
266
|
-
parser: typescriptParser, // Import the parser object directly
|
|
267
|
-
parserOptions: {
|
|
268
|
-
project: "./tsconfig.json",
|
|
269
|
-
tsconfigRootDir: import.meta.dirname, // Use import.meta.dirname in ESM
|
|
270
|
-
ecmaVersion: 2024,
|
|
271
|
-
sourceType: "module",
|
|
272
|
-
},
|
|
273
|
-
},
|
|
274
|
-
},
|
|
275
|
-
];
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
### Common TypeScript Rules
|
|
279
|
-
|
|
280
|
-
```javascript
|
|
281
|
-
export default [
|
|
282
|
-
{
|
|
283
|
-
files: ["**/*.ts", "**/*.tsx"],
|
|
284
|
-
rules: {
|
|
285
|
-
"@typescript-eslint/no-unused-vars": "error",
|
|
286
|
-
"@typescript-eslint/explicit-function-return-type": "warn",
|
|
287
|
-
"@typescript-eslint/no-explicit-any": "warn",
|
|
288
|
-
"@typescript-eslint/prefer-const": "error",
|
|
289
|
-
},
|
|
290
|
-
},
|
|
291
|
-
];
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
## Common Issues and Solutions
|
|
295
|
-
|
|
296
|
-
### Issue: "Expected object with parse() method"
|
|
297
|
-
|
|
298
|
-
**Problem**: Using `require.resolve()` for parser
|
|
299
|
-
|
|
300
|
-
```javascript
|
|
301
|
-
// ❌ Wrong
|
|
302
|
-
languageOptions: {
|
|
303
|
-
parser: require.resolve("@typescript-eslint/parser");
|
|
304
|
-
}
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
**Solution**: Import parser directly
|
|
308
|
-
|
|
309
|
-
```javascript
|
|
310
|
-
// ✅ Correct
|
|
311
|
-
import typescriptParser from "@typescript-eslint/parser";
|
|
312
|
-
|
|
313
|
-
languageOptions: {
|
|
314
|
-
parser: typescriptParser;
|
|
315
|
-
}
|
|
316
|
-
```
|
|
317
|
-
|
|
318
|
-
### Issue: "eslint:recommended" not working
|
|
319
|
-
|
|
320
|
-
**Problem**: Using string reference
|
|
321
|
-
|
|
322
|
-
```javascript
|
|
323
|
-
// ❌ Wrong
|
|
324
|
-
export default ["eslint:recommended"];
|
|
325
|
-
```
|
|
326
|
-
|
|
327
|
-
**Solution**: Import from @eslint/js
|
|
328
|
-
|
|
329
|
-
```javascript
|
|
330
|
-
// ✅ Correct
|
|
331
|
-
import js from "@eslint/js";
|
|
332
|
-
|
|
333
|
-
export default [js.configs.recommended];
|
|
334
|
-
```
|
|
335
|
-
|
|
336
|
-
### Issue: CLI flags not working
|
|
337
|
-
|
|
338
|
-
**Problem**: Using deprecated flags
|
|
339
|
-
|
|
340
|
-
```bash
|
|
341
|
-
# ❌ Wrong (deprecated in flat config)
|
|
342
|
-
eslint src --ext .ts --config eslint.config.js
|
|
343
|
-
```
|
|
344
|
-
|
|
345
|
-
**Solution**: Use file patterns in config
|
|
346
|
-
|
|
347
|
-
```bash
|
|
348
|
-
# ✅ Correct
|
|
349
|
-
eslint .
|
|
350
|
-
```
|
|
351
|
-
|
|
352
|
-
### Issue: Globals not defined
|
|
353
|
-
|
|
354
|
-
**Problem**: Missing environment globals
|
|
355
|
-
|
|
356
|
-
```javascript
|
|
357
|
-
// ❌ Wrong - globals not defined
|
|
358
|
-
export default [
|
|
359
|
-
{
|
|
360
|
-
files: ["**/*.js"],
|
|
361
|
-
// Missing globals for Node.js/browser
|
|
362
|
-
},
|
|
363
|
-
];
|
|
364
|
-
```
|
|
365
|
-
|
|
366
|
-
**Solution**: Define globals explicitly
|
|
367
|
-
|
|
368
|
-
```javascript
|
|
369
|
-
// ✅ Correct
|
|
370
|
-
export default [
|
|
371
|
-
{
|
|
372
|
-
files: ["**/*.js"],
|
|
373
|
-
languageOptions: {
|
|
374
|
-
globals: {
|
|
375
|
-
console: "readonly",
|
|
376
|
-
process: "readonly",
|
|
377
|
-
Buffer: "readonly",
|
|
378
|
-
// etc.
|
|
379
|
-
},
|
|
380
|
-
},
|
|
381
|
-
},
|
|
382
|
-
];
|
|
383
|
-
```
|
|
384
|
-
|
|
385
|
-
## Working Example
|
|
386
|
-
|
|
387
|
-
Here's a complete working configuration for a TypeScript ESLint plugin project:
|
|
388
|
-
|
|
389
|
-
```javascript
|
|
390
|
-
// eslint.config.js
|
|
391
|
-
import js from "@eslint/js";
|
|
392
|
-
import typescriptParser from "@typescript-eslint/parser";
|
|
393
|
-
|
|
394
|
-
// Conditional plugin loading (for plugin development)
|
|
395
|
-
let plugin;
|
|
396
|
-
try {
|
|
397
|
-
plugin = await import("./lib/index.js");
|
|
398
|
-
} catch {
|
|
399
|
-
console.warn("Plugin not built yet, skipping traceability rules");
|
|
400
|
-
plugin = {};
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
export default [
|
|
404
|
-
js.configs.recommended,
|
|
405
|
-
{
|
|
406
|
-
// Node.js config files (CommonJS)
|
|
407
|
-
files: ["*.config.js", "*.config.mjs", "jest.config.js"],
|
|
408
|
-
languageOptions: {
|
|
409
|
-
ecmaVersion: 2024,
|
|
410
|
-
sourceType: "commonjs",
|
|
411
|
-
globals: {
|
|
412
|
-
require: "readonly",
|
|
413
|
-
module: "readonly",
|
|
414
|
-
exports: "readonly",
|
|
415
|
-
__dirname: "readonly",
|
|
416
|
-
__filename: "readonly",
|
|
417
|
-
console: "readonly",
|
|
418
|
-
process: "readonly",
|
|
419
|
-
},
|
|
420
|
-
},
|
|
421
|
-
},
|
|
422
|
-
{
|
|
423
|
-
// TypeScript files
|
|
424
|
-
files: ["**/*.ts", "**/*.tsx"],
|
|
425
|
-
languageOptions: {
|
|
426
|
-
parser: typescriptParser,
|
|
427
|
-
parserOptions: {
|
|
428
|
-
project: "./tsconfig.json",
|
|
429
|
-
tsconfigRootDir: import.meta.dirname,
|
|
430
|
-
ecmaVersion: 2024,
|
|
431
|
-
sourceType: "module",
|
|
432
|
-
},
|
|
433
|
-
},
|
|
434
|
-
plugins: {
|
|
435
|
-
...(plugin.rules ? { traceability: plugin } : {}),
|
|
436
|
-
},
|
|
437
|
-
rules: {
|
|
438
|
-
"@typescript-eslint/no-unused-vars": "error",
|
|
439
|
-
},
|
|
440
|
-
},
|
|
441
|
-
{
|
|
442
|
-
// JavaScript files
|
|
443
|
-
files: ["**/*.js", "**/*.mjs"],
|
|
444
|
-
languageOptions: {
|
|
445
|
-
ecmaVersion: 2024,
|
|
446
|
-
sourceType: "module",
|
|
447
|
-
},
|
|
448
|
-
plugins: {
|
|
449
|
-
...(plugin.rules ? { traceability: plugin } : {}),
|
|
450
|
-
},
|
|
451
|
-
},
|
|
452
|
-
{
|
|
453
|
-
// Test files
|
|
454
|
-
files: [
|
|
455
|
-
"**/*.test.{js,ts}",
|
|
456
|
-
"**/__tests__/**/*.{js,ts}",
|
|
457
|
-
"**/tests/**/*.{js,ts}",
|
|
458
|
-
],
|
|
459
|
-
languageOptions: {
|
|
460
|
-
globals: {
|
|
461
|
-
describe: "readonly",
|
|
462
|
-
it: "readonly",
|
|
463
|
-
test: "readonly",
|
|
464
|
-
expect: "readonly",
|
|
465
|
-
beforeEach: "readonly",
|
|
466
|
-
afterEach: "readonly",
|
|
467
|
-
beforeAll: "readonly",
|
|
468
|
-
afterAll: "readonly",
|
|
469
|
-
jest: "readonly",
|
|
470
|
-
},
|
|
471
|
-
},
|
|
472
|
-
},
|
|
473
|
-
{
|
|
474
|
-
// Ignore patterns
|
|
475
|
-
ignores: [
|
|
476
|
-
"lib/**",
|
|
477
|
-
"dist/**",
|
|
478
|
-
"build/**",
|
|
479
|
-
"node_modules/**",
|
|
480
|
-
"coverage/**",
|
|
481
|
-
],
|
|
482
|
-
},
|
|
483
|
-
];
|
|
484
|
-
```
|
|
485
|
-
|
|
486
|
-
### Corresponding package.json:
|
|
487
|
-
|
|
488
|
-
```json
|
|
489
|
-
{
|
|
490
|
-
"scripts": {
|
|
491
|
-
"prelint": "npm run build",
|
|
492
|
-
"build": "tsc",
|
|
493
|
-
"lint": "eslint .",
|
|
494
|
-
"lint:fix": "eslint . --fix",
|
|
495
|
-
"type-check": "tsc --noEmit"
|
|
496
|
-
},
|
|
497
|
-
"devDependencies": {
|
|
498
|
-
"@eslint/js": "^9.39.1",
|
|
499
|
-
"@typescript-eslint/parser": "^8.46.4",
|
|
500
|
-
"@typescript-eslint/utils": "^8.46.4",
|
|
501
|
-
"eslint": "^9.39.1",
|
|
502
|
-
"typescript": "^5.9.3"
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
```
|
|
506
|
-
|
|
507
|
-
## Key Takeaways
|
|
508
|
-
|
|
509
|
-
1. **Use `eslint.config.js`**, not `.eslintrc.*`
|
|
510
|
-
2. **Import configurations**, don't use string references
|
|
511
|
-
3. **Import parsers directly**, don't use `require.resolve()`
|
|
512
|
-
4. **Define globals explicitly** for different environments
|
|
513
|
-
5. **Use file patterns** instead of CLI `--ext` flags
|
|
514
|
-
6. **Structure as array of objects**, each targeting specific file types
|
|
515
|
-
7. **Use `ignores`** instead of `.eslintignore` files
|
|
516
|
-
|
|
517
|
-
This setup provides a solid foundation for ESLint 9 that works reliably across different project types and environments.
|