eslint-plugin-traceability 1.4.6 → 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.
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import type { Rule } from "eslint";
8
8
  /**
9
- * @story docs/stories/001.2-RULE-NAMES-DECLARATION.story.md
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/001.2-RULE-NAMES-DECLARATION.story.md
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,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 branches (Story 003.0)", () => {
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 })),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-traceability",
3
- "version": "1.4.6",
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,12 +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": "npm run build && node scripts/lint-plugin-check.js",
20
- "lint:require-built-plugin": "npm run lint-plugin-check",
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",
21
22
  "lint": "eslint --config eslint.config.js \"src/**/*.{js,ts}\" \"tests/**/*.{js,ts}\" --max-warnings=0",
22
23
  "test": "jest --ci --bail",
23
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",
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)'",
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)'",
25
26
  "format": "prettier --write .",
26
27
  "format:check": "prettier --check \"src/**/*.ts\" \"tests/**/*.ts\"",
27
28
  "duplication": "jscpd src tests --reporters console --threshold 3 --ignore tests/utils/**",