eslint-plugin-traceability 1.7.1 → 1.8.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.
Files changed (92) hide show
  1. package/CHANGELOG.md +82 -0
  2. package/README.md +72 -32
  3. package/docs/ci-cd-pipeline.md +224 -0
  4. package/docs/cli-integration.md +22 -0
  5. package/docs/code-quality-refactor-opportunities-2025-12-03.md +78 -0
  6. package/docs/config-presets.md +38 -0
  7. package/docs/conventional-commits-guide.md +185 -0
  8. package/docs/custom-rules-development-guide.md +659 -0
  9. package/docs/decisions/0001-allow-dynamic-require-for-built-plugins.md +26 -0
  10. package/docs/decisions/001-typescript-for-eslint-plugin.accepted.md +111 -0
  11. package/docs/decisions/002-jest-for-eslint-testing.accepted.md +137 -0
  12. package/docs/decisions/003-code-quality-ratcheting-plan.md +48 -0
  13. package/docs/decisions/004-automated-version-bumping-for-ci-cd.md +196 -0
  14. package/docs/decisions/005-github-actions-validation-tooling.accepted.md +144 -0
  15. package/docs/decisions/006-semantic-release-for-automated-publishing.accepted.md +227 -0
  16. package/docs/decisions/007-github-releases-over-changelog.accepted.md +216 -0
  17. package/docs/decisions/008-ci-audit-flags.accepted.md +60 -0
  18. package/docs/decisions/009-security-focused-lint-rules.accepted.md +64 -0
  19. package/docs/decisions/010-implements-annotation-for-multi-story-requirements.proposed.md +184 -0
  20. package/docs/decisions/adr-0001-console-usage-for-cli-guards.md +190 -0
  21. package/docs/decisions/adr-accept-dev-dep-risk-glob.md +40 -0
  22. package/docs/decisions/adr-commit-branch-tests.md +54 -0
  23. package/docs/decisions/adr-maintenance-cli-interface.md +140 -0
  24. package/docs/decisions/adr-pre-push-parity.md +112 -0
  25. package/docs/decisions/code-quality-ratcheting-plan.md +53 -0
  26. package/docs/dependency-health.md +238 -0
  27. package/docs/eslint-9-setup-guide.md +517 -0
  28. package/docs/eslint-plugin-development-guide.md +487 -0
  29. package/docs/functionality-coverage-2025-12-03.md +250 -0
  30. package/docs/jest-testing-guide.md +100 -0
  31. package/docs/rules/prefer-implements-annotation.md +219 -0
  32. package/docs/rules/require-branch-annotation.md +71 -0
  33. package/docs/rules/require-req-annotation.md +203 -0
  34. package/docs/rules/require-story-annotation.md +159 -0
  35. package/docs/rules/valid-annotation-format.md +418 -0
  36. package/docs/rules/valid-req-reference.md +153 -0
  37. package/docs/rules/valid-story-reference.md +120 -0
  38. package/docs/security-incidents/2025-11-17-glob-cli-incident.md +45 -0
  39. package/docs/security-incidents/2025-11-18-brace-expansion-redos.md +45 -0
  40. package/docs/security-incidents/2025-11-18-bundled-dev-deps-accepted-risk.md +93 -0
  41. package/docs/security-incidents/2025-11-18-tar-race-condition.md +43 -0
  42. package/docs/security-incidents/2025-12-03-dependency-health-review.md +58 -0
  43. package/docs/security-incidents/SECURITY-INCIDENT-2025-11-18-semantic-release-bundled-npm.known-error.md +104 -0
  44. package/docs/security-incidents/SECURITY-INCIDENT-TEMPLATE.md +37 -0
  45. package/docs/security-incidents/dependency-override-rationale.md +57 -0
  46. package/docs/security-incidents/dev-deps-high.json +116 -0
  47. package/docs/security-incidents/handling-procedure.md +54 -0
  48. package/docs/stories/001.0-DEV-PLUGIN-SETUP.story.md +92 -0
  49. package/docs/stories/002.0-DEV-ESLINT-CONFIG.story.md +82 -0
  50. package/docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md +112 -0
  51. package/docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md +153 -0
  52. package/docs/stories/005.0-DEV-ANNOTATION-VALIDATION.story.md +138 -0
  53. package/docs/stories/006.0-DEV-FILE-VALIDATION.story.md +144 -0
  54. package/docs/stories/007.0-DEV-ERROR-REPORTING.story.md +163 -0
  55. package/docs/stories/008.0-DEV-AUTO-FIX.story.md +150 -0
  56. package/docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md +117 -0
  57. package/docs/stories/010.0-DEV-DEEP-VALIDATION.story.md +124 -0
  58. package/docs/stories/010.1-DEV-CONFIGURABLE-PATTERNS.story.md +149 -0
  59. package/docs/stories/010.2-DEV-MULTI-STORY-SUPPORT.story.md +216 -0
  60. package/docs/stories/010.3-DEV-MIGRATE-TO-IMPLEMENTS.story.md +236 -0
  61. package/docs/stories/developer-story.map.md +120 -0
  62. package/docs/ts-jest-presets-guide.md +548 -0
  63. package/lib/src/maintenance/batch.d.ts +5 -0
  64. package/lib/src/maintenance/batch.js +5 -0
  65. package/lib/src/maintenance/cli.js +34 -212
  66. package/lib/src/maintenance/commands.d.ts +32 -0
  67. package/lib/src/maintenance/commands.js +139 -0
  68. package/lib/src/maintenance/detect.d.ts +2 -0
  69. package/lib/src/maintenance/detect.js +4 -0
  70. package/lib/src/maintenance/flags.d.ts +99 -0
  71. package/lib/src/maintenance/flags.js +121 -0
  72. package/lib/src/maintenance/report.d.ts +2 -0
  73. package/lib/src/maintenance/report.js +2 -0
  74. package/lib/src/maintenance/update.d.ts +4 -0
  75. package/lib/src/maintenance/update.js +4 -0
  76. package/lib/src/rules/helpers/require-story-io.d.ts +3 -0
  77. package/lib/src/rules/helpers/require-story-io.js +20 -6
  78. package/lib/src/rules/helpers/valid-annotation-options.js +15 -4
  79. package/lib/src/rules/helpers/valid-annotation-utils.js +5 -0
  80. package/lib/src/rules/helpers/valid-story-reference-helpers.d.ts +3 -4
  81. package/lib/src/utils/reqAnnotationDetection.d.ts +4 -1
  82. package/lib/src/utils/reqAnnotationDetection.js +43 -15
  83. package/lib/tests/maintenance/cli.test.js +89 -0
  84. package/lib/tests/rules/require-req-annotation.test.js +8 -1
  85. package/lib/tests/rules/require-story-annotation.test.js +9 -4
  86. package/lib/tests/utils/ts-language-options.d.ts +1 -7
  87. package/lib/tests/utils/ts-language-options.js +8 -5
  88. package/package.json +7 -3
  89. package/user-docs/api-reference.md +507 -0
  90. package/user-docs/eslint-9-setup-guide.md +639 -0
  91. package/user-docs/examples.md +74 -0
  92. package/user-docs/migration-guide.md +158 -0
@@ -0,0 +1,517 @@
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.