eslint-plugin-traceability 1.1.10 → 1.1.11
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/README.md
CHANGED
|
@@ -21,6 +21,11 @@ For detailed setup with ESLint v9, see user-docs/eslint-9-setup-guide.md.
|
|
|
21
21
|
|
|
22
22
|
Add the plugin to your ESLint configuration and enable the rules.
|
|
23
23
|
|
|
24
|
+
Additional ESLint v9 configuration guidance:
|
|
25
|
+
|
|
26
|
+
- For detailed configuration examples, see [Common Configuration Patterns](user-docs/eslint-9-setup-guide.md#common-configuration-patterns) in the ESLint 9 Setup Guide.
|
|
27
|
+
- For troubleshooting ESLint flat-config errors, see [Troubleshooting ESLint Configuration](user-docs/eslint-9-setup-guide.md#troubleshooting-eslint-configuration).
|
|
28
|
+
|
|
24
29
|
Example eslint.config.js (ESLint v9 flat config):
|
|
25
30
|
|
|
26
31
|
```js
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* Rule to enforce @req annotation on functions
|
|
3
3
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
4
4
|
* @req REQ-ANNOTATION-REQUIRED - Require @req annotation on functions
|
|
5
|
+
* @req REQ-FUNCTION-DETECTION - Detect function declarations, expressions, arrow functions, and methods
|
|
6
|
+
* @req REQ-TYPESCRIPT-SUPPORT - Support TypeScript-specific function syntax
|
|
5
7
|
*/
|
|
6
8
|
declare const _default: any;
|
|
7
9
|
export default _default;
|
|
@@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
* Rule to enforce @req annotation on functions
|
|
5
5
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
6
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
|
|
7
9
|
*/
|
|
8
10
|
exports.default = {
|
|
9
11
|
meta: {
|
|
@@ -33,6 +35,48 @@ exports.default = {
|
|
|
33
35
|
});
|
|
34
36
|
}
|
|
35
37
|
},
|
|
38
|
+
/**
|
|
39
|
+
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
40
|
+
* @req REQ-TYPESCRIPT-SUPPORT
|
|
41
|
+
*/
|
|
42
|
+
TSDeclareFunction(node) {
|
|
43
|
+
const jsdoc = sourceCode.getJSDocComment(node);
|
|
44
|
+
const leading = node.leadingComments || [];
|
|
45
|
+
const comments = sourceCode.getCommentsBefore(node) || [];
|
|
46
|
+
const all = [...leading, ...comments];
|
|
47
|
+
const hasReq = (jsdoc && jsdoc.value.includes("@req")) ||
|
|
48
|
+
all.some((c) => c.value.includes("@req"));
|
|
49
|
+
if (!hasReq) {
|
|
50
|
+
context.report({
|
|
51
|
+
node,
|
|
52
|
+
messageId: "missingReq",
|
|
53
|
+
fix(fixer) {
|
|
54
|
+
return fixer.insertTextBefore(node, "/** @req <REQ-ID> */\n");
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
/**
|
|
60
|
+
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
61
|
+
* @req REQ-TYPESCRIPT-SUPPORT
|
|
62
|
+
*/
|
|
63
|
+
TSMethodSignature(node) {
|
|
64
|
+
const jsdoc = sourceCode.getJSDocComment(node);
|
|
65
|
+
const leading = node.leadingComments || [];
|
|
66
|
+
const comments = sourceCode.getCommentsBefore(node) || [];
|
|
67
|
+
const all = [...leading, ...comments];
|
|
68
|
+
const hasReq = (jsdoc && jsdoc.value.includes("@req")) ||
|
|
69
|
+
all.some((c) => c.value.includes("@req"));
|
|
70
|
+
if (!hasReq) {
|
|
71
|
+
context.report({
|
|
72
|
+
node,
|
|
73
|
+
messageId: "missingReq",
|
|
74
|
+
fix(fixer) {
|
|
75
|
+
return fixer.insertTextBefore(node, "/** @req <REQ-ID> */\n");
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
},
|
|
36
80
|
};
|
|
37
81
|
},
|
|
38
82
|
};
|
|
@@ -10,7 +10,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
10
10
|
*/
|
|
11
11
|
const eslint_1 = require("eslint");
|
|
12
12
|
const require_req_annotation_1 = __importDefault(require("../../src/rules/require-req-annotation"));
|
|
13
|
-
const ruleTester = new eslint_1.RuleTester(
|
|
13
|
+
const ruleTester = new eslint_1.RuleTester({
|
|
14
|
+
languageOptions: {
|
|
15
|
+
parserOptions: { ecmaVersion: 2022, sourceType: "module" },
|
|
16
|
+
},
|
|
17
|
+
});
|
|
14
18
|
describe("Require Req Annotation Rule (Story 003.0-DEV-FUNCTION-ANNOTATIONS)", () => {
|
|
15
19
|
ruleTester.run("require-req-annotation", require_req_annotation_1.default, {
|
|
16
20
|
valid: [
|
|
@@ -22,6 +26,22 @@ describe("Require Req Annotation Rule (Story 003.0-DEV-FUNCTION-ANNOTATIONS)", (
|
|
|
22
26
|
name: "[REQ-ANNOTATION-REQUIRED] valid with @story and @req annotations",
|
|
23
27
|
code: `/**\n * @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md\n * @req REQ-EXAMPLE\n */\nfunction bar() {}`,
|
|
24
28
|
},
|
|
29
|
+
{
|
|
30
|
+
name: "[REQ-TYPESCRIPT-SUPPORT] valid with @req annotation on TSDeclareFunction",
|
|
31
|
+
code: `/**\n * @req REQ-EXAMPLE\n */\ndeclare function foo(): void;`,
|
|
32
|
+
languageOptions: {
|
|
33
|
+
parser: require("@typescript-eslint/parser"),
|
|
34
|
+
parserOptions: { ecmaVersion: 2022, sourceType: "module" },
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "[REQ-TYPESCRIPT-SUPPORT] valid with @req annotation on TSMethodSignature",
|
|
39
|
+
code: `interface I {\n /**\n * @req REQ-EXAMPLE\n */\n method(): void;\n}`,
|
|
40
|
+
languageOptions: {
|
|
41
|
+
parser: require("@typescript-eslint/parser"),
|
|
42
|
+
parserOptions: { ecmaVersion: 2022, sourceType: "module" },
|
|
43
|
+
},
|
|
44
|
+
},
|
|
25
45
|
],
|
|
26
46
|
invalid: [
|
|
27
47
|
{
|
|
@@ -36,6 +56,26 @@ describe("Require Req Annotation Rule (Story 003.0-DEV-FUNCTION-ANNOTATIONS)", (
|
|
|
36
56
|
output: `/**\n * @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md\n */\n/** @req <REQ-ID> */\nfunction qux() {}`,
|
|
37
57
|
errors: [{ messageId: "missingReq" }],
|
|
38
58
|
},
|
|
59
|
+
{
|
|
60
|
+
name: "[REQ-TYPESCRIPT-SUPPORT] missing @req on TSDeclareFunction",
|
|
61
|
+
code: `declare function baz(): void;`,
|
|
62
|
+
output: `/** @req <REQ-ID> */\ndeclare function baz(): void;`,
|
|
63
|
+
errors: [{ messageId: "missingReq" }],
|
|
64
|
+
languageOptions: {
|
|
65
|
+
parser: require("@typescript-eslint/parser"),
|
|
66
|
+
parserOptions: { ecmaVersion: 2022, sourceType: "module" },
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: "[REQ-TYPESCRIPT-SUPPORT] missing @req on TSMethodSignature",
|
|
71
|
+
code: `interface I { method(): void; }`,
|
|
72
|
+
output: `interface I { /** @req <REQ-ID> */\nmethod(): void; }`,
|
|
73
|
+
errors: [{ messageId: "missingReq" }],
|
|
74
|
+
languageOptions: {
|
|
75
|
+
parser: require("@typescript-eslint/parser"),
|
|
76
|
+
parserOptions: { ecmaVersion: 2022, sourceType: "module" },
|
|
77
|
+
},
|
|
78
|
+
},
|
|
39
79
|
],
|
|
40
80
|
});
|
|
41
81
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-traceability",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.11",
|
|
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",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"build": "tsc -p tsconfig.json",
|
|
18
18
|
"type-check": "tsc --noEmit -p tsconfig.json",
|
|
19
19
|
"lint": "eslint \"src/**/*.{js,ts}\" \"tests/**/*.{js,ts}\" --max-warnings=0",
|
|
20
|
-
"test": "jest --ci --bail",
|
|
20
|
+
"test": "jest --ci --bail && node tests/integration/cli-integration.js",
|
|
21
21
|
"format": "prettier --write .",
|
|
22
22
|
"format:check": "prettier --check .",
|
|
23
23
|
"duplication": "jscpd src tests --reporters console --threshold 3",
|