eslint-plugin-traceability 1.11.0 → 1.11.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 +3 -4
- package/README.md +2 -2
- package/lib/src/maintenance/flags.js +111 -25
- package/lib/src/rules/helpers/require-story-core.d.ts +59 -0
- package/lib/src/rules/helpers/require-story-core.js +91 -1
- package/lib/src/rules/helpers/require-story-helpers.d.ts +2 -47
- package/lib/src/rules/helpers/require-story-helpers.js +135 -126
- package/lib/src/rules/helpers/require-story-io.js +51 -31
- package/lib/src/rules/helpers/valid-annotation-options.d.ts +3 -0
- package/lib/src/rules/helpers/valid-annotation-options.js +64 -21
- package/lib/src/utils/annotation-checker.js +31 -7
- package/lib/src/utils/reqAnnotationDetection.js +36 -22
- package/lib/tests/cli-error-handling.test.js +1 -0
- package/lib/tests/config/eslint-config-validation.test.d.ts +8 -0
- package/lib/tests/config/eslint-config-validation.test.js +8 -0
- package/lib/tests/config/flat-config-presets-integration.test.js +1 -3
- package/lib/tests/config/require-story-annotation-config.test.d.ts +9 -0
- package/lib/tests/config/require-story-annotation-config.test.js +9 -0
- package/lib/tests/integration/cli-integration.test.js +9 -1
- package/lib/tests/maintenance/batch.test.js +1 -0
- package/lib/tests/maintenance/cli.test.js +1 -0
- package/lib/tests/maintenance/detect-isolated.test.js +1 -0
- package/lib/tests/maintenance/detect.test.js +1 -0
- package/lib/tests/maintenance/index.test.js +1 -0
- package/lib/tests/maintenance/report.test.js +1 -0
- package/lib/tests/maintenance/update-isolated.test.js +1 -0
- package/lib/tests/maintenance/update.test.js +1 -0
- package/lib/tests/plugin-default-export-and-configs.test.js +2 -0
- package/lib/tests/plugin-setup-error.test.d.ts +1 -0
- package/lib/tests/plugin-setup-error.test.js +1 -0
- package/lib/tests/plugin-setup.test.js +1 -1
- package/lib/tests/rules/auto-fix-behavior-008.test.js +16 -0
- package/lib/tests/rules/error-reporting.test.js +1 -0
- package/lib/tests/rules/prefer-implements-annotation.test.js +8 -0
- package/lib/tests/rules/require-branch-annotation.test.js +2 -0
- package/lib/tests/rules/require-story-core-edgecases.test.js +1 -0
- package/lib/tests/rules/require-story-core.autofix.test.js +1 -0
- package/lib/tests/rules/require-story-core.test.js +1 -0
- package/lib/tests/rules/require-story-helpers-edgecases.test.d.ts +1 -0
- package/lib/tests/rules/require-story-helpers-edgecases.test.js +1 -0
- package/lib/tests/rules/require-story-helpers.test.js +4 -3
- package/lib/tests/rules/require-story-io-behavior.test.d.ts +1 -0
- package/lib/tests/rules/require-story-io-behavior.test.js +1 -0
- package/lib/tests/rules/require-story-io.edgecases.test.d.ts +1 -0
- package/lib/tests/rules/require-story-io.edgecases.test.js +1 -0
- package/lib/tests/rules/require-story-visitors-edgecases.test.d.ts +1 -0
- package/lib/tests/rules/require-story-visitors-edgecases.test.js +1 -0
- package/lib/tests/rules/valid-story-reference.test.js +2 -0
- package/lib/tests/utils/annotation-checker.test.js +2 -1
- package/lib/tests/utils/branch-annotation-helpers.test.js +2 -1
- package/package.json +1 -1
- package/user-docs/api-reference.md +117 -10
- package/user-docs/examples.md +2 -3
- package/user-docs/migration-guide.md +36 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
## [1.11.1](https://github.com/voder-ai/eslint-plugin-traceability/compare/v1.11.0...v1.11.1) (2025-12-05)
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
###
|
|
4
|
+
### Bug Fixes
|
|
5
5
|
|
|
6
|
-
*
|
|
7
|
-
* add configurable auto-fix templates and toggles ([21c3a79](https://github.com/voder-ai/eslint-plugin-traceability/commit/21c3a79ce2e2e7fd95a422a963735d67940c8bd8))
|
|
6
|
+
* expose valid-annotation-format autofix toggle and align docs ([32e7636](https://github.com/voder-ai/eslint-plugin-traceability/commit/32e7636e9b8f784b84f694a13e9e06d6120e38b3))
|
|
8
7
|
|
|
9
8
|
# Changelog
|
|
10
9
|
|
package/README.md
CHANGED
|
@@ -83,7 +83,7 @@ export default [
|
|
|
83
83
|
|
|
84
84
|
```js
|
|
85
85
|
/**
|
|
86
|
-
* @story stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
86
|
+
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
87
87
|
* // Point this to your own project's story/requirements file, not to this plugin's internal docs.
|
|
88
88
|
* @req REQ-ANNOTATION-REQUIRED
|
|
89
89
|
*/
|
|
@@ -242,4 +242,4 @@ For the canonical, user-facing security policy (including how to report vulnerab
|
|
|
242
242
|
- Contribution guide: <https://github.com/voder-ai/eslint-plugin-traceability/blob/main/CONTRIBUTING.md>
|
|
243
243
|
- Issue tracker: <https://github.com/voder-ai/eslint-plugin-traceability/issues>
|
|
244
244
|
- Changelog: [CHANGELOG.md](CHANGELOG.md)
|
|
245
|
-
- Versioning and Releases: This project uses semantic-release for automated versioning. The authoritative list of published versions and release notes is on GitHub Releases: <https://github.com/voder-ai/eslint-plugin-traceability/releases>
|
|
245
|
+
- Versioning and Releases: This project uses semantic-release for automated versioning. The authoritative list of published versions and release notes is on GitHub Releases: <https://github.com/voder-ai/eslint-plugin-traceability/releases>
|
|
@@ -60,43 +60,129 @@ function createDefaultFlags() {
|
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
|
-
*
|
|
63
|
+
* Safely check if the next argument value exists and is a string.
|
|
64
64
|
*
|
|
65
65
|
* @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
|
|
66
66
|
* @req REQ-MAINT-SAFE - Provide predictable, minimal argument parsing
|
|
67
67
|
*/
|
|
68
|
-
function
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
function isNextValueString(args, index) {
|
|
69
|
+
return typeof args[index + 1] === "string";
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Handle the --root flag, updating the root path if present.
|
|
73
|
+
*
|
|
74
|
+
* @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
|
|
75
|
+
* @req REQ-MAINT-SAFE - Provide predictable, minimal argument parsing
|
|
76
|
+
*/
|
|
77
|
+
function handleRootFlag(flags, args, index) {
|
|
78
|
+
if (args[index] !== "--root" || !isNextValueString(args, index)) {
|
|
79
|
+
return index;
|
|
80
|
+
}
|
|
81
|
+
flags.root = path_1.default.resolve(args[index + 1]);
|
|
82
|
+
return index + 1;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Handle the --json flag, toggling JSON output when present.
|
|
86
|
+
*
|
|
87
|
+
* @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
|
|
88
|
+
* @req REQ-MAINT-SAFE - Provide predictable, minimal argument parsing
|
|
89
|
+
*/
|
|
90
|
+
function handleJsonFlag(flags, args, index) {
|
|
91
|
+
if (args[index] !== "--json") {
|
|
92
|
+
return index;
|
|
73
93
|
}
|
|
74
|
-
|
|
75
|
-
|
|
94
|
+
flags.json = true;
|
|
95
|
+
return index;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Handle the --format flag, validating and setting the output format.
|
|
99
|
+
*
|
|
100
|
+
* @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
|
|
101
|
+
* @req REQ-MAINT-SAFE - Provide predictable, minimal argument parsing
|
|
102
|
+
*/
|
|
103
|
+
function handleFormatFlag(flags, args, index) {
|
|
104
|
+
if (args[index] !== "--format" || !isNextValueString(args, index)) {
|
|
76
105
|
return index;
|
|
77
106
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
throw new Error(`Invalid format: ${value}. Expected 'text' or 'json'.`);
|
|
85
|
-
}
|
|
86
|
-
return index + 1;
|
|
107
|
+
const value = args[index + 1];
|
|
108
|
+
if (value === "text" || value === "json") {
|
|
109
|
+
flags.format = value;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
throw new Error(`Invalid format: ${value}. Expected 'text' or 'json'.`);
|
|
87
113
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
114
|
+
return index + 1;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Handle the --from flag, capturing the starting reference if present.
|
|
118
|
+
*
|
|
119
|
+
* @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
|
|
120
|
+
* @req REQ-MAINT-SAFE - Provide predictable, minimal argument parsing
|
|
121
|
+
*/
|
|
122
|
+
function handleFromFlag(flags, args, index) {
|
|
123
|
+
if (args[index] !== "--from" || !isNextValueString(args, index)) {
|
|
124
|
+
return index;
|
|
91
125
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
126
|
+
flags.from = args[index + 1];
|
|
127
|
+
return index + 1;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Handle the --to flag, capturing the ending reference if present.
|
|
131
|
+
*
|
|
132
|
+
* @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
|
|
133
|
+
* @req REQ-MAINT-SAFE - Provide predictable, minimal argument parsing
|
|
134
|
+
*/
|
|
135
|
+
function handleToFlag(flags, args, index) {
|
|
136
|
+
if (args[index] !== "--to" || !isNextValueString(args, index)) {
|
|
137
|
+
return index;
|
|
95
138
|
}
|
|
96
|
-
|
|
97
|
-
|
|
139
|
+
flags.to = args[index + 1];
|
|
140
|
+
return index + 1;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Handle the --dry-run flag, enabling dry-run mode when present.
|
|
144
|
+
*
|
|
145
|
+
* @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
|
|
146
|
+
* @req REQ-MAINT-SAFE - Provide predictable, minimal argument parsing
|
|
147
|
+
*/
|
|
148
|
+
function handleDryRunFlag(flags, args, index) {
|
|
149
|
+
if (args[index] !== "--dry-run") {
|
|
98
150
|
return index;
|
|
99
151
|
}
|
|
152
|
+
flags.dryRun = true;
|
|
153
|
+
return index;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Handle a single CLI argument and update the flags accordingly.
|
|
157
|
+
*
|
|
158
|
+
* @story docs/stories/009.0-DEV-MAINTENANCE-TOOLS.story.md
|
|
159
|
+
* @req REQ-MAINT-SAFE - Provide predictable, minimal argument parsing
|
|
160
|
+
*/
|
|
161
|
+
function applyFlag(flags, args, index) {
|
|
162
|
+
const afterRoot = handleRootFlag(flags, args, index);
|
|
163
|
+
if (afterRoot !== index) {
|
|
164
|
+
return afterRoot;
|
|
165
|
+
}
|
|
166
|
+
const afterJson = handleJsonFlag(flags, args, index);
|
|
167
|
+
if (afterJson !== index) {
|
|
168
|
+
return afterJson;
|
|
169
|
+
}
|
|
170
|
+
const afterFormat = handleFormatFlag(flags, args, index);
|
|
171
|
+
if (afterFormat !== index) {
|
|
172
|
+
return afterFormat;
|
|
173
|
+
}
|
|
174
|
+
const afterFrom = handleFromFlag(flags, args, index);
|
|
175
|
+
if (afterFrom !== index) {
|
|
176
|
+
return afterFrom;
|
|
177
|
+
}
|
|
178
|
+
const afterTo = handleToFlag(flags, args, index);
|
|
179
|
+
if (afterTo !== index) {
|
|
180
|
+
return afterTo;
|
|
181
|
+
}
|
|
182
|
+
const afterDryRun = handleDryRunFlag(flags, args, index);
|
|
183
|
+
if (afterDryRun !== index) {
|
|
184
|
+
return afterDryRun;
|
|
185
|
+
}
|
|
100
186
|
return index;
|
|
101
187
|
}
|
|
102
188
|
/**
|
|
@@ -16,7 +16,66 @@ export declare function createMethodFix(node: any, annotationTemplate: string):
|
|
|
16
16
|
* @req REQ-ANNOTATION-REQUIRED - Provide sensible default scope for rule checks
|
|
17
17
|
*/
|
|
18
18
|
export declare const DEFAULT_SCOPE: string[];
|
|
19
|
+
/**
|
|
20
|
+
* Path to the story file for function-annotation helpers.
|
|
21
|
+
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
22
|
+
* @req REQ-ANNOTATION-REQUIRED - Provide a single source of truth for the canonical story path used by helper modules
|
|
23
|
+
*/
|
|
24
|
+
export declare const STORY_PATH = "docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md";
|
|
19
25
|
/**
|
|
20
26
|
* Allowed values for export priority option.
|
|
21
27
|
*/
|
|
22
28
|
export declare const EXPORT_PRIORITY_VALUES: string[];
|
|
29
|
+
import type { Rule } from "eslint";
|
|
30
|
+
type CoreReportOptions = {
|
|
31
|
+
annotationTemplateOverride?: string;
|
|
32
|
+
autoFixToggle?: boolean;
|
|
33
|
+
};
|
|
34
|
+
type ReportDeps = {
|
|
35
|
+
hasStoryAnnotation: (_sourceCode: any, _node: any) => boolean;
|
|
36
|
+
getReportedFunctionName: (_node: any) => string;
|
|
37
|
+
resolveAnnotationTargetNode: (_sourceCode: any, _node: any, _passedTarget: any) => any;
|
|
38
|
+
getNameNodeForReport: (_node: any) => any;
|
|
39
|
+
buildTemplateConfig: (_options?: CoreReportOptions) => {
|
|
40
|
+
effectiveTemplate: string;
|
|
41
|
+
allowFix: boolean;
|
|
42
|
+
};
|
|
43
|
+
extractName: (_node: any) => string;
|
|
44
|
+
getAnnotationTemplate: (_override?: string) => string;
|
|
45
|
+
shouldApplyAutoFix: (_autoFix: boolean | undefined) => boolean;
|
|
46
|
+
createAddStoryFix: (_target: any, _annotationTemplate: string) => any;
|
|
47
|
+
createMethodFix: (_node: any, _annotationTemplate: string) => any;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Core helper to report a missing @story annotation for a function-like node.
|
|
51
|
+
* Delegates actual behavior to injected dependencies so higher-level helpers
|
|
52
|
+
* can remain small while sharing error-reporting behavior.
|
|
53
|
+
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
54
|
+
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
55
|
+
* @story docs/stories/008.0-DEV-AUTO-FIX.story.md
|
|
56
|
+
* @req REQ-ANNOTATION-REQUIRED
|
|
57
|
+
* @req REQ-AUTOFIX-MISSING
|
|
58
|
+
* @req REQ-ERROR-SPECIFIC
|
|
59
|
+
*/
|
|
60
|
+
export declare function coreReportMissing(deps: ReportDeps, context: Rule.RuleContext, sourceCode: any, config: {
|
|
61
|
+
node: any;
|
|
62
|
+
target?: any;
|
|
63
|
+
options?: CoreReportOptions;
|
|
64
|
+
}): void;
|
|
65
|
+
/**
|
|
66
|
+
* Core helper to report a missing @story annotation for a method-like node.
|
|
67
|
+
* Delegates actual behavior to injected dependencies while keeping this
|
|
68
|
+
* module focused on core error-reporting behavior.
|
|
69
|
+
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
70
|
+
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
71
|
+
* @story docs/stories/008.0-DEV-AUTO-FIX.story.md
|
|
72
|
+
* @req REQ-ANNOTATION-REQUIRED
|
|
73
|
+
* @req REQ-AUTOFIX-MISSING
|
|
74
|
+
* @req REQ-ERROR-SPECIFIC
|
|
75
|
+
*/
|
|
76
|
+
export declare function coreReportMethod(deps: ReportDeps, context: Rule.RuleContext, sourceCode: any, config: {
|
|
77
|
+
node: any;
|
|
78
|
+
target?: any;
|
|
79
|
+
options?: CoreReportOptions;
|
|
80
|
+
}): void;
|
|
81
|
+
export {};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EXPORT_PRIORITY_VALUES = exports.DEFAULT_SCOPE = void 0;
|
|
3
|
+
exports.EXPORT_PRIORITY_VALUES = exports.STORY_PATH = exports.DEFAULT_SCOPE = void 0;
|
|
4
4
|
exports.createAddStoryFix = createAddStoryFix;
|
|
5
5
|
exports.createMethodFix = createMethodFix;
|
|
6
|
+
exports.coreReportMissing = coreReportMissing;
|
|
7
|
+
exports.coreReportMethod = coreReportMethod;
|
|
6
8
|
/**
|
|
7
9
|
* Create a fixer function that inserts a @story annotation before the target node.
|
|
8
10
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
@@ -69,7 +71,95 @@ exports.DEFAULT_SCOPE = [
|
|
|
69
71
|
"TSMethodSignature",
|
|
70
72
|
"TSDeclareFunction",
|
|
71
73
|
];
|
|
74
|
+
/**
|
|
75
|
+
* Path to the story file for function-annotation helpers.
|
|
76
|
+
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
77
|
+
* @req REQ-ANNOTATION-REQUIRED - Provide a single source of truth for the canonical story path used by helper modules
|
|
78
|
+
*/
|
|
79
|
+
exports.STORY_PATH = "docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md";
|
|
72
80
|
/**
|
|
73
81
|
* Allowed values for export priority option.
|
|
74
82
|
*/
|
|
75
83
|
exports.EXPORT_PRIORITY_VALUES = ["all", "exported", "non-exported"];
|
|
84
|
+
/**
|
|
85
|
+
* Core helper to report a missing @story annotation for a function-like node.
|
|
86
|
+
* Delegates actual behavior to injected dependencies so higher-level helpers
|
|
87
|
+
* can remain small while sharing error-reporting behavior.
|
|
88
|
+
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
89
|
+
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
90
|
+
* @story docs/stories/008.0-DEV-AUTO-FIX.story.md
|
|
91
|
+
* @req REQ-ANNOTATION-REQUIRED
|
|
92
|
+
* @req REQ-AUTOFIX-MISSING
|
|
93
|
+
* @req REQ-ERROR-SPECIFIC
|
|
94
|
+
*/
|
|
95
|
+
function coreReportMissing(deps, context, sourceCode, config) {
|
|
96
|
+
const { node, target: passedTarget, options = {} } = config;
|
|
97
|
+
try {
|
|
98
|
+
if (deps.hasStoryAnnotation(sourceCode, node)) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const functionName = deps.getReportedFunctionName(node);
|
|
102
|
+
const resolvedTarget = deps.resolveAnnotationTargetNode(sourceCode, node, passedTarget);
|
|
103
|
+
const nameNode = deps.getNameNodeForReport(node);
|
|
104
|
+
const { effectiveTemplate, allowFix } = deps.buildTemplateConfig(options);
|
|
105
|
+
const name = functionName;
|
|
106
|
+
context.report({
|
|
107
|
+
node: nameNode,
|
|
108
|
+
messageId: "missingStory",
|
|
109
|
+
data: { name, functionName: name },
|
|
110
|
+
fix: allowFix
|
|
111
|
+
? deps.createAddStoryFix(resolvedTarget, effectiveTemplate)
|
|
112
|
+
: undefined,
|
|
113
|
+
suggest: [
|
|
114
|
+
{
|
|
115
|
+
desc: `Add JSDoc @story annotation for function '${name}', e.g., ${effectiveTemplate}`,
|
|
116
|
+
fix: deps.createAddStoryFix(resolvedTarget, effectiveTemplate),
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
/* noop */
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Core helper to report a missing @story annotation for a method-like node.
|
|
127
|
+
* Delegates actual behavior to injected dependencies while keeping this
|
|
128
|
+
* module focused on core error-reporting behavior.
|
|
129
|
+
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
130
|
+
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
131
|
+
* @story docs/stories/008.0-DEV-AUTO-FIX.story.md
|
|
132
|
+
* @req REQ-ANNOTATION-REQUIRED
|
|
133
|
+
* @req REQ-AUTOFIX-MISSING
|
|
134
|
+
* @req REQ-ERROR-SPECIFIC
|
|
135
|
+
*/
|
|
136
|
+
function coreReportMethod(deps, context, sourceCode, config) {
|
|
137
|
+
const { node, target: passedTarget, options = {} } = config;
|
|
138
|
+
try {
|
|
139
|
+
if (deps.hasStoryAnnotation(sourceCode, node)) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const resolvedTarget = passedTarget ?? deps.resolveAnnotationTargetNode(sourceCode, node, null);
|
|
143
|
+
const name = deps.extractName(node);
|
|
144
|
+
const nameNode = (node.key && node.key.type === "Identifier" && node.key) || node;
|
|
145
|
+
const effectiveTemplate = deps.getAnnotationTemplate(options.annotationTemplateOverride);
|
|
146
|
+
const allowFix = deps.shouldApplyAutoFix(options.autoFixToggle);
|
|
147
|
+
context.report({
|
|
148
|
+
node: nameNode,
|
|
149
|
+
messageId: "missingStory",
|
|
150
|
+
data: { name, functionName: name },
|
|
151
|
+
fix: allowFix
|
|
152
|
+
? deps.createMethodFix(resolvedTarget, effectiveTemplate)
|
|
153
|
+
: undefined,
|
|
154
|
+
suggest: [
|
|
155
|
+
{
|
|
156
|
+
desc: `Add JSDoc @story annotation for function '${name}', e.g., ${effectiveTemplate}`,
|
|
157
|
+
fix: deps.createMethodFix(resolvedTarget, effectiveTemplate),
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
/* noop */
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -10,11 +10,7 @@
|
|
|
10
10
|
import type { Rule } from "eslint";
|
|
11
11
|
import { linesBeforeHasStory, parentChainHasStory, fallbackTextBeforeHasStory } from "./require-story-io";
|
|
12
12
|
import { getNodeName } from "./require-story-utils";
|
|
13
|
-
import { DEFAULT_SCOPE, EXPORT_PRIORITY_VALUES } from "./require-story-core";
|
|
14
|
-
/**
|
|
15
|
-
* Path to the story file for annotations
|
|
16
|
-
*/
|
|
17
|
-
declare const STORY_PATH = "docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md";
|
|
13
|
+
import { DEFAULT_SCOPE, EXPORT_PRIORITY_VALUES, STORY_PATH } from "./require-story-core";
|
|
18
14
|
/**
|
|
19
15
|
* Derive the annotation template, optionally using an override.
|
|
20
16
|
* When override is a non-empty string, its trimmed value is used.
|
|
@@ -26,18 +22,6 @@ declare function getAnnotationTemplate(override?: string): string;
|
|
|
26
22
|
* Explicit false disables auto-fix; all other values enable it.
|
|
27
23
|
*/
|
|
28
24
|
declare function shouldApplyAutoFix(autoFix: boolean | undefined): boolean;
|
|
29
|
-
/**
|
|
30
|
-
* Number of physical source lines to inspect before a node when searching for @story text
|
|
31
|
-
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
32
|
-
* @req REQ-ANNOTATION-REQUIRED - Replace magic number for lookback lines with named constant
|
|
33
|
-
*/
|
|
34
|
-
declare const LOOKBACK_LINES = 4;
|
|
35
|
-
/**
|
|
36
|
-
* Window (in characters) to inspect before a node as a fallback when searching for @story text
|
|
37
|
-
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
38
|
-
* @req REQ-ANNOTATION-REQUIRED - Replace magic number for fallback text window with named constant
|
|
39
|
-
*/
|
|
40
|
-
declare const FALLBACK_WINDOW = 800;
|
|
41
25
|
/**
|
|
42
26
|
* Determine if a node is in an export declaration
|
|
43
27
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
@@ -114,40 +98,11 @@ interface ReportOptions {
|
|
|
114
98
|
annotationTemplateOverride?: string;
|
|
115
99
|
autoFixToggle?: boolean;
|
|
116
100
|
}
|
|
117
|
-
/**
|
|
118
|
-
* Report a missing @story annotation for a function-like node
|
|
119
|
-
* Provides a suggestion to add the annotation.
|
|
120
|
-
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
121
|
-
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
122
|
-
* @story docs/stories/008.0-DEV-AUTO-FIX.story.md
|
|
123
|
-
* @req REQ-ANNOTATION-REQUIRED - Implement reporting for missing annotations with suggestion
|
|
124
|
-
* @req REQ-AUTOFIX-MISSING - Provide autofix for missing annotations while preserving suggestions
|
|
125
|
-
* @req REQ-ERROR-SPECIFIC - Error reports must include both name and functionName in the data payload for specific function context
|
|
126
|
-
* @param {Rule.RuleContext} context - ESLint rule context used to report
|
|
127
|
-
* @param {any} sourceCode - ESLint sourceCode object
|
|
128
|
-
* @param {{ node: any; target?: any; options?: ReportOptions }} config - configuration containing the node to report, optional insertion target, and optional report options
|
|
129
|
-
*/
|
|
130
101
|
declare function reportMissing(context: Rule.RuleContext, sourceCode: any, config: {
|
|
131
102
|
node: any;
|
|
132
103
|
target?: any;
|
|
133
104
|
options?: ReportOptions;
|
|
134
105
|
}): void;
|
|
135
|
-
/**
|
|
136
|
-
* Report a missing @story annotation for a method-like node
|
|
137
|
-
* Provides a suggestion to update the method/interface with the annotation.
|
|
138
|
-
* The error data payload uses both name and functionName for consistent, specific error context.
|
|
139
|
-
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
140
|
-
* @story docs/stories/008.0-DEV-AUTO-FIX.story.md
|
|
141
|
-
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
142
|
-
* @req REQ-ANNOTATION-REQUIRED - Implement reporting for missing method/interface annotations with suggestion
|
|
143
|
-
* @req REQ-AUTOFIX-MISSING - Provide autofix for missing method/interface annotations while preserving suggestions
|
|
144
|
-
* @req REQ-ERROR-SPECIFIC - Method error reports must include both name and functionName in the data payload for specific function context
|
|
145
|
-
* @req REQ-ERROR-LOCATION - Method error reports must use the method name node to anchor error location
|
|
146
|
-
* @req REQ-ERROR-CONTEXT - Method error reports must include functionName data for consistent error context
|
|
147
|
-
* @param {Rule.RuleContext} context - ESLint rule context to report
|
|
148
|
-
* @param {any} sourceCode - ESLint sourceCode object
|
|
149
|
-
* @param {{ node: any; target?: any; options?: ReportOptions }} config - configuration containing the node to report, optional insertion target, and optional report options
|
|
150
|
-
*/
|
|
151
106
|
declare function reportMethod(context: Rule.RuleContext, sourceCode: any, config: {
|
|
152
107
|
node: any;
|
|
153
108
|
target?: any;
|
|
@@ -158,4 +113,4 @@ declare function reportMethod(context: Rule.RuleContext, sourceCode: any, config
|
|
|
158
113
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
159
114
|
* @req REQ-ANNOTATION-REQUIRED - Explicitly export helper functions and constants used by requiring modules
|
|
160
115
|
*/
|
|
161
|
-
export { STORY_PATH, getAnnotationTemplate, shouldApplyAutoFix,
|
|
116
|
+
export { STORY_PATH, getAnnotationTemplate, shouldApplyAutoFix, isExportedNode, jsdocHasStory, commentsBeforeHasStory, leadingCommentsHasStory, hasStoryAnnotation, getNodeName, extractName, resolveTargetNode, shouldProcessNode, DEFAULT_SCOPE, EXPORT_PRIORITY_VALUES, linesBeforeHasStory, parentChainHasStory, fallbackTextBeforeHasStory, reportMissing, reportMethod, };
|