eslint-plugin-traceability 1.4.5 → 1.4.7
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 +1 -1
- package/lib/src/index.js +1 -1
- package/lib/tests/rules/require-story-core.autofix.test.d.ts +1 -0
- package/lib/tests/rules/require-story-core.autofix.test.js +69 -0
- package/lib/tests/rules/require-story-core.branches.test.js +1 -1
- package/lib/tests/rules/require-story-helpers.branches.test.d.ts +6 -0
- package/lib/tests/rules/require-story-helpers.branches.test.js +79 -0
- package/lib/tests/rules/require-story-io.branches.test.d.ts +6 -0
- package/lib/tests/rules/require-story-io.branches.test.js +50 -0
- package/lib/tests/rules/require-story-visitors.branches.test.d.ts +6 -0
- package/lib/tests/rules/require-story-visitors.branches.test.js +26 -0
- package/package.json +6 -1
package/lib/src/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { Rule } from "eslint";
|
|
8
8
|
/**
|
|
9
|
-
* @story docs/stories/
|
|
9
|
+
* @story docs/stories/002.0-DYNAMIC-RULE-LOADING.story.md
|
|
10
10
|
* @req REQ-RULE-LIST - Enumerate supported rule file names for plugin discovery
|
|
11
11
|
*/
|
|
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"];
|
package/lib/src/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.configs = exports.rules = void 0;
|
|
4
4
|
/**
|
|
5
|
-
* @story docs/stories/
|
|
5
|
+
* @story docs/stories/002.0-DYNAMIC-RULE-LOADING.story.md
|
|
6
6
|
* @req REQ-RULE-LIST - Enumerate supported rule file names for plugin discovery
|
|
7
7
|
*/
|
|
8
8
|
const RULE_NAMES = [
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Tests for: docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
5
|
+
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
6
|
+
* @req REQ-AUTOFIX - Cover additional branch cases in require-story-core (addStoryFixer/reportMissing)
|
|
7
|
+
*/
|
|
8
|
+
const require_story_core_1 = require("../../src/rules/helpers/require-story-core");
|
|
9
|
+
const require_story_helpers_1 = require("../../src/rules/helpers/require-story-helpers");
|
|
10
|
+
describe("Require Story Core (Story 003.0)", () => {
|
|
11
|
+
test("createAddStoryFix falls back to 0 when target is falsy", () => {
|
|
12
|
+
const fixer = {
|
|
13
|
+
insertTextBeforeRange: jest.fn((r, t) => ({ r, t })),
|
|
14
|
+
};
|
|
15
|
+
const fixFn = (0, require_story_core_1.createAddStoryFix)(null);
|
|
16
|
+
const res = fixFn(fixer);
|
|
17
|
+
expect(fixer.insertTextBeforeRange).toHaveBeenCalledTimes(1);
|
|
18
|
+
const args = fixer.insertTextBeforeRange.mock.calls[0];
|
|
19
|
+
expect(args[0]).toEqual([0, 0]);
|
|
20
|
+
expect(args[1]).toBe(`${require_story_helpers_1.ANNOTATION}\n`);
|
|
21
|
+
expect(res).toEqual({ r: [0, 0], t: `${require_story_helpers_1.ANNOTATION}\n` });
|
|
22
|
+
});
|
|
23
|
+
test("createAddStoryFix uses target.range when parent not export and parent.range missing", () => {
|
|
24
|
+
const target = {
|
|
25
|
+
type: "FunctionDeclaration",
|
|
26
|
+
range: [21, 33],
|
|
27
|
+
parent: { type: "ClassBody" },
|
|
28
|
+
};
|
|
29
|
+
const fixer = {
|
|
30
|
+
insertTextBeforeRange: jest.fn((r, t) => ({ r, t })),
|
|
31
|
+
};
|
|
32
|
+
const fixFn = (0, require_story_core_1.createAddStoryFix)(target);
|
|
33
|
+
const res = fixFn(fixer);
|
|
34
|
+
expect(fixer.insertTextBeforeRange.mock.calls[0][0]).toEqual([21, 21]);
|
|
35
|
+
expect(fixer.insertTextBeforeRange.mock.calls[0][1]).toBe(`${require_story_helpers_1.ANNOTATION}\n`);
|
|
36
|
+
expect(res).toEqual({ r: [21, 21], t: `${require_story_helpers_1.ANNOTATION}\n` });
|
|
37
|
+
});
|
|
38
|
+
test("createAddStoryFix prefers ExportDefaultDeclaration parent.range when present", () => {
|
|
39
|
+
const target = {
|
|
40
|
+
type: "FunctionDeclaration",
|
|
41
|
+
range: [50, 70],
|
|
42
|
+
parent: { type: "ExportDefaultDeclaration", range: [5, 100] },
|
|
43
|
+
};
|
|
44
|
+
const fixer = {
|
|
45
|
+
insertTextBeforeRange: jest.fn((r, t) => ({ r, t })),
|
|
46
|
+
};
|
|
47
|
+
const fixFn = (0, require_story_core_1.createAddStoryFix)(target);
|
|
48
|
+
const res = fixFn(fixer);
|
|
49
|
+
expect(fixer.insertTextBeforeRange.mock.calls[0][0]).toEqual([5, 5]);
|
|
50
|
+
expect(fixer.insertTextBeforeRange.mock.calls[0][1]).toBe(`${require_story_helpers_1.ANNOTATION}\n`);
|
|
51
|
+
expect(res).toEqual({ r: [5, 5], t: `${require_story_helpers_1.ANNOTATION}\n` });
|
|
52
|
+
});
|
|
53
|
+
test("reportMissing uses context.getSourceCode fallback when sourceCode not provided and still reports", () => {
|
|
54
|
+
const node = {
|
|
55
|
+
type: "FunctionDeclaration",
|
|
56
|
+
id: { name: "fnX" },
|
|
57
|
+
range: [0, 10],
|
|
58
|
+
};
|
|
59
|
+
const fakeSource = {
|
|
60
|
+
/* intentionally missing getJSDocComment to exercise branch */ getText: () => "",
|
|
61
|
+
};
|
|
62
|
+
const context = { getSourceCode: () => fakeSource, report: jest.fn() };
|
|
63
|
+
(0, require_story_core_1.reportMissing)(context, undefined, node, node);
|
|
64
|
+
expect(context.report).toHaveBeenCalledTimes(1);
|
|
65
|
+
const call = context.report.mock.calls[0][0];
|
|
66
|
+
expect(call.node).toBe(node);
|
|
67
|
+
expect(call.messageId).toBe("missingStory");
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
*/
|
|
8
8
|
const require_story_core_1 = require("../../src/rules/helpers/require-story-core");
|
|
9
9
|
const require_story_helpers_1 = require("../../src/rules/helpers/require-story-helpers");
|
|
10
|
-
describe("Require Story Core
|
|
10
|
+
describe("Require Story Core (Story 003.0)", () => {
|
|
11
11
|
test("createAddStoryFix falls back to 0 when target is falsy", () => {
|
|
12
12
|
const fixer = {
|
|
13
13
|
insertTextBeforeRange: jest.fn((r, t) => ({ r, t })),
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Tests for: docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
4
|
+
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
5
|
+
* @req REQ-COVERAGE-HELPERS - Additional tests to exercise edge branches in require-story-helpers.ts
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
const require_story_helpers_1 = require("../../src/rules/helpers/require-story-helpers");
|
|
9
|
+
describe("Require Story Helpers - additional branch coverage (Story 003.0)", () => {
|
|
10
|
+
test("jsdocHasStory returns false when JSDoc exists but value is not a string", () => {
|
|
11
|
+
const fakeSource = { getJSDocComment: () => ({ value: 123 }) };
|
|
12
|
+
const res = (0, require_story_helpers_1.jsdocHasStory)(fakeSource, {});
|
|
13
|
+
expect(res).toBe(false);
|
|
14
|
+
});
|
|
15
|
+
test("commentsBeforeHasStory returns false when comments exist but value is not a string", () => {
|
|
16
|
+
const fakeSource = { getCommentsBefore: () => [{ value: 123 }] };
|
|
17
|
+
const res = (0, require_story_helpers_1.commentsBeforeHasStory)(fakeSource, {});
|
|
18
|
+
expect(res).toBe(false);
|
|
19
|
+
});
|
|
20
|
+
test("leadingCommentsHasStory detects @story in leadingComments array", () => {
|
|
21
|
+
const node = {
|
|
22
|
+
leadingComments: [
|
|
23
|
+
{ type: "Block", value: "some other text" },
|
|
24
|
+
{
|
|
25
|
+
type: "Block",
|
|
26
|
+
value: "@story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md",
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
};
|
|
30
|
+
expect((0, require_story_helpers_1.leadingCommentsHasStory)(node)).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
test("resolveTargetNode returns ExpressionStatement parent for FunctionExpression", () => {
|
|
33
|
+
const fakeSource = { getText: () => "" };
|
|
34
|
+
const node = {
|
|
35
|
+
type: "FunctionExpression",
|
|
36
|
+
parent: { type: "ExpressionStatement" },
|
|
37
|
+
};
|
|
38
|
+
const resolved = (0, require_story_helpers_1.resolveTargetNode)(fakeSource, node);
|
|
39
|
+
expect(resolved).toBe(node.parent);
|
|
40
|
+
});
|
|
41
|
+
test("shouldProcessNode respects exportPriority 'exported' and 'non-exported'", () => {
|
|
42
|
+
const exportedNode = {
|
|
43
|
+
type: "FunctionDeclaration",
|
|
44
|
+
parent: { parent: { type: "ExportNamedDeclaration" } },
|
|
45
|
+
};
|
|
46
|
+
const nonExportedNode = {
|
|
47
|
+
type: "FunctionDeclaration",
|
|
48
|
+
parent: { parent: { type: "SomeOther" } },
|
|
49
|
+
};
|
|
50
|
+
expect((0, require_story_helpers_1.shouldProcessNode)(exportedNode, require_story_helpers_1.DEFAULT_SCOPE, "exported")).toBe(true);
|
|
51
|
+
expect((0, require_story_helpers_1.shouldProcessNode)(nonExportedNode, require_story_helpers_1.DEFAULT_SCOPE, "exported")).toBe(false);
|
|
52
|
+
// non-exported should reject exported nodes
|
|
53
|
+
expect((0, require_story_helpers_1.shouldProcessNode)(exportedNode, require_story_helpers_1.DEFAULT_SCOPE, "non-exported")).toBe(false);
|
|
54
|
+
expect((0, require_story_helpers_1.shouldProcessNode)(nonExportedNode, require_story_helpers_1.DEFAULT_SCOPE, "non-exported")).toBe(true);
|
|
55
|
+
});
|
|
56
|
+
test("reportMissing does not report when linesBeforeHasStory finds a preceding @story", () => {
|
|
57
|
+
const jsdoc = "/**\n * @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md\n */\n";
|
|
58
|
+
const rest = "function fnA() {}\n";
|
|
59
|
+
const full = jsdoc + rest;
|
|
60
|
+
const fakeSource = {
|
|
61
|
+
getText: () => full,
|
|
62
|
+
getJSDocComment: () => null,
|
|
63
|
+
lines: full.split(/\r?\n/),
|
|
64
|
+
getCommentsBefore: () => [],
|
|
65
|
+
};
|
|
66
|
+
const node = {
|
|
67
|
+
type: "FunctionDeclaration",
|
|
68
|
+
range: [full.indexOf("function"), full.length],
|
|
69
|
+
loc: {
|
|
70
|
+
start: {
|
|
71
|
+
line: fakeSource.lines.findIndex((l) => l.includes("function fnA() {}")) + 1,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
const context = { getSourceCode: () => fakeSource, report: jest.fn() };
|
|
76
|
+
(0, require_story_helpers_1.reportMissing)(context, fakeSource, node, node);
|
|
77
|
+
expect(context.report).not.toHaveBeenCalled();
|
|
78
|
+
});
|
|
79
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Tests for: docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
4
|
+
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
5
|
+
* @req REQ-COVERAGE-IO - Additional tests to exercise uncovered branches in require-story-io.ts
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
const require_story_io_1 = require("../../src/rules/helpers/require-story-io");
|
|
9
|
+
describe("Require Story IO helpers - branch coverage (Story 003.0)", () => {
|
|
10
|
+
test("parentChainHasStory returns false when sourceCode.getCommentsBefore is not a function", () => {
|
|
11
|
+
const fakeSource = {}; // no getCommentsBefore function
|
|
12
|
+
const node = { parent: { parent: null } };
|
|
13
|
+
expect((0, require_story_io_1.parentChainHasStory)(fakeSource, node)).toBe(false);
|
|
14
|
+
});
|
|
15
|
+
test("parentChainHasStory returns false when getCommentsBefore returns comments but none contain @story", () => {
|
|
16
|
+
const fakeSource = {
|
|
17
|
+
getCommentsBefore: () => [{ value: 123 }, { value: "no story here" }],
|
|
18
|
+
};
|
|
19
|
+
const node = { parent: { leadingComments: [], parent: null } };
|
|
20
|
+
expect((0, require_story_io_1.parentChainHasStory)(fakeSource, node)).toBe(false);
|
|
21
|
+
});
|
|
22
|
+
test("parentChainHasStory returns true when ancestor leadingComments contain @story", () => {
|
|
23
|
+
const fakeSource = { getCommentsBefore: () => [] };
|
|
24
|
+
const node = {
|
|
25
|
+
parent: {
|
|
26
|
+
leadingComments: [
|
|
27
|
+
{
|
|
28
|
+
value: "@story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md",
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
parent: null,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
expect((0, require_story_io_1.parentChainHasStory)(fakeSource, node)).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
test("fallbackTextBeforeHasStory returns false when node.range[0] is not a number", () => {
|
|
37
|
+
const fakeSource = { getText: () => "some text without story" };
|
|
38
|
+
const node = { range: ["a", 10] };
|
|
39
|
+
expect((0, require_story_io_1.fallbackTextBeforeHasStory)(fakeSource, node)).toBe(false);
|
|
40
|
+
});
|
|
41
|
+
test("fallbackTextBeforeHasStory detects @story in text before node.range", () => {
|
|
42
|
+
const story = "@story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md";
|
|
43
|
+
const pre = `/* ${story} */\n`;
|
|
44
|
+
const rest = "function y() {}";
|
|
45
|
+
const full = pre + rest;
|
|
46
|
+
const fakeSource = { getText: () => full };
|
|
47
|
+
const node = { range: [full.indexOf("function"), full.length] };
|
|
48
|
+
expect((0, require_story_io_1.fallbackTextBeforeHasStory)(fakeSource, node)).toBe(true);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Tests for: docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
4
|
+
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
5
|
+
* @req REQ-COVERAGE-VISITORS - Tests to cover visitors branches in require-story-visitors.ts
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
const require_story_visitors_1 = require("../../src/rules/helpers/require-story-visitors");
|
|
9
|
+
describe("Require Story Visitors - branch coverage (Story 003.0)", () => {
|
|
10
|
+
test("build visitors returns handlers for FunctionDeclaration and ArrowFunctionExpression", () => {
|
|
11
|
+
const fakeContext = { getFilename: () => "file.ts" };
|
|
12
|
+
const fakeSource = { getText: () => "" };
|
|
13
|
+
const options = { shouldProcessNode: () => true };
|
|
14
|
+
const visitors = (0, require_story_visitors_1.buildVisitors)(fakeContext, fakeSource, options);
|
|
15
|
+
expect(typeof visitors.FunctionDeclaration).toBe("function");
|
|
16
|
+
expect(typeof visitors.ArrowFunctionExpression).toBe("function");
|
|
17
|
+
});
|
|
18
|
+
test("FunctionDeclaration handler uses context.getFilename and doesn't throw when node lacks id", () => {
|
|
19
|
+
const fakeContext = { getFilename: () => "file.ts" };
|
|
20
|
+
const fakeSource = { getText: () => "" };
|
|
21
|
+
const options = { shouldProcessNode: () => true };
|
|
22
|
+
const visitors = (0, require_story_visitors_1.buildVisitors)(fakeContext, fakeSource, options);
|
|
23
|
+
const handler = visitors.FunctionDeclaration;
|
|
24
|
+
expect(() => handler({})).not.toThrow();
|
|
25
|
+
});
|
|
26
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-traceability",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.7",
|
|
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",
|
|
@@ -16,8 +16,13 @@
|
|
|
16
16
|
"build": "tsc -p tsconfig.json",
|
|
17
17
|
"type-check": "tsc --noEmit -p tsconfig.json",
|
|
18
18
|
"check:traceability": "node scripts/traceability-check.js",
|
|
19
|
+
"lint-plugin-check": "node scripts/lint-plugin-check.js",
|
|
20
|
+
"lint-plugin-guard": "node scripts/lint-plugin-guard.js",
|
|
21
|
+
"lint:require-built-plugin": "npm run lint-plugin-guard",
|
|
19
22
|
"lint": "eslint --config eslint.config.js \"src/**/*.{js,ts}\" \"tests/**/*.{js,ts}\" --max-warnings=0",
|
|
20
23
|
"test": "jest --ci --bail",
|
|
24
|
+
"ci-verify": "npm run type-check && npm run lint && npm run format:check && npm run duplication && npm run check:traceability && npm test && npm run audit:ci && npm run safety:deps",
|
|
25
|
+
"ci-verify:fast": "npm run lint:require-built-plugin && npm run type-check && npm run check:traceability && npm run duplication && jest --ci --bail --passWithNoTests --testPathPatterns 'tests/(unit|fast)'",
|
|
21
26
|
"format": "prettier --write .",
|
|
22
27
|
"format:check": "prettier --check \"src/**/*.ts\" \"tests/**/*.ts\"",
|
|
23
28
|
"duplication": "jscpd src tests --reporters console --threshold 3 --ignore tests/utils/**",
|