eslint-plugin-traceability 1.15.0 → 1.16.0

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +2 -2
  2. package/README.md +61 -13
  3. package/lib/src/index.js +59 -0
  4. package/lib/src/rules/helpers/require-story-core.js +1 -1
  5. package/lib/src/rules/helpers/require-story-helpers.d.ts +10 -3
  6. package/lib/src/rules/helpers/require-story-helpers.js +66 -7
  7. package/lib/src/rules/no-redundant-annotation.js +73 -55
  8. package/lib/src/rules/require-branch-annotation.js +2 -2
  9. package/lib/src/rules/require-req-annotation.js +2 -2
  10. package/lib/src/rules/require-story-annotation.js +8 -3
  11. package/lib/src/rules/require-traceability.js +8 -9
  12. package/lib/src/utils/annotation-checker.js +23 -4
  13. package/lib/tests/cli-error-handling.test.js +10 -1
  14. package/lib/tests/integration/cli-integration.test.js +5 -0
  15. package/lib/tests/integration/require-traceability-aliases.integration.test.js +126 -0
  16. package/lib/tests/plugin-default-export-and-configs.test.js +23 -0
  17. package/lib/tests/rules/auto-fix-behavior-008.test.js +7 -7
  18. package/lib/tests/rules/error-reporting.test.js +1 -1
  19. package/lib/tests/rules/no-redundant-annotation.test.js +20 -0
  20. package/lib/tests/rules/require-story-annotation.test.js +49 -10
  21. package/lib/tests/rules/require-story-helpers.test.js +32 -0
  22. package/lib/tests/rules/require-story-utils.test.d.ts +7 -0
  23. package/lib/tests/rules/require-story-utils.test.js +158 -0
  24. package/lib/tests/utils/annotation-checker-branches.test.d.ts +5 -0
  25. package/lib/tests/utils/annotation-checker-branches.test.js +103 -0
  26. package/lib/tests/utils/annotation-scope-analyzer.test.js +134 -0
  27. package/lib/tests/utils/branch-annotation-helpers.test.js +66 -0
  28. package/package.json +2 -2
  29. package/user-docs/api-reference.md +71 -15
  30. package/user-docs/examples.md +24 -13
  31. package/user-docs/migration-guide.md +127 -4
  32. package/user-docs/traceability-overview.md +116 -0
  33. package/lib/tests/integration/dogfooding-validation.test.js +0 -129
  34. /package/lib/tests/integration/{dogfooding-validation.test.d.ts → require-traceability-aliases.integration.test.d.ts} +0 -0
@@ -1,129 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- /**
37
- * Dogfooding validation integration tests
38
- * @supports docs/stories/023.0-MAINT-DOGFOODING-VALIDATION.story.md REQ-DOGFOODING-TEST REQ-DOGFOODING-CI REQ-DOGFOODING-VERIFY REQ-DOGFOODING-PRESET
39
- */
40
- const path = __importStar(require("path"));
41
- const child_process_1 = require("child_process");
42
- const use_at_your_own_risk_1 = require("eslint/use-at-your-own-risk");
43
- const index_1 = __importStar(require("../../src/index"));
44
- /**
45
- * @supports docs/stories/023.0-MAINT-DOGFOODING-VALIDATION.story.md REQ-DOGFOODING-TEST
46
- */
47
- function getTsConfigFromEslintConfig(eslintConfig) {
48
- const configs = Array.isArray(eslintConfig) ? eslintConfig : [eslintConfig];
49
- return configs.find((config) => {
50
- if (!config || !config.files)
51
- return false;
52
- const files = config.files;
53
- return files.includes("**/*.ts") && files.includes("**/*.tsx");
54
- });
55
- }
56
- describe("Dogfooding Validation (Story 023.0-MAINT-DOGFOODING-VALIDATION)", () => {
57
- // TEMPORARILY SKIPPED - dogfooding rules disabled pending systematic annotation format review
58
- // @story docs/stories/023.0-MAINT-DOGFOODING-VALIDATION.story.md
59
- // @req REQ-DOGFOODING - Plugin should dogfood its own rules
60
- it.skip("[REQ-DOGFOODING-TEST] should have traceability/require-story-annotation enabled for TS sources", () => {
61
- /**
62
- * @supports docs/stories/023.0-MAINT-DOGFOODING-VALIDATION.story.md REQ-DOGFOODING-TEST
63
- */
64
- // Require the project's eslint.config.js and find the TS-specific config
65
- // that applies to *.ts and *.tsx files.
66
- const eslintConfig = require("../../eslint.config.js");
67
- const tsConfig = getTsConfigFromEslintConfig(eslintConfig);
68
- expect(tsConfig).toBeDefined();
69
- const rules = tsConfig.rules || {};
70
- const ruleEntry = rules["traceability/require-story-annotation"];
71
- expect(ruleEntry).toBeDefined();
72
- const severity = Array.isArray(ruleEntry) && ruleEntry.length > 0
73
- ? ruleEntry[0]
74
- : ruleEntry;
75
- expect(severity).toBe("error");
76
- });
77
- it("[REQ-DOGFOODING-CI] should run traceability/require-story-annotation via ESLint CLI on TS sources", () => {
78
- /**
79
- * @supports docs/stories/023.0-MAINT-DOGFOODING-VALIDATION.story.md REQ-DOGFOODING-CI
80
- */
81
- const eslintBin = path.resolve(__dirname, "../../node_modules/.bin/eslint");
82
- const configPath = path.resolve(__dirname, "../../eslint.config.js");
83
- const tsSnippet = `
84
- const x: number = 42;
85
- export function foo() {
86
- return x;
87
- }
88
- `;
89
- const result = (0, child_process_1.spawnSync)(process.platform === "win32" ? `${eslintBin}.cmd` : eslintBin, ["--config", configPath, "--stdin", "--stdin-filename", "src/dogfood.ts"], {
90
- encoding: "utf8",
91
- input: tsSnippet,
92
- });
93
- // The snippet intentionally lacks @story annotations, so the rule should
94
- // report an error for the generated `src/dogfood.ts` virtual file.
95
- expect(result.status).not.toBe(0);
96
- expect(result.stdout).toContain("error");
97
- expect(result.stdout).toContain("src/dogfood.ts");
98
- });
99
- it.skip("[REQ-DOGFOODING-VERIFY] should report at least one traceability rule active for TS sources", () => {
100
- /**
101
- * @supports docs/stories/023.0-MAINT-DOGFOODING-VALIDATION.story.md REQ-DOGFOODING-VERIFY
102
- */
103
- const eslintConfig = require("../../eslint.config.js");
104
- const tsConfig = getTsConfigFromEslintConfig(eslintConfig);
105
- expect(tsConfig).toBeDefined();
106
- const rules = tsConfig.rules || {};
107
- const hasTraceabilityRule = Object.keys(rules).some((key) => key.startsWith("traceability/"));
108
- expect(hasTraceabilityRule).toBe(true);
109
- });
110
- it("[REQ-DOGFOODING-PRESET] should be compatible with recommended preset usage without throwing", async () => {
111
- /**
112
- * @supports docs/stories/023.0-MAINT-DOGFOODING-VALIDATION.story.md REQ-DOGFOODING-PRESET
113
- */
114
- const config = [
115
- { plugins: { traceability: index_1.default }, rules: {} },
116
- ...index_1.configs.recommended,
117
- ];
118
- const eslint = new use_at_your_own_risk_1.FlatESLint({
119
- overrideConfig: config,
120
- overrideConfigFile: true,
121
- ignore: false,
122
- });
123
- const results = await eslint.lintText("function foo() {}", {
124
- filePath: "example.ts",
125
- });
126
- expect(results.length).toBeGreaterThanOrEqual(1);
127
- expect(Array.isArray(results[0].messages)).toBe(true);
128
- });
129
- });