eslint-plugin-traceability 1.7.1 → 1.8.1
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 +82 -0
- package/README.md +76 -37
- package/SECURITY.md +132 -0
- package/lib/src/index.d.ts +6 -35
- package/lib/src/index.js +8 -5
- package/lib/src/maintenance/batch.d.ts +5 -0
- package/lib/src/maintenance/batch.js +5 -0
- package/lib/src/maintenance/cli.js +34 -212
- package/lib/src/maintenance/commands.d.ts +32 -0
- package/lib/src/maintenance/commands.js +139 -0
- package/lib/src/maintenance/detect.d.ts +2 -0
- package/lib/src/maintenance/detect.js +4 -0
- package/lib/src/maintenance/flags.d.ts +99 -0
- package/lib/src/maintenance/flags.js +121 -0
- package/lib/src/maintenance/report.d.ts +2 -0
- package/lib/src/maintenance/report.js +2 -0
- package/lib/src/maintenance/update.d.ts +4 -0
- package/lib/src/maintenance/update.js +4 -0
- package/lib/src/rules/helpers/require-story-io.d.ts +3 -0
- package/lib/src/rules/helpers/require-story-io.js +20 -6
- package/lib/src/rules/helpers/valid-annotation-options.js +15 -4
- package/lib/src/rules/helpers/valid-annotation-utils.js +5 -0
- package/lib/src/rules/helpers/valid-story-reference-helpers.d.ts +3 -4
- package/lib/src/utils/reqAnnotationDetection.d.ts +4 -1
- package/lib/src/utils/reqAnnotationDetection.js +43 -15
- 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/cli.test.js +89 -0
- package/lib/tests/plugin-default-export-and-configs.test.js +0 -2
- package/lib/tests/rules/prefer-implements-annotation.test.js +28 -0
- package/lib/tests/rules/require-req-annotation.test.js +8 -1
- package/lib/tests/rules/require-story-annotation.test.js +9 -4
- package/lib/tests/utils/ts-language-options.d.ts +1 -7
- package/lib/tests/utils/ts-language-options.js +8 -5
- package/package.json +11 -7
- package/user-docs/api-reference.md +527 -0
- package/user-docs/eslint-9-setup-guide.md +722 -0
- package/user-docs/examples.md +74 -0
- package/user-docs/migration-guide.md +174 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Examples
|
|
2
|
+
|
|
3
|
+
Created autonomously by [voder.ai](https://voder.ai).
|
|
4
|
+
Examples are written for the eslint-plugin-traceability 1.x series. For the latest published version and full release history, see GitHub Releases: <https://github.com/voder-ai/eslint-plugin-traceability/releases>.
|
|
5
|
+
|
|
6
|
+
This document provides runnable examples demonstrating how to use the `eslint-plugin-traceability` plugin in real-world scenarios.
|
|
7
|
+
|
|
8
|
+
## 1. ESLint Flat Config with Recommended Preset
|
|
9
|
+
|
|
10
|
+
Create an ESLint config file (`eslint.config.js`) at your project root:
|
|
11
|
+
|
|
12
|
+
```javascript
|
|
13
|
+
// eslint.config.js
|
|
14
|
+
import js from "@eslint/js";
|
|
15
|
+
import traceability from "eslint-plugin-traceability";
|
|
16
|
+
|
|
17
|
+
export default [js.configs.recommended, traceability.configs.recommended];
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Then run ESLint on your source files:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npx eslint "src/**/*.ts"
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 2. Using the Strict Preset
|
|
27
|
+
|
|
28
|
+
If you want to enforce all traceability rules (strict mode), update your config:
|
|
29
|
+
|
|
30
|
+
```javascript
|
|
31
|
+
// eslint.config.js
|
|
32
|
+
import js from "@eslint/js";
|
|
33
|
+
import traceability from "eslint-plugin-traceability";
|
|
34
|
+
|
|
35
|
+
export default [js.configs.recommended, traceability.configs.strict];
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Run ESLint the same way:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npx eslint "src/**/*.js"
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## 3. CLI Invocation Example
|
|
45
|
+
|
|
46
|
+
You can use the plugin without a config file by specifying rules inline:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npx eslint --no-eslintrc \
|
|
50
|
+
--rule "traceability/require-story-annotation:error" \
|
|
51
|
+
--rule "traceability/require-req-annotation:error" \
|
|
52
|
+
sample.js
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
- `--no-eslintrc` tells ESLint to ignore user configs.
|
|
56
|
+
- `--rule` options enable the traceability rules you need.
|
|
57
|
+
|
|
58
|
+
Replace `sample.js` with your JavaScript or TypeScript file.
|
|
59
|
+
|
|
60
|
+
## 4. Linting a Specific Directory
|
|
61
|
+
|
|
62
|
+
Add an npm script in your `package.json`:
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
"scripts": {
|
|
66
|
+
"lint:trace": "eslint \"src/**/*.{js,ts}\" --config eslint.config.js"
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Then run:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
npm run lint:trace
|
|
74
|
+
```
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# Migration Guide from v0.x to v1.x
|
|
2
|
+
|
|
3
|
+
Created autonomously by [voder.ai](https://voder.ai)
|
|
4
|
+
This guide covers migration from 0.x to the 1.x series of eslint-plugin-traceability. For the current 1.x release and detailed changelog, see GitHub Releases: <https://github.com/voder-ai/eslint-plugin-traceability/releases>.
|
|
5
|
+
|
|
6
|
+
This guide helps you migrate from versions 0.x of `eslint-plugin-traceability` to 1.x.
|
|
7
|
+
|
|
8
|
+
## 1. Update Dependency
|
|
9
|
+
|
|
10
|
+
Update your development dependency to the latest 1.x release:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install --save-dev eslint-plugin-traceability@^1.0.0
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Or with Yarn:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
yarn add --dev eslint-plugin-traceability@^1.0.0
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 2. ESLint Configuration Changes
|
|
23
|
+
|
|
24
|
+
- Version 1.x uses ESLint v9 flat config by default. If you currently use `.eslintrc.js`, you can continue using it, but consider migrating to the new flat config format for future upgrades.
|
|
25
|
+
- Update your ESLint config to load the plugin’s recommended settings:
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
// eslint.config.js (ESLint v9 flat config)
|
|
29
|
+
import traceability from "eslint-plugin-traceability";
|
|
30
|
+
|
|
31
|
+
export default [traceability.configs.recommended];
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## 3. New and Updated Rules
|
|
35
|
+
|
|
36
|
+
- `valid-story-reference` now enforces `.story.md` extensions strictly.
|
|
37
|
+
- `valid-req-reference` rejects path traversal (`../`) and absolute paths (`/etc/passwd`).
|
|
38
|
+
- `valid-annotation-format` enforces correct JSDoc traceability annotation syntax (`@story` and `@req` tags).
|
|
39
|
+
|
|
40
|
+
Review and update your existing annotations accordingly:
|
|
41
|
+
|
|
42
|
+
```diff
|
|
43
|
+
- /** @story docs/stories/001.0-DEV-PLUGIN-SETUP.md */
|
|
44
|
+
+ /** @story docs/stories/001.0-DEV-PLUGIN-SETUP.story.md */
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 3.1 Multi-story `@implements` annotations
|
|
48
|
+
|
|
49
|
+
Starting in v1.x, `eslint-plugin-traceability` supports an additional annotation form for integration code that implements requirements from multiple stories:
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
/**
|
|
53
|
+
* @implements docs/stories/010.2-DEV-MULTI-STORY-SUPPORT.story.md REQ-IMPLEMENTS-PARSE REQ-IMPLEMENTS-VALIDATE
|
|
54
|
+
*/
|
|
55
|
+
function integrate() {}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
You **do not** need to change existing, single-story annotations that already use `@story` and `@req`. Migration to `@implements` is only recommended when a function or module genuinely implements requirements from more than one story file.
|
|
59
|
+
|
|
60
|
+
#### Optional `prefer-implements-annotation` migration rule
|
|
61
|
+
|
|
62
|
+
For teams that want to gradually migrate from `@story` + `@req` to `@implements`, the plugin provides an optional rule: `traceability/prefer-implements-annotation`.
|
|
63
|
+
|
|
64
|
+
- This rule is **disabled by default** and is **not** included in any built-in presets.
|
|
65
|
+
- You can enable it with any standard ESLint severity (`"off"`, `"warn"`, or `"error"`) in your config, for example:
|
|
66
|
+
|
|
67
|
+
```js
|
|
68
|
+
// excerpt from eslint.config.js
|
|
69
|
+
{
|
|
70
|
+
rules: {
|
|
71
|
+
"traceability/prefer-implements-annotation": "warn",
|
|
72
|
+
},
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
- When enabled, it offers **conservative auto-fixes** that rewrite eligible `@story` + `@req` combinations into equivalent `@implements` lines, without attempting risky or ambiguous transformations.
|
|
77
|
+
- Detailed behavior, limitations, and examples are documented in `docs/rules/prefer-implements-annotation.md`.
|
|
78
|
+
|
|
79
|
+
#### When to keep `@story` + `@req`
|
|
80
|
+
|
|
81
|
+
Keep your current annotations if:
|
|
82
|
+
|
|
83
|
+
- Each function is tied to a single story file.
|
|
84
|
+
- All relevant requirements live in that story file.
|
|
85
|
+
- You do not need to distinguish which story a particular requirement ID comes from.
|
|
86
|
+
|
|
87
|
+
Example (no migration required):
|
|
88
|
+
|
|
89
|
+
```js
|
|
90
|
+
/**
|
|
91
|
+
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
92
|
+
* @req REQ-ANNOTATION-REQUIRED
|
|
93
|
+
*/
|
|
94
|
+
export function initAuth() {
|
|
95
|
+
// ...
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
#### When to introduce `@implements`
|
|
100
|
+
|
|
101
|
+
Adopt `@implements` for **multi-story integration** code, especially when:
|
|
102
|
+
|
|
103
|
+
- The function combines behavior governed by **multiple** stories.
|
|
104
|
+
- Requirement IDs are reused across stories (for example, `REQ-SHARED-ID` appears in more than one story file).
|
|
105
|
+
- You want deep validation (via `valid-req-reference`) to know **which story file** each requirement came from.
|
|
106
|
+
|
|
107
|
+
Before (single-story annotations trying to describe multi-story behavior):
|
|
108
|
+
|
|
109
|
+
```js
|
|
110
|
+
/**
|
|
111
|
+
* Apply age and security filters to rows.
|
|
112
|
+
* @story docs/stories/003.0-DEV-IDENTIFY-OUTDATED.story.md
|
|
113
|
+
* @req REQ-AGE-THRESHOLD
|
|
114
|
+
* @req REQ-OUTPUT
|
|
115
|
+
*/
|
|
116
|
+
export async function applyFilters(rows, options) {
|
|
117
|
+
// combined behavior
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
After (multi-story `@implements`), aligned with Story 010.2:
|
|
122
|
+
|
|
123
|
+
```js
|
|
124
|
+
/**
|
|
125
|
+
* Apply age and security filters to rows.
|
|
126
|
+
* @story docs/stories/003.0-DEV-IDENTIFY-OUTDATED.story.md
|
|
127
|
+
* @req REQ-AGE-THRESHOLD
|
|
128
|
+
* @req REQ-OUTPUT
|
|
129
|
+
*
|
|
130
|
+
* @implements docs/stories/003.0-DEV-IDENTIFY-OUTDATED.story.md REQ-AGE-THRESHOLD REQ-OUTPUT
|
|
131
|
+
* @implements docs/stories/004.0-DEV-FILTER-VULNERABLE-VERSIONS.story.md REQ-AUDIT-CHECK REQ-SAFE-ONLY
|
|
132
|
+
*/
|
|
133
|
+
export async function applyFilters(rows, options) {
|
|
134
|
+
// combined behavior
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
In the "after" example:
|
|
139
|
+
|
|
140
|
+
- `valid-annotation-format` ensures the `@implements` lines use a valid story path and requirement ID format.
|
|
141
|
+
- `valid-req-reference` validates that each requirement listed after `@implements` exists in the corresponding story file.
|
|
142
|
+
|
|
143
|
+
#### Mixed usage during migration
|
|
144
|
+
|
|
145
|
+
You can introduce `@implements` gradually without breaking existing code:
|
|
146
|
+
|
|
147
|
+
1. Leave existing `@story` and `@req` annotations in place.
|
|
148
|
+
2. Add `@implements` lines that group requirements by story file.
|
|
149
|
+
3. Run ESLint with `traceability/valid-annotation-format` and `traceability/valid-req-reference` enabled to confirm everything passes.
|
|
150
|
+
4. Optionally, once you are comfortable, standardize on using `@implements` for multi-story integration functions while keeping `@story` + `@req` for simple, single-story code.
|
|
151
|
+
|
|
152
|
+
For detailed semantics and edge cases (path validation, scoped requirement IDs, and multi-story fixtures), see the valid-annotation-format and valid-req-reference rule documentation and the multi-story support story in the project documentation.
|
|
153
|
+
|
|
154
|
+
## 4. Test and Validate
|
|
155
|
+
|
|
156
|
+
Run your test suite to confirm everything passes:
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
npm test
|
|
160
|
+
npm run lint -- --max-warnings=0
|
|
161
|
+
npm run format:check
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## 5. Update Documentation
|
|
165
|
+
|
|
166
|
+
If you have custom documentation or examples that reference old rule names or file paths, update them to match the new conventions introduced in v1.x.
|
|
167
|
+
|
|
168
|
+
## Security and Dependency Notes
|
|
169
|
+
|
|
170
|
+
Production dependency guarantees are enforced by CI scripts that run `npm audit --omit=dev --audit-level=high` and manage version changes via `dry-aged-deps`, with additional details on thresholds, review policies, and incident handling defined in the project's internal security and dependency health documentation.
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
If you encounter any issues during migration, please file an issue at https://github.com/voder-ai/eslint-plugin-traceability/issues.
|