eslint-plugin-traceability 1.6.0 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/src/index.d.ts +6 -0
- package/lib/src/index.js +6 -0
- package/lib/src/rules/helpers/require-story-helpers.d.ts +7 -0
- package/lib/src/rules/helpers/require-story-helpers.js +9 -2
- package/lib/src/rules/require-branch-annotation.js +5 -1
- package/lib/src/rules/require-req-annotation.d.ts +9 -4
- package/lib/src/rules/require-req-annotation.js +82 -22
- package/lib/src/rules/require-story-annotation.d.ts +8 -0
- package/lib/src/rules/require-story-annotation.js +17 -2
- package/lib/src/rules/valid-annotation-format.js +34 -2
- package/lib/src/rules/valid-req-reference.js +14 -0
- package/lib/src/rules/valid-story-reference.js +21 -0
- package/lib/src/utils/annotation-checker.d.ts +7 -1
- package/lib/src/utils/annotation-checker.js +145 -12
- package/lib/tests/cli-error-handling.test.js +1 -1
- package/lib/tests/plugin-default-export-and-configs.test.js +16 -0
- package/lib/tests/rules/auto-fix-behavior-008.test.js +76 -0
- package/lib/tests/rules/error-reporting.test.js +72 -23
- package/lib/tests/rules/require-branch-annotation.test.js +5 -1
- package/lib/tests/rules/require-req-annotation.test.js +228 -8
- package/lib/tests/rules/require-story-annotation.test.js +1 -0
- package/lib/tests/rules/valid-annotation-format.test.js +5 -0
- package/lib/tests/rules/valid-req-reference.test.js +6 -0
- package/lib/tests/rules/valid-story-reference.test.js +5 -0
- package/package.json +1 -1
package/lib/src/index.d.ts
CHANGED
|
@@ -12,6 +12,12 @@ import type { Rule } from "eslint";
|
|
|
12
12
|
declare const RULE_NAMES: readonly ["require-story-annotation", "require-req-annotation", "require-branch-annotation", "valid-annotation-format", "valid-story-reference", "valid-req-reference"];
|
|
13
13
|
type RuleName = (typeof RULE_NAMES)[number];
|
|
14
14
|
declare const rules: Record<RuleName, Rule.RuleModule>;
|
|
15
|
+
/**
|
|
16
|
+
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
17
|
+
* @req REQ-ERROR-SEVERITY - Map rule types to appropriate ESLint severity levels (errors vs warnings)
|
|
18
|
+
* The recommended and strict configs treat missing annotations and missing references as errors,
|
|
19
|
+
* while formatting issues are reported as warnings, matching the story's severity conventions.
|
|
20
|
+
*/
|
|
15
21
|
declare const configs: {
|
|
16
22
|
recommended: {
|
|
17
23
|
plugins: {
|
package/lib/src/index.js
CHANGED
|
@@ -67,6 +67,12 @@ RULE_NAMES.forEach(
|
|
|
67
67
|
};
|
|
68
68
|
}
|
|
69
69
|
});
|
|
70
|
+
/**
|
|
71
|
+
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
72
|
+
* @req REQ-ERROR-SEVERITY - Map rule types to appropriate ESLint severity levels (errors vs warnings)
|
|
73
|
+
* The recommended and strict configs treat missing annotations and missing references as errors,
|
|
74
|
+
* while formatting issues are reported as warnings, matching the story's severity conventions.
|
|
75
|
+
*/
|
|
70
76
|
const configs = {
|
|
71
77
|
recommended: [
|
|
72
78
|
{
|
|
@@ -100,9 +100,11 @@ declare function shouldProcessNode(node: any, scope: string[], exportPriority?:
|
|
|
100
100
|
* Report a missing @story annotation for a function-like node
|
|
101
101
|
* Provides a suggestion to add the annotation.
|
|
102
102
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
103
|
+
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
103
104
|
* @story docs/stories/008.0-DEV-AUTO-FIX.story.md
|
|
104
105
|
* @req REQ-ANNOTATION-REQUIRED - Implement reporting for missing annotations with suggestion
|
|
105
106
|
* @req REQ-AUTOFIX-MISSING - Provide autofix for missing annotations while preserving suggestions
|
|
107
|
+
* @req REQ-ERROR-SPECIFIC - Error reports must include both name and functionName in the data payload for specific function context
|
|
106
108
|
* @param {Rule.RuleContext} context - ESLint rule context used to report
|
|
107
109
|
* @param {any} sourceCode - ESLint sourceCode object
|
|
108
110
|
* @param {any} node - AST node that is missing the annotation
|
|
@@ -112,10 +114,15 @@ declare function reportMissing(context: Rule.RuleContext, sourceCode: any, node:
|
|
|
112
114
|
/**
|
|
113
115
|
* Report a missing @story annotation for a method-like node
|
|
114
116
|
* Provides a suggestion to update the method/interface with the annotation.
|
|
117
|
+
* The error data payload uses both name and functionName for consistent, specific error context.
|
|
115
118
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
116
119
|
* @story docs/stories/008.0-DEV-AUTO-FIX.story.md
|
|
120
|
+
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
117
121
|
* @req REQ-ANNOTATION-REQUIRED - Implement reporting for missing method/interface annotations with suggestion
|
|
118
122
|
* @req REQ-AUTOFIX-MISSING - Provide autofix for missing method/interface annotations while preserving suggestions
|
|
123
|
+
* @req REQ-ERROR-SPECIFIC - Method error reports must include both name and functionName in the data payload for specific function context
|
|
124
|
+
* @req REQ-ERROR-LOCATION - Method error reports must use the method name node to anchor error location
|
|
125
|
+
* @req REQ-ERROR-CONTEXT - Method error reports must include functionName data for consistent error context
|
|
119
126
|
* @param {Rule.RuleContext} context - ESLint rule context to report
|
|
120
127
|
* @param {any} sourceCode - ESLint sourceCode object
|
|
121
128
|
* @param {any} node - AST node that is missing the annotation
|
|
@@ -238,9 +238,11 @@ function shouldProcessNode(node, scope, exportPriority = "all") {
|
|
|
238
238
|
* Report a missing @story annotation for a function-like node
|
|
239
239
|
* Provides a suggestion to add the annotation.
|
|
240
240
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
241
|
+
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
241
242
|
* @story docs/stories/008.0-DEV-AUTO-FIX.story.md
|
|
242
243
|
* @req REQ-ANNOTATION-REQUIRED - Implement reporting for missing annotations with suggestion
|
|
243
244
|
* @req REQ-AUTOFIX-MISSING - Provide autofix for missing annotations while preserving suggestions
|
|
245
|
+
* @req REQ-ERROR-SPECIFIC - Error reports must include both name and functionName in the data payload for specific function context
|
|
244
246
|
* @param {Rule.RuleContext} context - ESLint rule context used to report
|
|
245
247
|
* @param {any} sourceCode - ESLint sourceCode object
|
|
246
248
|
* @param {any} node - AST node that is missing the annotation
|
|
@@ -260,7 +262,7 @@ function reportMissing(context, sourceCode, node, passedTarget) {
|
|
|
260
262
|
context.report({
|
|
261
263
|
node: nameNode,
|
|
262
264
|
messageId: "missingStory",
|
|
263
|
-
data: { name },
|
|
265
|
+
data: { name, functionName: name },
|
|
264
266
|
fix: (0, require_story_core_1.createAddStoryFix)(resolvedTarget),
|
|
265
267
|
suggest: [
|
|
266
268
|
{
|
|
@@ -277,10 +279,15 @@ function reportMissing(context, sourceCode, node, passedTarget) {
|
|
|
277
279
|
/**
|
|
278
280
|
* Report a missing @story annotation for a method-like node
|
|
279
281
|
* Provides a suggestion to update the method/interface with the annotation.
|
|
282
|
+
* The error data payload uses both name and functionName for consistent, specific error context.
|
|
280
283
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
281
284
|
* @story docs/stories/008.0-DEV-AUTO-FIX.story.md
|
|
285
|
+
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
282
286
|
* @req REQ-ANNOTATION-REQUIRED - Implement reporting for missing method/interface annotations with suggestion
|
|
283
287
|
* @req REQ-AUTOFIX-MISSING - Provide autofix for missing method/interface annotations while preserving suggestions
|
|
288
|
+
* @req REQ-ERROR-SPECIFIC - Method error reports must include both name and functionName in the data payload for specific function context
|
|
289
|
+
* @req REQ-ERROR-LOCATION - Method error reports must use the method name node to anchor error location
|
|
290
|
+
* @req REQ-ERROR-CONTEXT - Method error reports must include functionName data for consistent error context
|
|
284
291
|
* @param {Rule.RuleContext} context - ESLint rule context to report
|
|
285
292
|
* @param {any} sourceCode - ESLint sourceCode object
|
|
286
293
|
* @param {any} node - AST node that is missing the annotation
|
|
@@ -297,7 +304,7 @@ function reportMethod(context, sourceCode, node, passedTarget) {
|
|
|
297
304
|
context.report({
|
|
298
305
|
node: nameNode,
|
|
299
306
|
messageId: "missingStory",
|
|
300
|
-
data: { name },
|
|
307
|
+
data: { name, functionName: name },
|
|
301
308
|
fix: (0, require_story_core_1.createMethodFix)(resolvedTarget),
|
|
302
309
|
suggest: [
|
|
303
310
|
{
|
|
@@ -16,7 +16,11 @@ const rule = {
|
|
|
16
16
|
},
|
|
17
17
|
fixable: "code",
|
|
18
18
|
messages: {
|
|
19
|
-
|
|
19
|
+
/**
|
|
20
|
+
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
21
|
+
* @req REQ-ERROR-CONSISTENCY - Use shared branch error message convention with {{missing}} placeholder
|
|
22
|
+
*/
|
|
23
|
+
missingAnnotation: "Branch is missing required annotation: {{missing}}.",
|
|
20
24
|
},
|
|
21
25
|
schema: [
|
|
22
26
|
{
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
/****
|
|
2
|
+
* Rule to enforce @req annotation on functions
|
|
2
3
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
3
|
-
* @req REQ-RULE-EXPORT - Export the rule object for ESLint
|
|
4
4
|
* @req REQ-ANNOTATION-REQUIRED - Require @req annotation on functions
|
|
5
|
+
* @req REQ-FUNCTION-DETECTION - Detect function declarations, function expressions, and method definitions (including TypeScript declarations)
|
|
6
|
+
* @req REQ-TYPESCRIPT-SUPPORT - Support TypeScript-specific function syntax
|
|
7
|
+
* @req REQ-CONFIGURABLE-SCOPE - Allow configuration of which exports are checked
|
|
8
|
+
* @req REQ-EXPORT-PRIORITY - Allow configuration of export priority behavior
|
|
5
9
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
10
|
+
import type { Rule } from "eslint";
|
|
11
|
+
declare const rule: Rule.RuleModule;
|
|
12
|
+
export default rule;
|
|
@@ -1,37 +1,71 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
* Rule to enforce @req annotation on functions
|
|
5
|
-
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
6
|
-
* @req REQ-ANNOTATION-REQUIRED - Require @req annotation on functions
|
|
7
|
-
* @req REQ-FUNCTION-DETECTION - Detect function declarations, expressions, arrow functions, and methods
|
|
8
|
-
* @req REQ-TYPESCRIPT-SUPPORT - Support TypeScript-specific function syntax
|
|
9
|
-
*/
|
|
3
|
+
const require_story_helpers_1 = require("./helpers/require-story-helpers");
|
|
10
4
|
const annotation_checker_1 = require("../utils/annotation-checker");
|
|
11
|
-
|
|
12
|
-
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
13
|
-
* @req REQ-RULE-EXPORT - Export the rule object for ESLint
|
|
14
|
-
* @req REQ-ANNOTATION-REQUIRED - Require @req annotation on functions
|
|
15
|
-
*/
|
|
16
|
-
exports.default = {
|
|
5
|
+
const rule = {
|
|
17
6
|
meta: {
|
|
18
7
|
type: "problem",
|
|
19
8
|
fixable: "code",
|
|
20
9
|
docs: {
|
|
21
|
-
description: "Require @req annotations on functions",
|
|
10
|
+
description: "Require @req annotations on function-like exports (declarations, expressions, and methods, excluding arrow functions)",
|
|
22
11
|
recommended: "error",
|
|
23
12
|
},
|
|
24
13
|
messages: {
|
|
25
|
-
|
|
14
|
+
/**
|
|
15
|
+
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
16
|
+
* @req REQ-ERROR-CONSISTENCY - Align missing @req function error with cross-rule conventions
|
|
17
|
+
* @req REQ-ERROR-SPECIFIC - Provide specific function name in error message
|
|
18
|
+
* @req REQ-ERROR-SUGGESTION - Suggest adding a @req annotation with an example identifier
|
|
19
|
+
* @req REQ-ERROR-CONTEXT - Include @req format guidance in the error text
|
|
20
|
+
* @req REQ-ERROR-LOCATION - Report the error at the function identifier location
|
|
21
|
+
* @req REQ-ERROR-SEVERITY - Use ESLint severity level "error" for missing @req annotations
|
|
22
|
+
*
|
|
23
|
+
* This rule uses ESLint's message data placeholders for the function name,
|
|
24
|
+
* specifically the {{name}} placeholder populated via context.report.
|
|
25
|
+
*/
|
|
26
|
+
missingReq: "Function '{{functionName}}' is missing a required @req annotation. Add a JSDoc or line comment with @req (for example, '@req REQ-EXAMPLE') referencing the appropriate requirement from the story file.",
|
|
26
27
|
},
|
|
27
|
-
schema: [
|
|
28
|
+
schema: [
|
|
29
|
+
{
|
|
30
|
+
type: "object",
|
|
31
|
+
properties: {
|
|
32
|
+
scope: {
|
|
33
|
+
type: "array",
|
|
34
|
+
items: {
|
|
35
|
+
enum: require_story_helpers_1.DEFAULT_SCOPE,
|
|
36
|
+
},
|
|
37
|
+
uniqueItems: true,
|
|
38
|
+
},
|
|
39
|
+
exportPriority: {
|
|
40
|
+
enum: require_story_helpers_1.EXPORT_PRIORITY_VALUES,
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
additionalProperties: false,
|
|
44
|
+
},
|
|
45
|
+
],
|
|
28
46
|
},
|
|
29
47
|
/**
|
|
30
48
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
31
49
|
* @req REQ-CREATE-HOOK - Provide create(context) hook for rule behavior
|
|
32
|
-
* @req REQ-FUNCTION-DETECTION - Detect function declarations, expressions,
|
|
50
|
+
* @req REQ-FUNCTION-DETECTION - Detect function declarations, function expressions, and method definitions (including TS-specific nodes)
|
|
51
|
+
* @req REQ-CONFIGURABLE-SCOPE - Respect configurable scope of which exports are checked
|
|
52
|
+
* @req REQ-EXPORT-PRIORITY - Respect configurable export priority when determining which nodes to check
|
|
33
53
|
*/
|
|
34
54
|
create(context) {
|
|
55
|
+
const options = context.options?.[0] ?? {};
|
|
56
|
+
const rawScope = options?.scope;
|
|
57
|
+
const scope = Array.isArray(rawScope) && rawScope.length > 0 ? rawScope : require_story_helpers_1.DEFAULT_SCOPE;
|
|
58
|
+
const exportPriority = options?.exportPriority ?? "all";
|
|
59
|
+
const shouldCheck = (node) => (0, require_story_helpers_1.shouldProcessNode)(node, scope, exportPriority);
|
|
60
|
+
/**
|
|
61
|
+
* Helper to conditionally run the annotation check only when the node
|
|
62
|
+
* should be processed according to scope/exportPriority.
|
|
63
|
+
*/
|
|
64
|
+
const runCheck = (node) => {
|
|
65
|
+
if (!shouldCheck(node))
|
|
66
|
+
return;
|
|
67
|
+
(0, annotation_checker_1.checkReqAnnotation)(context, node, { enableFix: false });
|
|
68
|
+
};
|
|
35
69
|
return {
|
|
36
70
|
/**
|
|
37
71
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
@@ -39,18 +73,44 @@ exports.default = {
|
|
|
39
73
|
* @req REQ-ANNOTATION-REQUIRED - Enforce @req annotation on function declarations
|
|
40
74
|
*/
|
|
41
75
|
FunctionDeclaration(node) {
|
|
42
|
-
|
|
76
|
+
runCheck(node);
|
|
77
|
+
},
|
|
78
|
+
/**
|
|
79
|
+
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
80
|
+
* @req REQ-FUNCTION-DETECTION - Detect function expressions
|
|
81
|
+
* @req REQ-ANNOTATION-REQUIRED - Enforce @req annotation on function expressions
|
|
82
|
+
*/
|
|
83
|
+
FunctionExpression(node) {
|
|
84
|
+
if (node.parent && node.parent.type === "MethodDefinition") {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
runCheck(node);
|
|
43
88
|
},
|
|
44
89
|
/**
|
|
45
90
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
46
|
-
* @req REQ-
|
|
91
|
+
* @req REQ-FUNCTION-DETECTION - Detect method definitions
|
|
92
|
+
* @req REQ-ANNOTATION-REQUIRED - Enforce @req annotation on method definitions
|
|
47
93
|
*/
|
|
48
|
-
|
|
94
|
+
MethodDefinition(node) {
|
|
95
|
+
runCheck(node);
|
|
96
|
+
},
|
|
49
97
|
/**
|
|
50
98
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
51
|
-
* @req REQ-TYPESCRIPT-SUPPORT - Support TypeScript
|
|
99
|
+
* @req REQ-TYPESCRIPT-SUPPORT - Support TypeScript declare functions
|
|
100
|
+
* @req REQ-ANNOTATION-REQUIRED - Enforce @req annotation on TS declare functions
|
|
52
101
|
*/
|
|
53
|
-
|
|
102
|
+
TSDeclareFunction(node) {
|
|
103
|
+
runCheck(node);
|
|
104
|
+
},
|
|
105
|
+
/**
|
|
106
|
+
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
107
|
+
* @req REQ-TYPESCRIPT-SUPPORT - Support TypeScript method signatures
|
|
108
|
+
* @req REQ-ANNOTATION-REQUIRED - Enforce @req annotation on TS method signatures
|
|
109
|
+
*/
|
|
110
|
+
TSMethodSignature(node) {
|
|
111
|
+
runCheck(node);
|
|
112
|
+
},
|
|
54
113
|
};
|
|
55
114
|
},
|
|
56
115
|
};
|
|
116
|
+
exports.default = rule;
|
|
@@ -7,14 +7,22 @@
|
|
|
7
7
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
8
8
|
* @story docs/stories/008.0-DEV-AUTO-FIX.story.md
|
|
9
9
|
* @req REQ-ANNOTATION-REQUIRED
|
|
10
|
+
* @req REQ-AUTOFIX-MISSING - This rule supports auto-fixing missing @story annotations per Story 008.0 auto-fix behavior.
|
|
11
|
+
* @req REQ-AUTOFIX-SAFE - Auto-fix behavior only inserts @story annotation JSDoc comments and never changes executable or runtime code.
|
|
12
|
+
* @req REQ-AUTOFIX-PRESERVE - Auto-fix inserts a minimal placeholder JSDoc in a way that preserves existing surrounding formatting and structure.
|
|
10
13
|
*/
|
|
11
14
|
import type { Rule } from "eslint";
|
|
12
15
|
/**
|
|
13
16
|
* ESLint rule to require @story annotations on functions/methods.
|
|
14
17
|
*
|
|
15
18
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
19
|
+
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
16
20
|
* @story docs/stories/008.0-DEV-AUTO-FIX.story.md
|
|
17
21
|
* @req REQ-ANNOTATION-REQUIRED
|
|
22
|
+
* @req REQ-AUTOFIX-MISSING - This rule participates in auto-fix for missing @story annotations.
|
|
23
|
+
* @req REQ-ERROR-MSG-CONTENT - Error message instructs adding an explicit @story annotation that points to the implementing story file.
|
|
24
|
+
* @req REQ-ERROR-MSG-PLACEHOLDER - Error message retains the {{name}} placeholder while also providing functionName in the data payload for cross-rule consistency.
|
|
25
|
+
* @req REQ-ERROR-MSG-ACTIONABLE - Error message text is concise, imperative, and describes the required remediation.
|
|
18
26
|
*/
|
|
19
27
|
declare const rule: Rule.RuleModule;
|
|
20
28
|
export default rule;
|
|
@@ -6,20 +6,34 @@ const require_story_helpers_1 = require("./helpers/require-story-helpers");
|
|
|
6
6
|
* ESLint rule to require @story annotations on functions/methods.
|
|
7
7
|
*
|
|
8
8
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
9
|
+
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
9
10
|
* @story docs/stories/008.0-DEV-AUTO-FIX.story.md
|
|
10
11
|
* @req REQ-ANNOTATION-REQUIRED
|
|
12
|
+
* @req REQ-AUTOFIX-MISSING - This rule participates in auto-fix for missing @story annotations.
|
|
13
|
+
* @req REQ-ERROR-MSG-CONTENT - Error message instructs adding an explicit @story annotation that points to the implementing story file.
|
|
14
|
+
* @req REQ-ERROR-MSG-PLACEHOLDER - Error message retains the {{name}} placeholder while also providing functionName in the data payload for cross-rule consistency.
|
|
15
|
+
* @req REQ-ERROR-MSG-ACTIONABLE - Error message text is concise, imperative, and describes the required remediation.
|
|
11
16
|
*/
|
|
12
17
|
const rule = {
|
|
13
18
|
meta: {
|
|
14
19
|
type: "problem",
|
|
15
20
|
docs: {
|
|
16
|
-
description: "Require @story annotations on functions",
|
|
21
|
+
description: "Require @story annotations on functions and auto-fix missing annotations where possible",
|
|
17
22
|
recommended: "error",
|
|
18
23
|
},
|
|
19
24
|
hasSuggestions: true,
|
|
25
|
+
/**
|
|
26
|
+
* Auto-fix support for inserting @story annotations.
|
|
27
|
+
*
|
|
28
|
+
* @story docs/stories/008.0-DEV-AUTO-FIX.story.md
|
|
29
|
+
* @req REQ-ANNOTATION-REQUIRED
|
|
30
|
+
* @req REQ-AUTOFIX-MISSING - `fixable: \"code\"` is used to implement REQ-AUTOFIX-MISSING for missing @story annotations.
|
|
31
|
+
* @req REQ-AUTOFIX-SAFE - Auto-fix is conservative and only adds a single-line JSDoc @story annotation without modifying existing runtime expressions.
|
|
32
|
+
* @req REQ-AUTOFIX-PRESERVE - Auto-fix behavior preserves surrounding code formatting and indentation when inserting the placeholder JSDoc.
|
|
33
|
+
*/
|
|
20
34
|
fixable: "code",
|
|
21
35
|
messages: {
|
|
22
|
-
missingStory: "
|
|
36
|
+
missingStory: "Function '{{name}}' must have an explicit @story annotation. Add a JSDoc or line comment with @story that points to the implementing story file (for example, docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md).",
|
|
23
37
|
},
|
|
24
38
|
schema: [
|
|
25
39
|
{
|
|
@@ -42,6 +56,7 @@ const rule = {
|
|
|
42
56
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
43
57
|
* @story docs/stories/008.0-DEV-AUTO-FIX.story.md
|
|
44
58
|
* @req REQ-CREATE-HOOK
|
|
59
|
+
* @req REQ-AUTOFIX-MISSING - The create hook wires in visitors that are capable of providing auto-fix suggestions for missing @story annotations.
|
|
45
60
|
*/
|
|
46
61
|
create(context) {
|
|
47
62
|
const sourceCode = context.getSourceCode();
|
|
@@ -8,6 +8,7 @@ const STORY_EXAMPLE_PATH = "docs/stories/005.0-DEV-EXAMPLE.story.md";
|
|
|
8
8
|
* @story docs/stories/005.0-DEV-ANNOTATION-VALIDATION.story.md
|
|
9
9
|
* @story docs/stories/008.0-DEV-AUTO-FIX.story.md
|
|
10
10
|
* @req REQ-AUTOFIX-FORMAT - Provide safe, minimal automatic fixes for common format issues
|
|
11
|
+
* @req REQ-AUTOFIX-PRESERVE - Avoid risky text replacements when the annotation tag cannot be located
|
|
11
12
|
*/
|
|
12
13
|
const TAG_NOT_FOUND_INDEX = -1;
|
|
13
14
|
/**
|
|
@@ -89,6 +90,8 @@ function buildReqErrorMessage(kind, value) {
|
|
|
89
90
|
*
|
|
90
91
|
* @story docs/stories/008.0-DEV-AUTO-FIX.story.md
|
|
91
92
|
* @req REQ-AUTOFIX-FORMAT - Provide safe, minimal automatic fixes for common format issues
|
|
93
|
+
* @req REQ-AUTOFIX-SAFE - Auto-fix must be conservative and never broaden the referenced path
|
|
94
|
+
* @req REQ-AUTOFIX-PRESERVE - Preserve surrounding formatting when normalizing story path suffixes
|
|
92
95
|
*/
|
|
93
96
|
function getFixedStoryPath(original) {
|
|
94
97
|
if (original.includes("..")) {
|
|
@@ -124,10 +127,18 @@ function reportInvalidStoryFormat(context, comment, collapsed) {
|
|
|
124
127
|
* for common path suffix issues by locating and replacing the path text
|
|
125
128
|
* within the original comment.
|
|
126
129
|
*
|
|
130
|
+
* This helper:
|
|
131
|
+
* - only adjusts the story path suffix when a safe, well-understood
|
|
132
|
+
* transformation is available, satisfying REQ-AUTOFIX-SAFE.
|
|
133
|
+
* - preserves all surrounding comment formatting, spacing, and text
|
|
134
|
+
* outside the path substring, satisfying REQ-AUTOFIX-PRESERVE.
|
|
135
|
+
*
|
|
127
136
|
* @story docs/stories/005.0-DEV-ANNOTATION-VALIDATION.story.md
|
|
128
137
|
* @story docs/stories/008.0-DEV-AUTO-FIX.story.md
|
|
129
138
|
* @req REQ-PATH-FORMAT - Validate @story paths follow expected patterns
|
|
130
139
|
* @req REQ-AUTOFIX-FORMAT - Provide safe, minimal automatic fixes for common format issues
|
|
140
|
+
* @req REQ-AUTOFIX-SAFE - Auto-fix must be conservative and avoid changing semantics
|
|
141
|
+
* @req REQ-AUTOFIX-PRESERVE - Auto-fix must preserve surrounding formatting and comments
|
|
131
142
|
*/
|
|
132
143
|
function reportInvalidStoryFormatWithFix(context, comment, collapsed, fixed) {
|
|
133
144
|
const sourceCode = context.getSourceCode();
|
|
@@ -313,10 +324,31 @@ exports.default = {
|
|
|
313
324
|
recommended: "error",
|
|
314
325
|
},
|
|
315
326
|
messages: {
|
|
316
|
-
|
|
317
|
-
|
|
327
|
+
/**
|
|
328
|
+
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
329
|
+
* @req REQ-ERROR-SPECIFIC - Provide specific details about invalid @story annotation format
|
|
330
|
+
* @req REQ-ERROR-CONTEXT - Include human-readable details about the expected @story annotation format
|
|
331
|
+
* @req REQ-ERROR-CONSISTENCY - Use shared "Invalid annotation format: {{details}}." message pattern across rules
|
|
332
|
+
*/
|
|
333
|
+
invalidStoryFormat: "Invalid annotation format: {{details}}.",
|
|
334
|
+
/**
|
|
335
|
+
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
336
|
+
* @req REQ-ERROR-SPECIFIC - Provide specific details about invalid @req annotation format
|
|
337
|
+
* @req REQ-ERROR-CONTEXT - Include human-readable details about the expected @req annotation format
|
|
338
|
+
* @req REQ-ERROR-CONSISTENCY - Use shared "Invalid annotation format: {{details}}." message pattern across rules
|
|
339
|
+
*/
|
|
340
|
+
invalidReqFormat: "Invalid annotation format: {{details}}.",
|
|
318
341
|
},
|
|
319
342
|
schema: [],
|
|
343
|
+
/**
|
|
344
|
+
* This rule's fixable support is limited to safe @story path suffix normalization per Story 008.0.
|
|
345
|
+
* Fixes are limited strictly to adjusting the suffix portion of the @story path (e.g., adding
|
|
346
|
+
* `.md` or `.story.md`), preserving all other comment text and whitespace exactly as written.
|
|
347
|
+
*
|
|
348
|
+
* @story docs/stories/008.0-DEV-AUTO-FIX.story.md
|
|
349
|
+
* @req REQ-AUTOFIX-SAFE
|
|
350
|
+
* @req REQ-AUTOFIX-PRESERVE
|
|
351
|
+
*/
|
|
320
352
|
fixable: "code",
|
|
321
353
|
},
|
|
322
354
|
/**
|
|
@@ -170,7 +170,21 @@ exports.default = {
|
|
|
170
170
|
recommended: "error",
|
|
171
171
|
},
|
|
172
172
|
messages: {
|
|
173
|
+
/**
|
|
174
|
+
* @story docs/stories/010.0-DEV-DEEP-VALIDATION.story.md
|
|
175
|
+
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
176
|
+
* @req REQ-ERROR-SPECIFIC - Provide specific diagnostics when a referenced requirement ID cannot be found in a story
|
|
177
|
+
* @req REQ-ERROR-CONTEXT - Include both the missing requirement ID and the story path in the message
|
|
178
|
+
* @req REQ-ERROR-CONSISTENCY - Use a consistent message template for requirement lookup failures
|
|
179
|
+
*/
|
|
173
180
|
reqMissing: "Requirement '{{reqId}}' not found in '{{storyPath}}'",
|
|
181
|
+
/**
|
|
182
|
+
* @story docs/stories/010.0-DEV-DEEP-VALIDATION.story.md
|
|
183
|
+
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
184
|
+
* @req REQ-ERROR-SPECIFIC - Indicate that the story path associated with a @req annotation is invalid
|
|
185
|
+
* @req REQ-ERROR-CONTEXT - Include the problematic storyPath value so the developer can correct it
|
|
186
|
+
* @req REQ-ERROR-CONSISTENCY - Reuse the same storyPath placeholder convention used by other rules
|
|
187
|
+
*/
|
|
174
188
|
invalidPath: "Invalid story path '{{storyPath}}'",
|
|
175
189
|
},
|
|
176
190
|
schema: [],
|
|
@@ -180,8 +180,29 @@ exports.default = {
|
|
|
180
180
|
recommended: "error",
|
|
181
181
|
},
|
|
182
182
|
messages: {
|
|
183
|
+
/**
|
|
184
|
+
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
185
|
+
* @story docs/stories/006.0-DEV-FILE-VALIDATION.story.md
|
|
186
|
+
* @req REQ-ERROR-SPECIFIC - Provide specific diagnostics when a referenced story file cannot be found
|
|
187
|
+
* @req REQ-ERROR-CONTEXT - Include the original story path in the error message for troubleshooting
|
|
188
|
+
* @req REQ-ERROR-CONSISTENCY - Use consistent file-related error wording and placeholders across rules
|
|
189
|
+
*/
|
|
183
190
|
fileMissing: "Story file '{{path}}' not found",
|
|
191
|
+
/**
|
|
192
|
+
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
193
|
+
* @story docs/stories/006.0-DEV-FILE-VALIDATION.story.md
|
|
194
|
+
* @req REQ-ERROR-SPECIFIC - Indicate that the story file extension is invalid and what is expected
|
|
195
|
+
* @req REQ-ERROR-CONTEXT - Include the provided path so developers can see which reference is wrong
|
|
196
|
+
* @req REQ-ERROR-CONSISTENCY - Reuse the same pattern of "{{path}}" placeholder across file validation messages
|
|
197
|
+
*/
|
|
184
198
|
invalidExtension: "Invalid story file extension for '{{path}}', expected '.story.md'",
|
|
199
|
+
/**
|
|
200
|
+
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
201
|
+
* @story docs/stories/006.0-DEV-FILE-VALIDATION.story.md
|
|
202
|
+
* @req REQ-ERROR-SPECIFIC - Explain that the story path is invalid due to absolute or unsafe traversal
|
|
203
|
+
* @req REQ-ERROR-CONTEXT - Surface the offending path to assist with correcting the reference
|
|
204
|
+
* @req REQ-ERROR-CONSISTENCY - Maintain a consistent template for invalid path diagnostics across rules
|
|
205
|
+
*/
|
|
185
206
|
invalidPath: "Invalid story path '{{path}}'",
|
|
186
207
|
/**
|
|
187
208
|
* @story docs/stories/006.0-DEV-FILE-VALIDATION.story.md
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Helper to check @req annotation presence on TS declare functions and method signatures.
|
|
3
|
+
* This helper is intentionally scope/exportPriority agnostic and focuses solely
|
|
4
|
+
* on detection and reporting of @req annotations for the given node.
|
|
3
5
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
4
6
|
* @req REQ-TYPESCRIPT-SUPPORT - Support TypeScript-specific function syntax
|
|
7
|
+
* @req REQ-ANNOTATION-REQ-DETECTION - Determine presence of @req annotation
|
|
8
|
+
* @req REQ-ANNOTATION-REPORTING - Report missing @req annotation to context
|
|
5
9
|
*/
|
|
6
|
-
export declare function checkReqAnnotation(context: any, node: any
|
|
10
|
+
export declare function checkReqAnnotation(context: any, node: any, options?: {
|
|
11
|
+
enableFix?: boolean;
|
|
12
|
+
}): void;
|