eslint-plugin-traceability 1.4.5 → 1.4.6

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.
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Tests for: docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
3
+ * @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
4
+ * @req REQ-COVERAGE-HELPERS - Additional tests to exercise edge branches in require-story-helpers.ts
5
+ */
6
+ export {};
@@ -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,6 @@
1
+ /**
2
+ * Tests for: docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
3
+ * @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
4
+ * @req REQ-COVERAGE-IO - Additional tests to exercise uncovered branches in require-story-io.ts
5
+ */
6
+ export {};
@@ -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,6 @@
1
+ /**
2
+ * Tests for: docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
3
+ * @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
4
+ * @req REQ-COVERAGE-VISITORS - Tests to cover visitors branches in require-story-visitors.ts
5
+ */
6
+ export {};
@@ -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.5",
3
+ "version": "1.4.6",
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,12 @@
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": "npm run build && node scripts/lint-plugin-check.js",
20
+ "lint:require-built-plugin": "npm run lint-plugin-check",
19
21
  "lint": "eslint --config eslint.config.js \"src/**/*.{js,ts}\" \"tests/**/*.{js,ts}\" --max-warnings=0",
20
22
  "test": "jest --ci --bail",
23
+ "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",
24
+ "ci-verify:fast": "npm run lint-plugin-check && npm run type-check && npm run check:traceability && npm run duplication && jest --ci --bail --passWithNoTests --testPathPatterns 'tests/(unit|fast)'",
21
25
  "format": "prettier --write .",
22
26
  "format:check": "prettier --check \"src/**/*.ts\" \"tests/**/*.ts\"",
23
27
  "duplication": "jscpd src tests --reporters console --threshold 3 --ignore tests/utils/**",