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,250 @@
1
+ # Functionality Coverage Assessment (2025-12-03)
2
+
3
+ This document summarizes the current implementation status of the main traceability stories and their requirements, based on the existing rules, maintenance CLI, and automated tests.
4
+
5
+ ## Scope
6
+
7
+ Stories reviewed:
8
+
9
+ - 001.0-DEV-PLUGIN-SETUP
10
+ - 002.0-DEV-ESLINT-CONFIG
11
+ - 003.0-DEV-FUNCTION-ANNOTATIONS
12
+ - 004.0-DEV-BRANCH-ANNOTATIONS
13
+ - 005.0-DEV-ANNOTATION-VALIDATION
14
+ - 006.0-DEV-FILE-VALIDATION
15
+ - 007.0-DEV-ERROR-REPORTING
16
+ - 008.0-DEV-AUTO-FIX
17
+ - 009.0-DEV-MAINTENANCE-TOOLS
18
+ - 010.0-DEV-DEEP-VALIDATION
19
+ - 010.1-DEV-CONFIGURABLE-PATTERNS
20
+ - 010.2-DEV-MULTI-STORY-SUPPORT
21
+ - 010.3-DEV-MIGRATE-TO-IMPLEMENTS
22
+
23
+ ## Story-level implementation summary
24
+
25
+ ### 001.0-DEV-PLUGIN-SETUP
26
+
27
+ **Status:** Substantially implemented; some checklist items in the story remain unchecked but are covered in code and tests.
28
+
29
+ Evidence:
30
+
31
+ - `src/index.ts` exports `rules`, `configs`, and `maintenance`, satisfying `REQ-PLUGIN-STRUCTURE`, `REQ-RULE-REGISTRY`, and `REQ-MAINTENANCE-API-EXPORT`.
32
+ - `tests/plugin-setup.test.ts`, `tests/plugin-default-export-and-configs.test.ts`, `tests/plugin-setup-error.test.ts`, and `tests/integration/cli-integration.test.ts` validate plugin export shape, config presets, and error handling.
33
+ - User-facing setup docs: `README.md`, `user-docs/eslint-9-setup-guide.md`, and `user-docs/examples.md` provide configuration guidance.
34
+
35
+ Notable gaps vs. story checkboxes:
36
+
37
+ - Story acceptance criteria checkboxes for **Core Functionality**, **Quality Standards**, **Integration**, **User Experience**, and **Documentation** are not explicitly marked as done in the story file, but the implementation and tests indicate they are effectively satisfied.
38
+
39
+ ### 002.0-DEV-ESLINT-CONFIG
40
+
41
+ **Status:** Implemented via flat-config presets and documented, but story checkboxes remain unchecked.
42
+
43
+ Evidence:
44
+
45
+ - `src/index.ts` defines `configs.recommended` and `configs.strict` using `TRACEABILITY_RULE_SEVERITIES` mapping, satisfying `REQ-CONFIG-PRESETS`, `REQ-FLAT-CONFIG`, and `REQ-CONFIG-SYSTEM`.
46
+ - `docs/config-presets.md` and `user-docs/eslint-9-setup-guide.md` document preset usage and flat config examples.
47
+ - `tests/plugin-default-export-and-configs.test.ts` asserts rule presence and severity mapping, including `prefer-implements-annotation`.
48
+
49
+ Notable gaps vs. story checkboxes:
50
+
51
+ - Acceptance criteria in `002.0-DEV-ESLINT-CONFIG.story.md` are unchecked, but implemented behavior and tests demonstrate that configuration presets and flat-config integration work.
52
+ - There are no targeted tests for configuration error handling beyond schema-based validation in individual rules (e.g., `require-branch-annotation` and `valid-annotation-format`).
53
+
54
+ ### 003.0-DEV-FUNCTION-ANNOTATIONS
55
+
56
+ **Status:** Implemented and well tested.
57
+
58
+ Evidence:
59
+
60
+ - `src/rules/require-story-annotation.ts` and `src/rules/require-req-annotation.ts` implement function-level enforcement with shared detection logic via `require-story-helpers`.
61
+ - Tests under `tests/rules/require-story-*.test.ts` and `tests/rules/require-req-annotation.test.ts` cover detection of supported node types, configurable scope, and `exportPriority`.
62
+ - CLI integration tests (`tests/integration/cli-integration.test.ts`) confirm rule behavior via ESLint CLI.
63
+
64
+ Gaps:
65
+
66
+ - Story `003.0` DoD checklist has unchecked items for "Code reviewed", "Rule integrated into plugin configuration presets", and "Performance tested" even though presets include the rules and Jest coverage is high. There is no dedicated performance testing beyond normal CI, which matches the story note.
67
+
68
+ ### 004.0-DEV-BRANCH-ANNOTATIONS
69
+
70
+ **Status:** Implemented and tested, but story acceptance criteria remain unchecked.
71
+
72
+ Evidence:
73
+
74
+ - `src/rules/require-branch-annotation.ts` with helpers in `src/utils/branch-annotation-helpers.ts` enforces `@story`/`@req` on configurable branch types.
75
+ - `tests/rules/require-branch-annotation.test.ts` verifies behavior across branch types, configuration, error messaging, and auto-fix output.
76
+ - Story requirements `REQ-BRANCH-DETECTION` and `REQ-CONFIGURABLE-SCOPE` are clearly covered by code and tests.
77
+
78
+ Gaps:
79
+
80
+ - Story-level checkboxes for **Core Functionality**, **Quality Standards**, etc. are not updated in the markdown.
81
+ - No explicit performance testing beyond normal CI runs.
82
+
83
+ ### 005.0-DEV-ANNOTATION-VALIDATION
84
+
85
+ **Status:** Implemented and heavily tested.
86
+
87
+ Evidence:
88
+
89
+ - `src/rules/valid-annotation-format.ts` and helpers implement syntax/format validation for `@story`, `@req`, and `@implements`, including multiline handling and configurable patterns.
90
+ - `tests/rules/valid-annotation-format.test.ts` covers happy path and error cases, multiline annotations, custom patterns, and configuration error behavior.
91
+
92
+ Gaps:
93
+
94
+ - Story DoD items for "Code reviewed" and "Performance tested" remain unchecked, but behavior and coverage are complete.
95
+
96
+ ### 006.0-DEV-FILE-VALIDATION
97
+
98
+ **Status:** Implemented and tested; some DoD items left unchecked.
99
+
100
+ Evidence:
101
+
102
+ - `src/rules/valid-story-reference.ts` and `src/utils/storyReferenceUtils.ts` implement existence checks, path resolution, security validation, project boundary enforcement, and configuration (`storyDirectories`, `allowAbsolutePaths`, `requireStoryExtension`).
103
+ - `tests/rules/valid-story-reference.test.ts` validates core behavior, configuration variants, project boundary logic, and error handling for filesystem failures.
104
+
105
+ Gaps:
106
+
107
+ - Story DoD still marks "Code reviewed" and full performance testing as incomplete.
108
+
109
+ ### 007.0-DEV-ERROR-REPORTING
110
+
111
+ **Status:** Implemented across rules with shared conventions; acceptance criteria and DoD fully checked in story.
112
+
113
+ Evidence:
114
+
115
+ - Messages in `require-story-annotation`, `require-req-annotation`, `require-branch-annotation`, `valid-annotation-format`, `valid-story-reference`, and `valid-req-reference` align with documented patterns.
116
+ - `tests/rules/error-reporting.test.ts` and per-rule tests assert message contents and placeholders.
117
+
118
+ Gaps:
119
+
120
+ - None identified at functionality level.
121
+
122
+ ### 008.0-DEV-AUTO-FIX
123
+
124
+ **Status:** Partially implemented according to story narrative; acceptance criteria in the story are mostly checked but not all DoD items are complete.
125
+
126
+ Evidence:
127
+
128
+ - Auto-fix for missing `@story` on functions is implemented in `require-story-annotation` and tested in `tests/rules/auto-fix-behavior-008.test.ts`.
129
+ - Auto-fix for simple `@story` path suffix issues is implemented via `valid-annotation-format` helpers and covered in tests.
130
+
131
+ Gaps:
132
+
133
+ - Story DoD items for "Code reviewed", "Tests written and passing" (not ticked even though tests exist), and deployment/acceptance are left unchecked.
134
+ - Configurable auto-fix templates and selective fix toggles are explicitly out of scope in the current implementation but still listed as future requirements in the story.
135
+
136
+ ### 009.0-DEV-MAINTENANCE-TOOLS
137
+
138
+ **Status:** Core maintenance API and CLI behaviors are implemented and tested; story acceptance checkboxes are currently unchecked.
139
+
140
+ Evidence:
141
+
142
+ - Maintenance modules: `src/maintenance/detect.ts`, `src/maintenance/update.ts`, `src/maintenance/report.ts`, `src/maintenance/batch.ts`, and `src/maintenance/index.ts` implement `detectStaleAnnotations`, `updateAnnotationReferences`, `batchUpdateAnnotations`, `verifyAnnotations`, and `generateMaintenanceReport`.
143
+ - CLI: `src/maintenance/cli.ts` exposes `detect`, `verify`, `report`, and `update` commands with documented flags; tests in `tests/maintenance/cli.test.ts` cover exit codes, dry-run, JSON output, and update behavior.
144
+ - Additional tests in `tests/maintenance/*.test.ts` confirm behavior of individual operations.
145
+ - User docs in `user-docs/api-reference.md` and README describe the CLI and API.
146
+
147
+ Gaps:
148
+
149
+ - Story acceptance checkboxes for **Core Functionality**, **Quality Standards**, **Integration**, **User Experience**, **Error Handling**, and **Documentation** have not been updated despite matching implementation.
150
+ - Advanced features mentioned in implementation notes (e.g., file system watching) are not implemented and are treated as future enhancements.
151
+
152
+ ### 010.0-DEV-DEEP-VALIDATION
153
+
154
+ **Status:** Partially implemented.
155
+
156
+ Evidence:
157
+
158
+ - `src/rules/valid-req-reference.ts` implements deep validation of `@req` and `@implements` references against story file content, including caching and path safety.
159
+ - `tests/rules/valid-req-reference.test.ts` covers missing requirements, bullet-list formats, `@implements` references, and path security for both `@story` and `@implements`.
160
+
161
+ Gaps:
162
+
163
+ - Story acceptance criteria for handling varied requirement formats, sections, and error handling are only partially reflected in implementation; e.g., current regex-based extraction looks for `REQ-...` anywhere, which handles common formats but does not parse document sections explicitly.
164
+ - Story DoD items for code review, testing, documentation, and deployment remain unchecked.
165
+
166
+ ### 010.1-DEV-CONFIGURABLE-PATTERNS
167
+
168
+ **Status:** Implemented at the rule level, with tests and documentation; story checkboxes partially unchecked.
169
+
170
+ Evidence:
171
+
172
+ - `valid-annotation-format` supports nested and flat configuration for `story` and `req` patterns and examples via `valid-annotation-options` helpers.
173
+ - `tests/rules/valid-annotation-format.test.ts` thoroughly covers nested vs. flat options, precedence, invalid regex handling, and example propagation into error messages.
174
+ - `docs/rules/valid-annotation-format.md` documents configuration options and behavior.
175
+
176
+ Gaps:
177
+
178
+ - Story DoD fields for schema validation and integration testing are partially left unchecked, though tests indicate behavior is covered.
179
+
180
+ ### 010.2-DEV-MULTI-STORY-SUPPORT
181
+
182
+ **Status:** Implemented at annotation and deep-validation levels; some DoD items still open.
183
+
184
+ Evidence:
185
+
186
+ - `valid-annotation-format` parses and validates `@implements` annotation syntax.
187
+ - `valid-req-reference` validates `@implements` requirement IDs against referenced story files, allowing shared IDs across stories.
188
+ - `tests/rules/valid-annotation-format.test.ts` and `tests/rules/valid-req-reference.test.ts` cover `@implements` syntax, error cases, and multi-story behavior.
189
+ - `docs/rules/valid-annotation-format.md` describes `@implements` format and usage.
190
+
191
+ Gaps:
192
+
193
+ - Story `010.2` DoD items for code review, full test completion, backward-compat checks, and integration with a real codebase are not ticked.
194
+
195
+ ### 010.3-DEV-MIGRATE-TO-IMPLEMENTS
196
+
197
+ **Status:** Implemented as an opt-in rule with auto-fix; several DoD items marked incomplete in story.
198
+
199
+ Evidence:
200
+
201
+ - `src/rules/prefer-implements-annotation.ts` implements detection, diagnostics, and conservative auto-fix transforming simple `@story` + `@req` blocks into `@implements`.
202
+ - `tests/rules/prefer-implements-annotation.test.ts` validates basic recommendations, multi-story detection, mixed-usage behavior, and auto-fix outputs.
203
+ - Rule documentation: `docs/rules/prefer-implements-annotation.md` and `user-docs/migration-guide.md`.
204
+
205
+ Gaps:
206
+
207
+ - Story DoD items for code review, applying auto-fix to a real repository (e.g., dry-aged-deps), and some validation bullets remain unchecked.
208
+
209
+ ## Cross-cutting observations
210
+
211
+ - Many stories have acceptance criteria and Definition of Done checkboxes that are not aligned with the current implementation reality. Functionality and tests are generally ahead of the story metadata.
212
+ - Core plugin rules and maintenance tools are wired into presets and CLI and covered by both unit tests and integration tests (via ESLint CLI and the `traceability-maint` CLI).
213
+ - Deep validation (`valid-req-reference`) has a narrower implementation than the full aspirational scope of Story 010.0 but still satisfies the main user-visible goal of preventing references to non-existent requirement IDs.
214
+
215
+ ## High-level gaps and mismatches
216
+
217
+ 1. **Stories vs. Implementation Status**
218
+ - Several stories (001.0, 002.0, 004.0, 005.0, 006.0, 008.0, 009.0, 010.0, 010.1, 010.2, 010.3) show unchecked acceptance criteria or DoD items even though the corresponding functionality and tests exist.
219
+ - This is primarily a documentation/traceability misalignment rather than missing code.
220
+
221
+ 2. **Deep Validation Scope (010.0)**
222
+ - Implementation uses a regex-based extraction (`/REQ-[A-Z0-9-]+/g`) over the entire story file, which:
223
+ - Works for the common patterns in `docs/stories/*.story.md` and test fixtures.
224
+ - Does not explicitly parse sections or structured requirement blocks as described in the story.
225
+ - Story requirements about section-specific parsing and multiple requirement formats are only partially realized.
226
+
227
+ 3. **Maintenance Tools Advanced Features (009.0)**
228
+ - The story mentions file system watching and potential Git hook integration; current code exposes CLI and batch functions but does not implement watching or direct hook integration.
229
+ - From a functionality standpoint, the main user story about batch update and detection is satisfied, but advanced scenarios are left for future work.
230
+
231
+ 4. **Auto-fix Configurability (008.0, 010.3)**
232
+ - Auto-fix is implemented for specific, safe scenarios:
233
+ - Adding missing `@story` annotations.
234
+ - Correcting simple `.story.md` suffix issues.
235
+ - Migrating simple `@story` + `@req` blocks to `@implements`.
236
+ - Story mentions configurable templates and selective fix toggles that are not yet implemented.
237
+
238
+ 5. **ESLint Config Story (002.0)**
239
+ - While presets and docs exist, the story leaves acceptance criteria unchecked and there are no dedicated negative tests for misconfiguration at the plugin or preset level beyond per-rule schema checks.
240
+
241
+ ## Summary
242
+
243
+ - **Core traceability rules (003.00.3) and maintenance tools (009.0) are functionally implemented and well tested.**
244
+ - **Most remaining discrepancies are between story checklists and actual implementation, plus a few aspirational requirements (deep parsing, FS watching, configurable templates) that have been consciously scoped out.**
245
+ - **No major gaps were found where a documented user-facing behavior is entirely missing from the code or tests.**
246
+
247
+ This assessment should be used as a baseline for any future work that aims to either:
248
+
249
+ - Bring the story markdown files up to date with the current implementation status, and/or
250
+ - Extend implementation to cover the remaining aspirational requirements (deep markdown parsing, advanced maintenance automation, configurable auto-fix templates).
@@ -0,0 +1,100 @@
1
+ # Jest Testing Guide
2
+
3
+ This guide covers testing practices and configuration for the eslint-plugin-traceability project.
4
+
5
+ ## Traceability in Test Output
6
+
7
+ ### Viewing Story and Requirement References
8
+
9
+ By default, Jest's standard output only shows file-level test results without displaying individual test descriptions or traceability annotations. To see the full traceability information including story references and requirement IDs, you must use the `--verbose` option.
10
+
11
+ **Standard output (limited visibility):**
12
+
13
+ ```bash
14
+ npm test
15
+ ```
16
+
17
+ Shows only:
18
+
19
+ ```
20
+ PASS tests/maintenance/batch.test.ts
21
+ PASS tests/rules/require-branch-annotation.test.ts
22
+ ```
23
+
24
+ **Verbose output (full traceability):**
25
+
26
+ ```bash
27
+ npm test -- --verbose
28
+ ```
29
+
30
+ Shows detailed test descriptions with traceability annotations:
31
+
32
+ ```
33
+ PASS tests/maintenance/batch.test.ts
34
+ batchUpdateAnnotations (Story 009.0-DEV-MAINTENANCE-TOOLS)
35
+ ✓ [REQ-MAINT-BATCH] should return 0 when no mappings applied (6 ms)
36
+ verifyAnnotations (Story 009.0-DEV-MAINTENANCE-TOOLS)
37
+ ✓ [REQ-MAINT-VERIFY] should return true when annotations are valid
38
+
39
+ PASS tests/rules/require-branch-annotation.test.ts
40
+ Require Branch Annotation Rule (Story 004.0-DEV-BRANCH-ANNOTATIONS)
41
+ require-branch-annotation
42
+ valid
43
+ ✓ [REQ-BRANCH-DETECTION] valid if-statement with annotations (4 ms)
44
+ ```
45
+
46
+ ### Test Structure Requirements
47
+
48
+ All tests in this project follow a specific structure to support traceability:
49
+
50
+ 1. **File-level annotations** at the top of each test file:
51
+
52
+ ```typescript
53
+ /**
54
+ * Tests for: docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
55
+ * @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
56
+ * @req REQ-MAINT-BATCH - Perform batch updates
57
+ * @req REQ-MAINT-VERIFY - Verify annotation references
58
+ */
59
+ ```
60
+
61
+ 2. **Describe blocks** that reference the story:
62
+
63
+ ```typescript
64
+ describe('batchUpdateAnnotations (Story 009.0-DEV-MAINTENANCE-TOOLS)', () => {
65
+ ```
66
+
67
+ 3. **Test cases** that reference specific requirements:
68
+ ```typescript
69
+ it('[REQ-MAINT-BATCH] should return 0 when no mappings applied', () => {
70
+ ```
71
+
72
+ ### Running Tests for Traceability Review
73
+
74
+ When reviewing test coverage for specific stories or requirements:
75
+
76
+ - **For development/debugging**: Use `npm test -- --verbose` to see all traceability information
77
+ - **For CI/CD pipelines**: Standard `npm test` provides sufficient pass/fail information
78
+ - **For coverage analysis**: Both modes provide the same coverage statistics
79
+
80
+ ### Best Practices
81
+
82
+ 1. **Always include story references** in describe blocks to make them visible in verbose output
83
+ 2. **Prefix test descriptions with requirement IDs** in square brackets (e.g., `[REQ-MAINT-BATCH]`)
84
+ 3. **Use meaningful test descriptions** that clearly indicate what requirement is being tested
85
+ 4. **Run with --verbose during development** to verify traceability annotations are properly displayed
86
+
87
+ ## Configuration
88
+
89
+ The project's Jest configuration is defined in `jest.config.js` and includes:
90
+
91
+ - Coverage reporting
92
+ - TypeScript support via ts-jest
93
+ - Test file patterns
94
+ - CI-friendly options (--ci --bail --coverage)
95
+
96
+ ## Related Documentation
97
+
98
+ - [Story Files](stories/) - User story definitions
99
+ - [ESLint Plugin Development Guide](eslint-plugin-development-guide.md) - General development practices
100
+ - [Decision Records](decisions/) - Architectural decisions including Jest adoption
@@ -0,0 +1,219 @@
1
+ # prefer-implements-annotation
2
+
3
+ Optional migration rule that recommends converting legacy `@story` + `@req` annotations to the newer `@implements` format.
4
+
5
+ @story docs/stories/010.3-DEV-MIGRATE-TO-IMPLEMENTS.story.md
6
+ @req REQ-OPTIONAL-WARNING - Emit configurable recommendation diagnostics for legacy @story/@req usage
7
+ @req REQ-MULTI-STORY-DETECT - Detect multi-story patterns and mixed usage that cannot be auto-fixed yet
8
+ @req REQ-AUTO-FIX - Provide safe auto-fix support for simple single-story @story + @req blocks
9
+ @req REQ-SINGLE-STORY-FIX - Automatically convert single-story @story/@req blocks to @implements
10
+ @req REQ-PRESERVE-FORMAT - Preserve surrounding comment structure and non-traceability tags during auto-fix
11
+ @req REQ-VALID-OUTPUT - Ensure auto-fixed output always passes existing validation rules
12
+ @req REQ-BACKWARDS-COMPAT-VALIDATION - Ensure legacy @story/@req annotations remain valid when the rule is disabled
13
+
14
+ > Note: Auto-fix is intentionally conservative and only applies to simple, clearly single-story legacy blocks. More complex patterns (multi-story, mixed `@implements`, or unusual formatting) are detected but **not** auto-fixed and will still require manual migration.
15
+
16
+ ## Rule Details
17
+
18
+ This rule is designed as an **opt-in migration aid** for teams that want to gradually standardize on the `@implements` annotation while keeping existing `@story` + `@req` annotations fully supported.
19
+
20
+ When enabled, it scans block/JSDoc comments and:
21
+
22
+ - Detects legacy blocks that contain both `@story` and `@req` but **no** `@implements` lines
23
+ - Emits a `preferImplements` recommendation diagnostic for those blocks (and auto-fixes eligible ones to `@implements` when run with `--fix`)
24
+ - Detects mixed usage where a single comment combines `@story`/`@req` and `@implements`
25
+ - Detects multiple distinct `@story` paths in the same block (likely multi-story integration)
26
+
27
+ It **does not** change how any of the validation rules behave:
28
+
29
+ - `valid-annotation-format` continues to validate `@story`, `@req`, and `@implements` formats
30
+ - `valid-req-reference` continues to perform deep validation of requirements against story files
31
+ - `require-story-annotation` and `require-req-annotation` continue to enforce presence of annotations as before
32
+
33
+ This separation ensures that turning the rule on/off only affects **recommendations**, not validation correctness.
34
+
35
+ ## Options
36
+
37
+ The rule currently does not accept any options. You control its behavior with normal ESLint severity configuration:
38
+
39
+ ```js
40
+ // eslint.config.js (flat config)
41
+ import traceability from "eslint-plugin-traceability";
42
+
43
+ export default [
44
+ traceability.configs.recommended,
45
+ {
46
+ rules: {
47
+ // Default: off (no recommendations)
48
+ "traceability/prefer-implements-annotation": "off",
49
+
50
+ // Or enable as warnings
51
+ // "traceability/prefer-implements-annotation": "warn",
52
+
53
+ // Or enforce as errors
54
+ // "traceability/prefer-implements-annotation": "error",
55
+ },
56
+ },
57
+ ];
58
+ ```
59
+
60
+ - `"off"` (default) – rule is disabled; no additional diagnostics
61
+ - `"warn"` – surfaces recommendations without failing builds
62
+ - `"error"` – treats recommendations as errors for strict migration phases
63
+
64
+ ## Behavior
65
+
66
+ ### Legacy `@story` + `@req` blocks
67
+
68
+ When the rule encounters a block/JSDoc comment that contains **both** `@story` and `@req` lines and **no** `@implements` lines, it reports:
69
+
70
+ - **Message ID:** `preferImplements`
71
+ - **Text:**
72
+ > Consider using @implements instead of @story + @req for clearer traceability. Run ESLint with --fix to auto-convert.
73
+
74
+ For simple single-story blocks, running ESLint with `--fix` will automatically rewrite the comment to use `@implements` while preserving the rest of the comment content.
75
+
76
+ Example (will trigger `preferImplements` and is auto-fixable):
77
+
78
+ ```js
79
+ /**
80
+ * Calculate age in days since publish date.
81
+ * @story docs/stories/002.0-DEV-FETCH-AVAILABLE-VERSIONS.story.md
82
+ * @req REQ-AGE-CALC
83
+ */
84
+ export function calculateAgeInDays(publishDate) {}
85
+ ```
86
+
87
+ Auto-fix output:
88
+
89
+ ```js
90
+ /**
91
+ * Calculate age in days since publish date.
92
+ * @implements docs/stories/002.0-DEV-FETCH-AVAILABLE-VERSIONS.story.md REQ-AGE-CALC
93
+ */
94
+ export function calculateAgeInDays(publishDate) {}
95
+ ```
96
+
97
+ ### Auto-fix limitations
98
+
99
+ Auto-fix is deliberately limited to straightforward cases. It will **not** rewrite:
100
+
101
+ - Comments with multiple distinct `@story` annotations (multi-story integration blocks)
102
+ - Comments that already contain any `@implements` annotations (mixed legacy/modern usage)
103
+ - Comments where `@story` or `@req` lines are unusually formatted or split across lines in ways that make the intent ambiguous
104
+
105
+ In these cases the rule still reports diagnostics, but leaves the comment unchanged so you can migrate it manually.
106
+
107
+ ### Mixed `@story` / `@req` / `@implements` usage
108
+
109
+ If the rule sees a comment that already contains `@implements` alongside legacy `@story` / `@req`, it cannot know the intended final layout. In this case it reports:
110
+
111
+ - **Message ID:** `cannotAutoFix`
112
+ - **Data:** `{ reason: "comment mixes @story/@req with existing @implements annotations" }`
113
+
114
+ Example:
115
+
116
+ ```js
117
+ /**
118
+ * @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
119
+ * @req REQ-ANNOTATION-REQUIRED
120
+ * @implements docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md REQ-ANNOTATION-REQUIRED
121
+ */
122
+ function mixed() {}
123
+ ```
124
+
125
+ The rule warns that this block requires **manual** restructuring into clear `@implements` lines.
126
+
127
+ ### Multiple `@story` annotations in a single block
128
+
129
+ When a single comment block contains more than one distinct `@story` path, the rule treats it as a likely multi-story integration block and reports:
130
+
131
+ - **Message ID:** `multiStoryDetected`
132
+ - **Text:**
133
+ > Multiple @story annotations detected in the same comment block. Manually convert to separate @implements lines.
134
+
135
+ Example:
136
+
137
+ ```js
138
+ /**
139
+ * @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
140
+ * @req REQ-ANNOTATION-REQUIRED
141
+ * @story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md
142
+ * @req REQ-BRANCH-DETECTION
143
+ */
144
+ function multiStory() {}
145
+ ```
146
+
147
+ This is a strong indicator that the code should use separate `@implements` lines for each story.
148
+
149
+ ### What the rule intentionally ignores
150
+
151
+ To preserve backward compatibility and avoid noisy diagnostics, the rule intentionally **does not** report on:
152
+
153
+ - Comments that contain only `@story` or only `@req` (no migration opportunity)
154
+ - Comments that contain only `@implements` (already in the target format)
155
+ - Line comments with annotations (`// @story ...`) – the first iteration focuses on JSDoc/block comments, which are the primary migration targets
156
+
157
+ Validation for all of these cases remains the responsibility of the existing rules (`valid-annotation-format`, `require-story-annotation`, `require-req-annotation`, `valid-req-reference`).
158
+
159
+ ## Examples
160
+
161
+ ### Correct (rule disabled or satisfied)
162
+
163
+ ```js
164
+ /**
165
+ * @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
166
+ * @req REQ-ANNOTATION-REQUIRED
167
+ */
168
+ function legacyButValid() {}
169
+
170
+ /**
171
+ * @implements docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md REQ-ANNOTATION-REQUIRED
172
+ */
173
+ function alreadyMigrated() {}
174
+ ```
175
+
176
+ ### Reported: single-story legacy block
177
+
178
+ ```js
179
+ /**
180
+ * @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
181
+ * @req REQ-ANNOTATION-REQUIRED
182
+ */
183
+ function legacy() {}
184
+ // -> preferImplements (eligible blocks will be auto-fixed to @implements when running with --fix)
185
+ ```
186
+
187
+ ### Reported: mixed legacy and `@implements`
188
+
189
+ ```js
190
+ /**
191
+ * @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
192
+ * @req REQ-ANNOTATION-REQUIRED
193
+ * @implements docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md REQ-ANNOTATION-REQUIRED
194
+ */
195
+ function mixed() {}
196
+ // -> cannotAutoFix (manual intervention required)
197
+ ```
198
+
199
+ ### Reported: multiple distinct `@story` paths
200
+
201
+ ```js
202
+ /**
203
+ * @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
204
+ * @req REQ-ANNOTATION-REQUIRED
205
+ * @story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md
206
+ * @req REQ-BRANCH-DETECTION
207
+ */
208
+ function multiStory() {}
209
+ // -> multiStoryDetected (multi-story integration needs manual @implements mapping)
210
+ ```
211
+
212
+ ## Relationship to other rules
213
+
214
+ - Use `prefer-implements-annotation` to **guide migration** from legacy annotations to `@implements`.
215
+ - Use `valid-annotation-format` to enforce syntax and format for `@story`, `@req`, and `@implements`.
216
+ - Use `valid-req-reference` to validate that each `@req` and `@implements` requirement ID exists in the referenced story file.
217
+ - Keep `require-story-annotation` and `require-req-annotation` enabled to ensure functions remain fully annotated during and after migration.
218
+
219
+ Together, these rules support a smooth, incremental transition from purely `@story` + `@req` annotations to richer, multi-story `@implements` annotations without breaking existing projects.
@@ -0,0 +1,71 @@
1
+ # require-branch-annotation
2
+
3
+ Ensures that significant code branches (if/else, switch cases, loops, try/catch) have `@story` and `@req` annotations for traceability.
4
+
5
+ @story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md
6
+ @req REQ-BRANCH-DETECTION - Detect significant code branches for traceability annotations
7
+ @req REQ-CONFIGURABLE-SCOPE - Allow configuration of branch types for annotation enforcement
8
+
9
+ ## Rule Details
10
+
11
+ This rule checks for JSDoc or inline comments immediately preceding significant code branches and ensures both `@story` and `@req` annotations are present.
12
+
13
+ ### Options
14
+
15
+ Property: `branchTypes` (array of AST node type strings)
16
+ Default: `["IfStatement", "SwitchCase", "TryStatement", "CatchClause", "ForStatement", "ForOfStatement", "ForInStatement", "WhileStatement", "DoWhileStatement"]` (DEFAULT_BRANCH_TYPES)
17
+ Allowed values: `["IfStatement", "SwitchCase", "TryStatement", "CatchClause", "ForStatement", "ForOfStatement", "ForInStatement", "WhileStatement", "DoWhileStatement"]`
18
+ If an invalid branch type is provided, the rule will report a configuration error with a message: Value "<invalid>" should be equal to one of the allowed values.
19
+
20
+ Example (.eslintrc.js):
21
+
22
+ ```js
23
+ module.exports = {
24
+ rules: {
25
+ "traceability/require-branch-annotation": [
26
+ "error",
27
+ {
28
+ branchTypes: ["IfStatement", "ForStatement"],
29
+ },
30
+ ],
31
+ },
32
+ };
33
+ ```
34
+
35
+ ### Examples
36
+
37
+ #### Correct
38
+
39
+ ```js
40
+ // @story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md
41
+ // @req REQ-BRANCH-DETECTION
42
+ if (error) {
43
+ handleError();
44
+ }
45
+ ```
46
+
47
+ #### Incorrect
48
+
49
+ ```js
50
+ if (error) {
51
+ handleError();
52
+ }
53
+ ```
54
+
55
+ #### Invalid Configuration
56
+
57
+ ```js
58
+ // .eslintrc.js
59
+ module.exports = {
60
+ rules: {
61
+ "traceability/require-branch-annotation": [
62
+ "error",
63
+ {
64
+ branchTypes: ["IfStatement", "InvalidType"],
65
+ },
66
+ ],
67
+ },
68
+ };
69
+
70
+ // Error: Value "InvalidType" should be equal to one of the allowed values.
71
+ ```