eslint-plugin-traceability 1.0.1 → 1.0.2

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.
@@ -7,73 +7,78 @@
7
7
  import { spawnSync, SpawnSyncReturns } from "child_process";
8
8
  import path from "path";
9
9
 
10
+ // Ensure ESLint CLI uses built plugin
10
11
  const eslintBin = path.resolve(__dirname, "../../node_modules/.bin/eslint");
11
12
  const configPath = path.resolve(__dirname, "../../eslint.config.js");
12
13
 
13
- function runEslint(code: string, rule: string): SpawnSyncReturns<string> {
14
- const args = [
15
- "--no-config-lookup",
16
- "--config",
17
- configPath,
18
- "--stdin",
19
- "--stdin-filename",
20
- "foo.js",
21
- "--rule",
22
- "no-unused-vars:off",
23
- "--rule",
24
- rule,
25
- ];
26
- // Use Node to run the ESLint CLI script
27
- return spawnSync("node", [eslintBin, ...args], {
28
- encoding: "utf-8",
29
- input: code,
14
+ describe("ESLint CLI Integration (Story 001.0-DEV-PLUGIN-SETUP)", () => {
15
+ /**
16
+ * Helper to run ESLint CLI with the traceability plugin and custom rule
17
+ * @story docs/stories/001.0-DEV-PLUGIN-SETUP.story.md
18
+ * @req REQ-PLUGIN-STRUCTURE - Invoke ESLint CLI for integration testing
19
+ */
20
+ function runEslint(code: string, rule: string): SpawnSyncReturns<string> {
21
+ const args = [
22
+ "--no-config-lookup",
23
+ "--config",
24
+ configPath,
25
+ "--stdin",
26
+ "--stdin-filename",
27
+ "foo.js",
28
+ "--rule",
29
+ "no-unused-vars:off",
30
+ "--rule",
31
+ rule,
32
+ ];
33
+ return spawnSync("node", [eslintBin, ...args], {
34
+ encoding: "utf-8",
35
+ input: code,
36
+ });
37
+ }
38
+
39
+ it("[REQ-PLUGIN-STRUCTURE] reports error when @story annotation is missing", () => {
40
+ // Arrange
41
+ const code = "function foo() {}";
42
+ const rule = "traceability/require-story-annotation:error";
43
+ // Act
44
+ const result = runEslint(code, rule);
45
+ // Assert
46
+ expect(result.status).toBe(1);
47
+ expect(result.stdout).toMatch(/require-story-annotation/);
48
+ });
49
+
50
+ it("[REQ-PLUGIN-STRUCTURE] does not report error when @story annotation is present", () => {
51
+ // Arrange
52
+ const code = `/**
53
+ * @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
54
+ */
55
+ function foo() {}`;
56
+ const rule = "traceability/require-story-annotation:error";
57
+ // Act
58
+ const result = runEslint(code, rule);
59
+ // Assert
60
+ expect(result.status).toBe(0);
30
61
  });
31
- }
32
62
 
33
- const cliTests = [
34
- {
35
- name: "[REQ-PLUGIN-STRUCTURE] reports error when @story annotation is missing",
36
- code: "function foo() {}",
37
- rule: "traceability/require-story-annotation:error",
38
- expectedStatus: 1,
39
- stdoutRegex: /require-story-annotation/,
40
- },
41
- {
42
- name: "does not report error when @story annotation is present",
43
- code: `
44
- /**
45
- * @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
46
- */
47
- function foo() {}
48
- `,
49
- rule: "traceability/require-story-annotation:error",
50
- expectedStatus: 0,
51
- },
52
- {
53
- name: "Require Req Annotation CLI (Story 003.0-DEV-FUNCTION-ANNOTATIONS)",
54
- code: "function foo() {}",
55
- rule: "traceability/require-req-annotation:error",
56
- expectedStatus: 1,
57
- stdoutRegex: /require-req-annotation/,
58
- },
59
- {
60
- name: "Require Branch Annotation CLI (Story 004.0-DEV-BRANCH-ANNOTATIONS)",
61
- code: "if (condition) {}",
62
- rule: "traceability/require-branch-annotation:error",
63
- expectedStatus: 1,
64
- stdoutRegex: /require-branch-annotation/,
65
- },
66
- ];
63
+ it("[REQ-REQ-CLI] reports error when @req annotation is missing", () => {
64
+ // Arrange
65
+ const code = "function foo() {}";
66
+ const rule = "traceability/require-req-annotation:error";
67
+ // Act
68
+ const result = runEslint(code, rule);
69
+ // Assert
70
+ expect(result.status).toBe(1);
71
+ expect(result.stdout).toMatch(/require-req-annotation/);
72
+ });
67
73
 
68
- describe("ESLint CLI Integration (Story 001.0-DEV-PLUGIN-SETUP)", () => {
69
- test.each(cliTests)(
70
- "$name",
71
- ({ code, rule, expectedStatus, stdoutRegex }) => {
72
- const result = runEslint(code, rule);
73
- expect(result.status).toBe(expectedStatus);
74
- if (stdoutRegex) {
75
- expect(result.stdout).toMatch(stdoutRegex);
76
- }
77
- },
78
- );
74
+ it("[REQ-BRANCH-CLI] reports error when branch annotations missing", () => {
75
+ // Arrange
76
+ const code = "if (true) {}";
77
+ const rule = "traceability/require-branch-annotation:error";
78
+ // Act
79
+ const result = runEslint(code, rule);
80
+ // Assert
81
+ expect(result.status).toBe(1);
82
+ expect(result.stdout).toMatch(/require-branch-annotation/);
83
+ });
79
84
  });
@@ -15,6 +15,7 @@ describe("detectStaleAnnotations isolated (Story 009.0-DEV-MAINTENANCE-TOOLS)",
15
15
  });
16
16
 
17
17
  it("[REQ-MAINT-DETECT] detects stale annotations in nested directories", () => {
18
+ // Arrange
18
19
  const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "tmp-nested-"));
19
20
  const nestedDir = path.join(tmpDir, "nested");
20
21
  fs.mkdirSync(nestedDir);
@@ -33,10 +34,13 @@ describe("detectStaleAnnotations isolated (Story 009.0-DEV-MAINTENANCE-TOOLS)",
33
34
  `;
34
35
  fs.writeFileSync(filePath2, content2, "utf8");
35
36
 
37
+ // Act
36
38
  const result = detectStaleAnnotations(tmpDir);
37
- expect(result.sort()).toEqual(
38
- ["stale1.story.md", "stale2.story.md"].sort(),
39
- );
39
+
40
+ // Assert
41
+ expect(result).toHaveLength(2);
42
+ expect(result).toContain("stale1.story.md");
43
+ expect(result).toContain("stale2.story.md");
40
44
  });
41
45
 
42
46
  it("[REQ-MAINT-DETECT] throws error on permission denied", () => {
@@ -1,6 +1,8 @@
1
- // Tests for: docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md
2
- // @story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md
3
- // @req REQ-BRANCH-DETECTION - Verify require-branch-annotation rule enforces branch annotations
1
+ /**
2
+ * Tests for: docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md
3
+ * @story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md
4
+ * @req REQ-BRANCH-DETECTION - Verify require-branch-annotation rule enforces branch annotations
5
+ */
4
6
  import { RuleTester } from "eslint";
5
7
  import rule from "../../src/rules/require-branch-annotation";
6
8
 
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Tests for: docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
3
3
  * @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
4
+ * @req REQ-ANNOTATION-REQUIRED - Verify require-story-annotation rule enforces @story annotation on functions
4
5
  */
5
6
  import { RuleTester } from "eslint";
6
7
  import rule from "../../src/rules/require-story-annotation";