eslint-plugin-traceability 1.5.0 → 1.5.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/lib/src/index.js
CHANGED
|
@@ -77,7 +77,7 @@ const configs = {
|
|
|
77
77
|
"traceability/require-story-annotation": "error",
|
|
78
78
|
"traceability/require-req-annotation": "error",
|
|
79
79
|
"traceability/require-branch-annotation": "error",
|
|
80
|
-
"traceability/valid-annotation-format": "
|
|
80
|
+
"traceability/valid-annotation-format": "warn",
|
|
81
81
|
"traceability/valid-story-reference": "error",
|
|
82
82
|
"traceability/valid-req-reference": "error",
|
|
83
83
|
},
|
|
@@ -92,7 +92,7 @@ const configs = {
|
|
|
92
92
|
"traceability/require-story-annotation": "error",
|
|
93
93
|
"traceability/require-req-annotation": "error",
|
|
94
94
|
"traceability/require-branch-annotation": "error",
|
|
95
|
-
"traceability/valid-annotation-format": "
|
|
95
|
+
"traceability/valid-annotation-format": "warn",
|
|
96
96
|
"traceability/valid-story-reference": "error",
|
|
97
97
|
"traceability/valid-req-reference": "error",
|
|
98
98
|
},
|
|
@@ -22,7 +22,7 @@ exports.default = {
|
|
|
22
22
|
recommended: "error",
|
|
23
23
|
},
|
|
24
24
|
messages: {
|
|
25
|
-
missingReq: "Missing @req annotation",
|
|
25
|
+
missingReq: "Missing @req annotation for function '{{name}}' (REQ-ANNOTATION-REQUIRED)",
|
|
26
26
|
},
|
|
27
27
|
schema: [],
|
|
28
28
|
},
|
|
@@ -32,7 +32,6 @@ exports.default = {
|
|
|
32
32
|
* @req REQ-FUNCTION-DETECTION - Detect function declarations, expressions, arrow functions, and methods
|
|
33
33
|
*/
|
|
34
34
|
create(context) {
|
|
35
|
-
const sourceCode = context.getSourceCode();
|
|
36
35
|
return {
|
|
37
36
|
/**
|
|
38
37
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
@@ -40,21 +39,7 @@ exports.default = {
|
|
|
40
39
|
* @req REQ-ANNOTATION-REQUIRED - Enforce @req annotation on function declarations
|
|
41
40
|
*/
|
|
42
41
|
FunctionDeclaration(node) {
|
|
43
|
-
|
|
44
|
-
if (!jsdoc || !jsdoc.value.includes("@req")) {
|
|
45
|
-
context.report({
|
|
46
|
-
node,
|
|
47
|
-
messageId: "missingReq",
|
|
48
|
-
/**
|
|
49
|
-
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
50
|
-
* @req REQ-AUTOFIX - Provide automatic fix to insert @req annotation
|
|
51
|
-
* @req REQ-ANNOTATION-REQUIRED - Ensure inserted fix contains @req placeholder
|
|
52
|
-
*/
|
|
53
|
-
fix(fixer) {
|
|
54
|
-
return fixer.insertTextBefore(node, "/** @req <REQ-ID> */\n");
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
}
|
|
42
|
+
return (0, annotation_checker_1.checkReqAnnotation)(context, node);
|
|
58
43
|
},
|
|
59
44
|
/**
|
|
60
45
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.checkReqAnnotation = checkReqAnnotation;
|
|
4
|
+
const require_story_utils_1 = require("../rules/helpers/require-story-utils");
|
|
4
5
|
/**
|
|
5
6
|
* Helper to retrieve the JSDoc comment for a node.
|
|
6
7
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
@@ -65,13 +66,20 @@ function createMissingReqFix(node) {
|
|
|
65
66
|
}
|
|
66
67
|
/**
|
|
67
68
|
* Helper to report a missing @req annotation via the ESLint context API.
|
|
69
|
+
* Uses getNodeName to provide a readable name for the node.
|
|
68
70
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
71
|
+
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
69
72
|
* @req REQ-ANNOTATION-REPORTING - Report missing @req annotation to context
|
|
73
|
+
* @req REQ-ERROR-SPECIFIC - Provide specific error details including node name
|
|
74
|
+
* @req REQ-ERROR-LOCATION - Include contextual location information in errors
|
|
70
75
|
*/
|
|
71
76
|
function reportMissing(context, node) {
|
|
77
|
+
const rawName = (0, require_story_utils_1.getNodeName)(node);
|
|
78
|
+
const name = rawName ?? "(anonymous)";
|
|
72
79
|
context.report({
|
|
73
80
|
node,
|
|
74
81
|
messageId: "missingReq",
|
|
82
|
+
data: { name },
|
|
75
83
|
fix: createMissingReqFix(node),
|
|
76
84
|
});
|
|
77
85
|
}
|
|
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
* Tests for: docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
8
8
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
9
9
|
* @req REQ-ANNOTATION-REQUIRED - Verify require-req-annotation rule enforces @req on functions
|
|
10
|
+
* @story docs/stories/007.0-DEV-ERROR-REPORTING.story.md
|
|
11
|
+
* @req REQ-ERROR-SPECIFIC - Verify enhanced, specific error messaging behavior
|
|
10
12
|
*/
|
|
11
13
|
const eslint_1 = require("eslint");
|
|
12
14
|
const require_req_annotation_1 = __importDefault(require("../../src/rules/require-req-annotation"));
|
|
@@ -48,19 +50,19 @@ describe("Require Req Annotation Rule (Story 003.0-DEV-FUNCTION-ANNOTATIONS)", (
|
|
|
48
50
|
name: "[REQ-ANNOTATION-REQUIRED] missing @req on function without JSDoc",
|
|
49
51
|
code: `function baz() {}`,
|
|
50
52
|
output: `/** @req <REQ-ID> */\nfunction baz() {}`,
|
|
51
|
-
errors: [{ messageId: "missingReq" }],
|
|
53
|
+
errors: [{ messageId: "missingReq", data: { name: "baz" } }],
|
|
52
54
|
},
|
|
53
55
|
{
|
|
54
56
|
name: "[REQ-ANNOTATION-REQUIRED] missing @req on function with only @story annotation",
|
|
55
57
|
code: `/**\n * @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md\n */\nfunction qux() {}`,
|
|
56
58
|
output: `/**\n * @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md\n */\n/** @req <REQ-ID> */\nfunction qux() {}`,
|
|
57
|
-
errors: [{ messageId: "missingReq" }],
|
|
59
|
+
errors: [{ messageId: "missingReq", data: { name: "qux" } }],
|
|
58
60
|
},
|
|
59
61
|
{
|
|
60
62
|
name: "[REQ-TYPESCRIPT-SUPPORT] missing @req on TSDeclareFunction",
|
|
61
63
|
code: `declare function baz(): void;`,
|
|
62
64
|
output: `/** @req <REQ-ID> */\ndeclare function baz(): void;`,
|
|
63
|
-
errors: [{ messageId: "missingReq" }],
|
|
65
|
+
errors: [{ messageId: "missingReq", data: { name: "baz" } }],
|
|
64
66
|
languageOptions: {
|
|
65
67
|
parser: require("@typescript-eslint/parser"),
|
|
66
68
|
parserOptions: { ecmaVersion: 2022, sourceType: "module" },
|
|
@@ -70,7 +72,7 @@ describe("Require Req Annotation Rule (Story 003.0-DEV-FUNCTION-ANNOTATIONS)", (
|
|
|
70
72
|
name: "[REQ-TYPESCRIPT-SUPPORT] missing @req on TSMethodSignature",
|
|
71
73
|
code: `interface I { method(): void; }`,
|
|
72
74
|
output: `interface I { /** @req <REQ-ID> */\nmethod(): void; }`,
|
|
73
|
-
errors: [{ messageId: "missingReq" }],
|
|
75
|
+
errors: [{ messageId: "missingReq", data: { name: "method" } }],
|
|
74
76
|
languageOptions: {
|
|
75
77
|
parser: require("@typescript-eslint/parser"),
|
|
76
78
|
parserOptions: { ecmaVersion: 2022, sourceType: "module" },
|
|
@@ -78,6 +78,30 @@ describe("Valid Annotation Format Rule (Story 005.0-DEV-ANNOTATION-VALIDATION)",
|
|
|
78
78
|
},
|
|
79
79
|
],
|
|
80
80
|
},
|
|
81
|
+
{
|
|
82
|
+
name: "[REQ-PATH-FORMAT] missing extension in story path",
|
|
83
|
+
code: `// @story docs/stories/005.0-DEV-ANNOTATION-VALIDATION`,
|
|
84
|
+
errors: [
|
|
85
|
+
{
|
|
86
|
+
messageId: "invalidStoryFormat",
|
|
87
|
+
data: {
|
|
88
|
+
details: 'Invalid story path "docs/stories/005.0-DEV-ANNOTATION-VALIDATION" for @story annotation. Expected a path like "docs/stories/005.0-DEV-EXAMPLE.story.md".',
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: "[REQ-PATH-FORMAT] story path must not use path traversal",
|
|
95
|
+
code: `// @story ../docs/stories/005.0-DEV-ANNOTATION-VALIDATION.story.md`,
|
|
96
|
+
errors: [
|
|
97
|
+
{
|
|
98
|
+
messageId: "invalidStoryFormat",
|
|
99
|
+
data: {
|
|
100
|
+
details: 'Invalid story path "../docs/stories/005.0-DEV-ANNOTATION-VALIDATION.story.md" for @story annotation. Expected a path like "docs/stories/005.0-DEV-EXAMPLE.story.md".',
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
},
|
|
81
105
|
{
|
|
82
106
|
name: "[REQ-REQ-FORMAT] missing req id (single line)",
|
|
83
107
|
code: `// @req`,
|
|
@@ -102,6 +126,18 @@ describe("Valid Annotation Format Rule (Story 005.0-DEV-ANNOTATION-VALIDATION)",
|
|
|
102
126
|
},
|
|
103
127
|
],
|
|
104
128
|
},
|
|
129
|
+
{
|
|
130
|
+
name: "[REQ-REQ-FORMAT] missing req identifier with trailing space",
|
|
131
|
+
code: `// @req `,
|
|
132
|
+
errors: [
|
|
133
|
+
{
|
|
134
|
+
messageId: "invalidReqFormat",
|
|
135
|
+
data: {
|
|
136
|
+
details: 'Missing requirement ID for @req annotation. Expected an identifier like "REQ-EXAMPLE".',
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
],
|
|
140
|
+
},
|
|
105
141
|
{
|
|
106
142
|
name: "[REQ-MULTILINE-SUPPORT] missing story path with multi-line block comment",
|
|
107
143
|
code: `/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-traceability",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.1",
|
|
4
4
|
"description": "A customizable ESLint plugin that enforces traceability annotations in your code, ensuring each implementation is linked to its requirement or test case.",
|
|
5
5
|
"main": "lib/src/index.js",
|
|
6
6
|
"types": "lib/src/index.d.ts",
|