eslint-plugin-traceability 1.22.0 → 1.23.1
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/CHANGELOG.md +8 -7
- package/lib/{src/rules → rules}/require-req-annotation.js +51 -45
- package/package.json +9 -13
- package/user-docs/api-reference.md +2 -2
- package/lib/tests/cli-error-handling.test.d.ts +0 -1
- package/lib/tests/cli-error-handling.test.js +0 -54
- package/lib/tests/config/eslint-config-validation.test.d.ts +0 -9
- package/lib/tests/config/eslint-config-validation.test.js +0 -101
- package/lib/tests/config/flat-config-presets-integration.test.d.ts +0 -1
- package/lib/tests/config/flat-config-presets-integration.test.js +0 -76
- package/lib/tests/config/require-story-annotation-config.test.d.ts +0 -10
- package/lib/tests/config/require-story-annotation-config.test.js +0 -26
- package/lib/tests/fixtures/stale/example.d.ts +0 -0
- package/lib/tests/fixtures/stale/example.js +0 -4
- package/lib/tests/fixtures/update/example.d.ts +0 -0
- package/lib/tests/fixtures/update/example.js +0 -4
- package/lib/tests/fixtures/valid-annotations/example.d.ts +0 -0
- package/lib/tests/fixtures/valid-annotations/example.js +0 -3
- package/lib/tests/integration/annotation-placement-inside-prettier.integration.test.d.ts +0 -1
- package/lib/tests/integration/annotation-placement-inside-prettier.integration.test.js +0 -133
- package/lib/tests/integration/catch-annotation-prettier.integration.test.d.ts +0 -1
- package/lib/tests/integration/catch-annotation-prettier.integration.test.js +0 -121
- package/lib/tests/integration/cli-integration.test.d.ts +0 -1
- package/lib/tests/integration/cli-integration.test.js +0 -96
- package/lib/tests/integration/else-if-annotation-prettier.integration.test.d.ts +0 -1
- package/lib/tests/integration/else-if-annotation-prettier.integration.test.js +0 -100
- package/lib/tests/integration/no-redundant-annotation.integration.test.d.ts +0 -1
- package/lib/tests/integration/no-redundant-annotation.integration.test.js +0 -129
- package/lib/tests/integration/prettier-test-helpers.d.ts +0 -9
- package/lib/tests/integration/prettier-test-helpers.js +0 -35
- package/lib/tests/integration/require-traceability-aliases.integration.test.d.ts +0 -1
- package/lib/tests/integration/require-traceability-aliases.integration.test.js +0 -152
- package/lib/tests/integration/require-traceability-test-callbacks.integration.test.d.ts +0 -1
- package/lib/tests/integration/require-traceability-test-callbacks.integration.test.js +0 -149
- package/lib/tests/maintenance/batch.test.d.ts +0 -1
- package/lib/tests/maintenance/batch.test.js +0 -80
- package/lib/tests/maintenance/cli.test.d.ts +0 -1
- package/lib/tests/maintenance/cli.test.js +0 -306
- package/lib/tests/maintenance/detect-isolated.test.d.ts +0 -1
- package/lib/tests/maintenance/detect-isolated.test.js +0 -187
- package/lib/tests/maintenance/detect.test.d.ts +0 -1
- package/lib/tests/maintenance/detect.test.js +0 -46
- package/lib/tests/maintenance/index.test.d.ts +0 -1
- package/lib/tests/maintenance/index.test.js +0 -26
- package/lib/tests/maintenance/report.test.d.ts +0 -1
- package/lib/tests/maintenance/report.test.js +0 -68
- package/lib/tests/maintenance/storyParser.test.d.ts +0 -8
- package/lib/tests/maintenance/storyParser.test.js +0 -505
- package/lib/tests/maintenance/update-isolated.test.d.ts +0 -1
- package/lib/tests/maintenance/update-isolated.test.js +0 -71
- package/lib/tests/maintenance/update.test.d.ts +0 -1
- package/lib/tests/maintenance/update.test.js +0 -27
- package/lib/tests/perf/maintenance-cli-large-workspace.test.d.ts +0 -1
- package/lib/tests/perf/maintenance-cli-large-workspace.test.js +0 -229
- package/lib/tests/perf/maintenance-large-workspace.test.d.ts +0 -1
- package/lib/tests/perf/maintenance-large-workspace.test.js +0 -169
- package/lib/tests/perf/require-branch-annotation-large-file.test.d.ts +0 -1
- package/lib/tests/perf/require-branch-annotation-large-file.test.js +0 -67
- package/lib/tests/perf/valid-annotation-format-large-file.test.d.ts +0 -1
- package/lib/tests/perf/valid-annotation-format-large-file.test.js +0 -75
- package/lib/tests/plugin-default-export-and-configs.test.d.ts +0 -1
- package/lib/tests/plugin-default-export-and-configs.test.js +0 -121
- package/lib/tests/plugin-setup-error.test.d.ts +0 -6
- package/lib/tests/plugin-setup-error.test.js +0 -38
- package/lib/tests/plugin-setup.test.d.ts +0 -1
- package/lib/tests/plugin-setup.test.js +0 -63
- package/lib/tests/rules/auto-fix-behavior-008.test.d.ts +0 -1
- package/lib/tests/rules/auto-fix-behavior-008.test.js +0 -285
- package/lib/tests/rules/error-reporting.test.d.ts +0 -1
- package/lib/tests/rules/error-reporting.test.js +0 -99
- package/lib/tests/rules/no-redundant-annotation.test.d.ts +0 -1
- package/lib/tests/rules/no-redundant-annotation.test.js +0 -163
- package/lib/tests/rules/prefer-implements-annotation.test.d.ts +0 -1
- package/lib/tests/rules/prefer-implements-annotation.test.js +0 -162
- package/lib/tests/rules/require-branch-annotation.test.d.ts +0 -1
- package/lib/tests/rules/require-branch-annotation.test.js +0 -593
- package/lib/tests/rules/require-req-annotation.test.d.ts +0 -1
- package/lib/tests/rules/require-req-annotation.test.js +0 -246
- package/lib/tests/rules/require-story-annotation.test.d.ts +0 -1
- package/lib/tests/rules/require-story-annotation.test.js +0 -376
- package/lib/tests/rules/require-story-core-edgecases.test.d.ts +0 -1
- package/lib/tests/rules/require-story-core-edgecases.test.js +0 -15
- package/lib/tests/rules/require-story-core.autofix.test.d.ts +0 -1
- package/lib/tests/rules/require-story-core.autofix.test.js +0 -66
- package/lib/tests/rules/require-story-core.test.d.ts +0 -1
- package/lib/tests/rules/require-story-core.test.js +0 -65
- package/lib/tests/rules/require-story-helpers-edgecases.test.d.ts +0 -7
- package/lib/tests/rules/require-story-helpers-edgecases.test.js +0 -80
- package/lib/tests/rules/require-story-helpers.test.d.ts +0 -1
- package/lib/tests/rules/require-story-helpers.test.js +0 -474
- package/lib/tests/rules/require-story-io-behavior.test.d.ts +0 -7
- package/lib/tests/rules/require-story-io-behavior.test.js +0 -46
- package/lib/tests/rules/require-story-io.edgecases.test.d.ts +0 -7
- package/lib/tests/rules/require-story-io.edgecases.test.js +0 -46
- package/lib/tests/rules/require-story-utils.test.d.ts +0 -7
- package/lib/tests/rules/require-story-utils.test.js +0 -158
- package/lib/tests/rules/require-story-visitors-edgecases.test.d.ts +0 -7
- package/lib/tests/rules/require-story-visitors-edgecases.test.js +0 -27
- package/lib/tests/rules/require-test-traceability.test.d.ts +0 -1
- package/lib/tests/rules/require-test-traceability.test.js +0 -95
- package/lib/tests/rules/valid-annotation-format-internal.test.d.ts +0 -8
- package/lib/tests/rules/valid-annotation-format-internal.test.js +0 -47
- package/lib/tests/rules/valid-annotation-format.test.d.ts +0 -1
- package/lib/tests/rules/valid-annotation-format.test.js +0 -634
- package/lib/tests/rules/valid-req-reference.test.d.ts +0 -1
- package/lib/tests/rules/valid-req-reference.test.js +0 -129
- package/lib/tests/rules/valid-story-reference.test.d.ts +0 -1
- package/lib/tests/rules/valid-story-reference.test.js +0 -413
- package/lib/tests/utils/annotation-checker-autofix-behavior.test.d.ts +0 -5
- package/lib/tests/utils/annotation-checker-autofix-behavior.test.js +0 -103
- package/lib/tests/utils/annotation-checker.test.d.ts +0 -24
- package/lib/tests/utils/annotation-checker.test.js +0 -84
- package/lib/tests/utils/annotation-scope-analyzer.test.d.ts +0 -1
- package/lib/tests/utils/annotation-scope-analyzer.test.js +0 -211
- package/lib/tests/utils/branch-annotation-catch-insert-position.test.d.ts +0 -1
- package/lib/tests/utils/branch-annotation-catch-insert-position.test.js +0 -69
- package/lib/tests/utils/branch-annotation-catch-position.test.d.ts +0 -1
- package/lib/tests/utils/branch-annotation-catch-position.test.js +0 -115
- package/lib/tests/utils/branch-annotation-else-if-insert-position.test.d.ts +0 -1
- package/lib/tests/utils/branch-annotation-else-if-insert-position.test.js +0 -82
- package/lib/tests/utils/branch-annotation-else-if-position.test.d.ts +0 -1
- package/lib/tests/utils/branch-annotation-else-if-position.test.js +0 -145
- package/lib/tests/utils/branch-annotation-helpers.test.d.ts +0 -1
- package/lib/tests/utils/branch-annotation-helpers.test.js +0 -462
- package/lib/tests/utils/fsTestHelpers.d.ts +0 -7
- package/lib/tests/utils/fsTestHelpers.js +0 -26
- package/lib/tests/utils/ioTestHelpers.d.ts +0 -7
- package/lib/tests/utils/ioTestHelpers.js +0 -24
- package/lib/tests/utils/req-annotation-detection.test.d.ts +0 -1
- package/lib/tests/utils/req-annotation-detection.test.js +0 -358
- package/lib/tests/utils/require-story-core-test-helpers.d.ts +0 -10
- package/lib/tests/utils/require-story-core-test-helpers.js +0 -75
- package/lib/tests/utils/temp-dir-helpers.d.ts +0 -19
- package/lib/tests/utils/temp-dir-helpers.js +0 -62
- package/lib/tests/utils/ts-language-options.d.ts +0 -16
- package/lib/tests/utils/ts-language-options.js +0 -30
- /package/lib/{src/index.d.ts → index.d.ts} +0 -0
- /package/lib/{src/index.js → index.js} +0 -0
- /package/lib/{src/maintenance → maintenance}/batch.d.ts +0 -0
- /package/lib/{src/maintenance → maintenance}/batch.js +0 -0
- /package/lib/{src/maintenance → maintenance}/cli.d.ts +0 -0
- /package/lib/{src/maintenance → maintenance}/cli.js +0 -0
- /package/lib/{src/maintenance → maintenance}/commands.d.ts +0 -0
- /package/lib/{src/maintenance → maintenance}/commands.js +0 -0
- /package/lib/{src/maintenance → maintenance}/detect.d.ts +0 -0
- /package/lib/{src/maintenance → maintenance}/detect.js +0 -0
- /package/lib/{src/maintenance → maintenance}/flags.d.ts +0 -0
- /package/lib/{src/maintenance → maintenance}/flags.js +0 -0
- /package/lib/{src/maintenance → maintenance}/index.d.ts +0 -0
- /package/lib/{src/maintenance → maintenance}/index.js +0 -0
- /package/lib/{src/maintenance → maintenance}/report.d.ts +0 -0
- /package/lib/{src/maintenance → maintenance}/report.js +0 -0
- /package/lib/{src/maintenance → maintenance}/storyParser.d.ts +0 -0
- /package/lib/{src/maintenance → maintenance}/storyParser.js +0 -0
- /package/lib/{src/maintenance → maintenance}/update.d.ts +0 -0
- /package/lib/{src/maintenance → maintenance}/update.js +0 -0
- /package/lib/{src/maintenance → maintenance}/utils.d.ts +0 -0
- /package/lib/{src/maintenance → maintenance}/utils.js +0 -0
- /package/lib/{src/rules → rules}/helpers/pattern-validators.d.ts +0 -0
- /package/lib/{src/rules → rules}/helpers/pattern-validators.js +0 -0
- /package/lib/{src/rules → rules}/helpers/prefer-implements-inline.d.ts +0 -0
- /package/lib/{src/rules → rules}/helpers/prefer-implements-inline.js +0 -0
- /package/lib/{src/rules → rules}/helpers/require-story-comment-detection.d.ts +0 -0
- /package/lib/{src/rules → rules}/helpers/require-story-comment-detection.js +0 -0
- /package/lib/{src/rules → rules}/helpers/require-story-core.d.ts +0 -0
- /package/lib/{src/rules → rules}/helpers/require-story-core.js +0 -0
- /package/lib/{src/rules → rules}/helpers/require-story-helpers.d.ts +0 -0
- /package/lib/{src/rules → rules}/helpers/require-story-helpers.js +0 -0
- /package/lib/{src/rules → rules}/helpers/require-story-io.d.ts +0 -0
- /package/lib/{src/rules → rules}/helpers/require-story-io.js +0 -0
- /package/lib/{src/rules → rules}/helpers/require-story-name-extraction.d.ts +0 -0
- /package/lib/{src/rules → rules}/helpers/require-story-name-extraction.js +0 -0
- /package/lib/{src/rules → rules}/helpers/require-story-node-utils.d.ts +0 -0
- /package/lib/{src/rules → rules}/helpers/require-story-node-utils.js +0 -0
- /package/lib/{src/rules → rules}/helpers/require-story-utils.d.ts +0 -0
- /package/lib/{src/rules → rules}/helpers/require-story-utils.js +0 -0
- /package/lib/{src/rules → rules}/helpers/require-story-visitors.d.ts +0 -0
- /package/lib/{src/rules → rules}/helpers/require-story-visitors.js +0 -0
- /package/lib/{src/rules → rules}/helpers/require-test-traceability-helpers.d.ts +0 -0
- /package/lib/{src/rules → rules}/helpers/require-test-traceability-helpers.js +0 -0
- /package/lib/{src/rules → rules}/helpers/test-callback-exclusion.d.ts +0 -0
- /package/lib/{src/rules → rules}/helpers/test-callback-exclusion.js +0 -0
- /package/lib/{src/rules → rules}/helpers/valid-annotation-format-internal.d.ts +0 -0
- /package/lib/{src/rules → rules}/helpers/valid-annotation-format-internal.js +0 -0
- /package/lib/{src/rules → rules}/helpers/valid-annotation-format-validators.d.ts +0 -0
- /package/lib/{src/rules → rules}/helpers/valid-annotation-format-validators.js +0 -0
- /package/lib/{src/rules → rules}/helpers/valid-annotation-options.d.ts +0 -0
- /package/lib/{src/rules → rules}/helpers/valid-annotation-options.js +0 -0
- /package/lib/{src/rules → rules}/helpers/valid-annotation-utils.d.ts +0 -0
- /package/lib/{src/rules → rules}/helpers/valid-annotation-utils.js +0 -0
- /package/lib/{src/rules → rules}/helpers/valid-implements-utils.d.ts +0 -0
- /package/lib/{src/rules → rules}/helpers/valid-implements-utils.js +0 -0
- /package/lib/{src/rules → rules}/helpers/valid-req-reference-helpers.d.ts +0 -0
- /package/lib/{src/rules → rules}/helpers/valid-req-reference-helpers.js +0 -0
- /package/lib/{src/rules → rules}/helpers/valid-story-reference-helpers.d.ts +0 -0
- /package/lib/{src/rules → rules}/helpers/valid-story-reference-helpers.js +0 -0
- /package/lib/{src/rules → rules}/no-redundant-annotation.d.ts +0 -0
- /package/lib/{src/rules → rules}/no-redundant-annotation.js +0 -0
- /package/lib/{src/rules → rules}/prefer-implements-annotation.d.ts +0 -0
- /package/lib/{src/rules → rules}/prefer-implements-annotation.js +0 -0
- /package/lib/{src/rules → rules}/require-branch-annotation.d.ts +0 -0
- /package/lib/{src/rules → rules}/require-branch-annotation.js +0 -0
- /package/lib/{src/rules → rules}/require-req-annotation.d.ts +0 -0
- /package/lib/{src/rules → rules}/require-story-annotation.d.ts +0 -0
- /package/lib/{src/rules → rules}/require-story-annotation.js +0 -0
- /package/lib/{src/rules → rules}/require-test-traceability.d.ts +0 -0
- /package/lib/{src/rules → rules}/require-test-traceability.js +0 -0
- /package/lib/{src/rules → rules}/require-traceability.d.ts +0 -0
- /package/lib/{src/rules → rules}/require-traceability.js +0 -0
- /package/lib/{src/rules → rules}/valid-annotation-format.d.ts +0 -0
- /package/lib/{src/rules → rules}/valid-annotation-format.js +0 -0
- /package/lib/{src/rules → rules}/valid-req-reference.d.ts +0 -0
- /package/lib/{src/rules → rules}/valid-req-reference.js +0 -0
- /package/lib/{src/rules → rules}/valid-story-reference.d.ts +0 -0
- /package/lib/{src/rules → rules}/valid-story-reference.js +0 -0
- /package/lib/{src/utils → utils}/annotation-checker.d.ts +0 -0
- /package/lib/{src/utils → utils}/annotation-checker.js +0 -0
- /package/lib/{src/utils → utils}/annotation-scope-analyzer.d.ts +0 -0
- /package/lib/{src/utils → utils}/annotation-scope-analyzer.js +0 -0
- /package/lib/{src/utils → utils}/branch-annotation-catch-helpers.d.ts +0 -0
- /package/lib/{src/utils → utils}/branch-annotation-catch-helpers.js +0 -0
- /package/lib/{src/utils → utils}/branch-annotation-helpers.d.ts +0 -0
- /package/lib/{src/utils → utils}/branch-annotation-helpers.js +0 -0
- /package/lib/{src/utils → utils}/branch-annotation-if-helpers.d.ts +0 -0
- /package/lib/{src/utils → utils}/branch-annotation-if-helpers.js +0 -0
- /package/lib/{src/utils → utils}/branch-annotation-indent-helpers.d.ts +0 -0
- /package/lib/{src/utils → utils}/branch-annotation-indent-helpers.js +0 -0
- /package/lib/{src/utils → utils}/branch-annotation-loop-helpers.d.ts +0 -0
- /package/lib/{src/utils → utils}/branch-annotation-loop-helpers.js +0 -0
- /package/lib/{src/utils → utils}/branch-annotation-report-helpers.d.ts +0 -0
- /package/lib/{src/utils → utils}/branch-annotation-report-helpers.js +0 -0
- /package/lib/{src/utils → utils}/branch-annotation-story-fix-helpers.d.ts +0 -0
- /package/lib/{src/utils → utils}/branch-annotation-story-fix-helpers.js +0 -0
- /package/lib/{src/utils → utils}/branch-annotation-switch-helpers.d.ts +0 -0
- /package/lib/{src/utils → utils}/branch-annotation-switch-helpers.js +0 -0
- /package/lib/{src/utils → utils}/branch-validation.d.ts +0 -0
- /package/lib/{src/utils → utils}/branch-validation.js +0 -0
- /package/lib/{src/utils → utils}/comment-text-helpers.d.ts +0 -0
- /package/lib/{src/utils → utils}/comment-text-helpers.js +0 -0
- /package/lib/{src/utils → utils}/function-annotation-helpers.d.ts +0 -0
- /package/lib/{src/utils → utils}/function-annotation-helpers.js +0 -0
- /package/lib/{src/utils → utils}/redundancy-detector.d.ts +0 -0
- /package/lib/{src/utils → utils}/redundancy-detector.js +0 -0
- /package/lib/{src/utils → utils}/reqAnnotationDetection.d.ts +0 -0
- /package/lib/{src/utils → utils}/reqAnnotationDetection.js +0 -0
- /package/lib/{src/utils → utils}/storyReferenceUtils.d.ts +0 -0
- /package/lib/{src/utils → utils}/storyReferenceUtils.js +0 -0
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const branch_annotation_helpers_1 = require("../../src/utils/branch-annotation-helpers");
|
|
4
|
-
function createMockSourceCode(options) {
|
|
5
|
-
const { lines = [], commentsBefore = [] } = options;
|
|
6
|
-
return {
|
|
7
|
-
lines,
|
|
8
|
-
getCommentsBefore() {
|
|
9
|
-
return commentsBefore;
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
describe("gatherBranchCommentText else-if behavior (Story 026.0-DEV-ELSE-IF-ANNOTATION-POSITION)", () => {
|
|
14
|
-
it("[REQ-DUAL-POSITION-DETECTION-ELSE-IF] detects annotations placed before the else-if keyword", () => {
|
|
15
|
-
const sourceCode = createMockSourceCode({
|
|
16
|
-
commentsBefore: [
|
|
17
|
-
{
|
|
18
|
-
value: "@story docs/stories/026.0-DEV-ELSE-IF-ANNOTATION-POSITION.story.md",
|
|
19
|
-
},
|
|
20
|
-
{ value: "@req REQ-DUAL-POSITION-DETECTION-ELSE-IF" },
|
|
21
|
-
],
|
|
22
|
-
// lines are unused in this case because we short-circuit on before-text annotations.
|
|
23
|
-
lines: [],
|
|
24
|
-
});
|
|
25
|
-
const node = {
|
|
26
|
-
type: "IfStatement",
|
|
27
|
-
loc: { start: { line: 10 } },
|
|
28
|
-
};
|
|
29
|
-
const parent = {
|
|
30
|
-
type: "IfStatement",
|
|
31
|
-
alternate: node,
|
|
32
|
-
};
|
|
33
|
-
const text = (0, branch_annotation_helpers_1.gatherBranchCommentText)(sourceCode, node, parent);
|
|
34
|
-
expect(text).toContain("@story docs/stories/026.0-DEV-ELSE-IF-ANNOTATION-POSITION.story.md");
|
|
35
|
-
expect(text).toContain("@req REQ-DUAL-POSITION-DETECTION-ELSE-IF");
|
|
36
|
-
});
|
|
37
|
-
it("[REQ-FALLBACK-LOGIC-ELSE-IF] falls back to annotations between condition and body when before-else-if comments lack annotations", () => {
|
|
38
|
-
const lines = [
|
|
39
|
-
"if (a) {",
|
|
40
|
-
" doA();",
|
|
41
|
-
"} else if (b && c) {",
|
|
42
|
-
" // @story docs/stories/026.0-DEV-ELSE-IF-ANNOTATION-POSITION.story.md",
|
|
43
|
-
" // @req REQ-FALLBACK-LOGIC-ELSE-IF",
|
|
44
|
-
" doB();",
|
|
45
|
-
"}",
|
|
46
|
-
];
|
|
47
|
-
const sourceCode = createMockSourceCode({
|
|
48
|
-
commentsBefore: [{ value: "// some unrelated comment" }],
|
|
49
|
-
lines,
|
|
50
|
-
});
|
|
51
|
-
const node = {
|
|
52
|
-
type: "IfStatement",
|
|
53
|
-
loc: { start: { line: 3 } },
|
|
54
|
-
test: { loc: { end: { line: 3 } } },
|
|
55
|
-
consequent: {
|
|
56
|
-
type: "BlockStatement",
|
|
57
|
-
loc: { start: { line: 6 } },
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
const parent = {
|
|
61
|
-
type: "IfStatement",
|
|
62
|
-
alternate: node,
|
|
63
|
-
};
|
|
64
|
-
const text = (0, branch_annotation_helpers_1.gatherBranchCommentText)(sourceCode, node, parent);
|
|
65
|
-
expect(text).toContain("@story docs/stories/026.0-DEV-ELSE-IF-ANNOTATION-POSITION.story.md");
|
|
66
|
-
expect(text).toContain("@req REQ-FALLBACK-LOGIC-ELSE-IF");
|
|
67
|
-
});
|
|
68
|
-
it("[REQ-POSITION-PRIORITY-ELSE-IF] prefers before-else-if annotations when both positions are present", () => {
|
|
69
|
-
const lines = [
|
|
70
|
-
"if (a) {",
|
|
71
|
-
" doA();",
|
|
72
|
-
"} else if (b) {",
|
|
73
|
-
" // @story docs/stories/026.0-DEV-ELSE-IF-ANNOTATION-POSITION.story.md",
|
|
74
|
-
" // @req REQ-POSITION-PRIORITY-ELSE-IF-BETWEEN",
|
|
75
|
-
" doB();",
|
|
76
|
-
"}",
|
|
77
|
-
];
|
|
78
|
-
const sourceCode = createMockSourceCode({
|
|
79
|
-
commentsBefore: [
|
|
80
|
-
{
|
|
81
|
-
value: "@story docs/stories/026.0-DEV-ELSE-IF-ANNOTATION-POSITION.story.md",
|
|
82
|
-
},
|
|
83
|
-
{ value: "@req REQ-POSITION-PRIORITY-ELSE-IF" },
|
|
84
|
-
],
|
|
85
|
-
lines,
|
|
86
|
-
});
|
|
87
|
-
const node = {
|
|
88
|
-
type: "IfStatement",
|
|
89
|
-
loc: { start: { line: 3 } },
|
|
90
|
-
test: { loc: { end: { line: 3 } } },
|
|
91
|
-
consequent: {
|
|
92
|
-
type: "BlockStatement",
|
|
93
|
-
loc: { start: { line: 6 } },
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
const parent = {
|
|
97
|
-
type: "IfStatement",
|
|
98
|
-
alternate: node,
|
|
99
|
-
};
|
|
100
|
-
const text = (0, branch_annotation_helpers_1.gatherBranchCommentText)(sourceCode, node, parent);
|
|
101
|
-
// The helper should use the before-else-if annotations and not need to
|
|
102
|
-
// fall back to between-condition-and-body comments.
|
|
103
|
-
expect(text).toContain("@story docs/stories/026.0-DEV-ELSE-IF-ANNOTATION-POSITION.story.md");
|
|
104
|
-
expect(text).toContain("@req REQ-POSITION-PRIORITY-ELSE-IF");
|
|
105
|
-
expect(text).not.toContain("REQ-POSITION-PRIORITY-ELSE-IF-BETWEEN");
|
|
106
|
-
});
|
|
107
|
-
it("[REQ-SINGLE-LINE-ELSE-IF-SUPPORT] detects annotations on single-line else-if without braces when placed before the else-if keyword", () => {
|
|
108
|
-
const lines = [
|
|
109
|
-
"let suggestion;",
|
|
110
|
-
"// @story docs/stories/026.0-DEV-ELSE-IF-ANNOTATION-POSITION.story.md",
|
|
111
|
-
"// @req REQ-SINGLE-LINE-ELSE-IF-SUPPORT",
|
|
112
|
-
"if (arg === \"--json\") suggestion = \"--format=json\";",
|
|
113
|
-
"// @story docs/stories/026.0-DEV-ELSE-IF-ANNOTATION-POSITION.story.md",
|
|
114
|
-
"// @req REQ-SINGLE-LINE-ELSE-IF-SUPPORT",
|
|
115
|
-
"else if (arg.startsWith(\"--format\")) suggestion = \"--format\";",
|
|
116
|
-
];
|
|
117
|
-
const sourceCode = createMockSourceCode({
|
|
118
|
-
commentsBefore: [
|
|
119
|
-
{
|
|
120
|
-
value: "@story docs/stories/026.0-DEV-ELSE-IF-ANNOTATION-POSITION.story.md",
|
|
121
|
-
},
|
|
122
|
-
{ value: "@req REQ-SINGLE-LINE-ELSE-IF-SUPPORT" },
|
|
123
|
-
],
|
|
124
|
-
lines,
|
|
125
|
-
});
|
|
126
|
-
const node = {
|
|
127
|
-
type: "IfStatement",
|
|
128
|
-
loc: { start: { line: 7 } },
|
|
129
|
-
test: { loc: { end: { line: 7 } } },
|
|
130
|
-
consequent: {
|
|
131
|
-
// single-line consequent without BlockStatement braces in the real-world source;
|
|
132
|
-
// for this helper-level test we only care that loc values exist and are consistent.
|
|
133
|
-
type: "ExpressionStatement",
|
|
134
|
-
loc: { start: { line: 7 } },
|
|
135
|
-
},
|
|
136
|
-
};
|
|
137
|
-
const parent = {
|
|
138
|
-
type: "IfStatement",
|
|
139
|
-
alternate: node,
|
|
140
|
-
};
|
|
141
|
-
const text = (0, branch_annotation_helpers_1.gatherBranchCommentText)(sourceCode, node, parent);
|
|
142
|
-
expect(text).toContain("@story docs/stories/026.0-DEV-ELSE-IF-ANNOTATION-POSITION.story.md");
|
|
143
|
-
expect(text).toContain("@req REQ-SINGLE-LINE-ELSE-IF-SUPPORT");
|
|
144
|
-
});
|
|
145
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,462 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
/* eslint-disable traceability/valid-annotation-format */
|
|
4
|
-
/**
|
|
5
|
-
* Unit tests for branch annotation helpers
|
|
6
|
-
* Tests for: docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md
|
|
7
|
-
* @story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md
|
|
8
|
-
* @req REQ-CONFIGURABLE-SCOPE - Allow configuration of branch types for annotation enforcement
|
|
9
|
-
* @supports docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md REQ-CONFIGURABLE-SCOPE
|
|
10
|
-
*/
|
|
11
|
-
const branch_annotation_helpers_1 = require("../../src/utils/branch-annotation-helpers");
|
|
12
|
-
describe("validateBranchTypes helper (Story 004.0-DEV-BRANCH-ANNOTATIONS)", () => {
|
|
13
|
-
let context;
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
context = { options: [], report: jest.fn() };
|
|
16
|
-
});
|
|
17
|
-
it("should return default branch types when no options provided", () => {
|
|
18
|
-
const result = (0, branch_annotation_helpers_1.validateBranchTypes)(context);
|
|
19
|
-
expect(Array.isArray(result)).toBe(true);
|
|
20
|
-
expect(result).toEqual(branch_annotation_helpers_1.DEFAULT_BRANCH_TYPES);
|
|
21
|
-
});
|
|
22
|
-
it("should return custom branch types when valid options provided", () => {
|
|
23
|
-
context.options = [{ branchTypes: ["IfStatement", "ForStatement"] }];
|
|
24
|
-
const result = (0, branch_annotation_helpers_1.validateBranchTypes)(context);
|
|
25
|
-
expect(Array.isArray(result)).toBe(true);
|
|
26
|
-
expect(result).toEqual(["IfStatement", "ForStatement"]);
|
|
27
|
-
});
|
|
28
|
-
it("should return listener when invalid branch types provided and report errors", () => {
|
|
29
|
-
const invalid = ["UnknownType", "Foo"];
|
|
30
|
-
context.options = [{ branchTypes: invalid }];
|
|
31
|
-
// Invoke helper
|
|
32
|
-
const result = (0, branch_annotation_helpers_1.validateBranchTypes)(context);
|
|
33
|
-
// Should return a listener object
|
|
34
|
-
expect(typeof result).toBe("object");
|
|
35
|
-
expect(result).toHaveProperty("Program");
|
|
36
|
-
// Call the Program listener
|
|
37
|
-
const fakeNode = {};
|
|
38
|
-
result.Program(fakeNode);
|
|
39
|
-
// report should be called for each invalid type
|
|
40
|
-
expect(context.report).toHaveBeenCalledTimes(invalid.length);
|
|
41
|
-
invalid.forEach((t) => {
|
|
42
|
-
expect(context.report).toHaveBeenCalledWith(expect.objectContaining({
|
|
43
|
-
node: fakeNode,
|
|
44
|
-
message: expect.stringContaining(`Value "${t}" should be equal to one of the allowed values:`),
|
|
45
|
-
}));
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
it("should gather SwitchCase comment text via gatherBranchCommentText (Story 004.0-DEV-BRANCH-ANNOTATIONS)", () => {
|
|
49
|
-
const sourceCode = {
|
|
50
|
-
lines: [],
|
|
51
|
-
getCommentsBefore: jest.fn().mockReturnValue([
|
|
52
|
-
{ value: "@story first part" },
|
|
53
|
-
{ value: "@req REQ-FIRST" },
|
|
54
|
-
]),
|
|
55
|
-
getText: jest.fn(),
|
|
56
|
-
};
|
|
57
|
-
// SwitchCase-like node with loc.start.line corresponding to "case 1:" line (line 3)
|
|
58
|
-
const switchCaseNode = {
|
|
59
|
-
type: "SwitchCase",
|
|
60
|
-
loc: {
|
|
61
|
-
start: { line: 3, column: 0 },
|
|
62
|
-
end: { line: 3, column: 7 },
|
|
63
|
-
},
|
|
64
|
-
};
|
|
65
|
-
const text = (0, branch_annotation_helpers_1.gatherBranchCommentText)(sourceCode, switchCaseNode);
|
|
66
|
-
expect(text).toBe("@story first part @req REQ-FIRST");
|
|
67
|
-
});
|
|
68
|
-
it("should gather comment text for CatchClause and loop nodes via gatherBranchCommentText (Story 004.0-DEV-BRANCH-ANNOTATIONS)", () => {
|
|
69
|
-
// CatchClause: comments come from getCommentsBefore when beforeText already contains @story
|
|
70
|
-
const catchComments = [
|
|
71
|
-
{ type: "Line", value: "@story catch branch story" },
|
|
72
|
-
{ type: "Line", value: "additional info" },
|
|
73
|
-
];
|
|
74
|
-
const sourceCodeCatch = {
|
|
75
|
-
getCommentsBefore: jest.fn().mockReturnValue(catchComments),
|
|
76
|
-
getText: jest.fn().mockReturnValue("@story existing beforeText"),
|
|
77
|
-
lines: [],
|
|
78
|
-
};
|
|
79
|
-
const catchNode = {
|
|
80
|
-
type: "CatchClause",
|
|
81
|
-
loc: {
|
|
82
|
-
start: { line: 10, column: 0 },
|
|
83
|
-
end: { line: 12, column: 1 },
|
|
84
|
-
},
|
|
85
|
-
};
|
|
86
|
-
const catchText = (0, branch_annotation_helpers_1.gatherBranchCommentText)(sourceCodeCatch, catchNode);
|
|
87
|
-
expect(sourceCodeCatch.getCommentsBefore).toHaveBeenCalledWith(catchNode);
|
|
88
|
-
expect(catchText).toContain("@story catch branch story");
|
|
89
|
-
expect(catchText).toContain("additional info");
|
|
90
|
-
// Loop node: ForStatement currently uses beforeComments.map(extractCommentValue).join(" ")
|
|
91
|
-
const loopComments = [
|
|
92
|
-
{ type: "Line", value: "@story loop branch story" },
|
|
93
|
-
{ type: "Block", value: "loop details" },
|
|
94
|
-
];
|
|
95
|
-
const sourceCodeLoop = {
|
|
96
|
-
getCommentsBefore: jest.fn().mockReturnValue(loopComments),
|
|
97
|
-
getText: jest.fn().mockReturnValue("@story loop beforeText"),
|
|
98
|
-
lines: [],
|
|
99
|
-
};
|
|
100
|
-
const forNode = {
|
|
101
|
-
type: "ForStatement",
|
|
102
|
-
loc: {
|
|
103
|
-
start: { line: 20, column: 0 },
|
|
104
|
-
end: { line: 25, column: 1 },
|
|
105
|
-
},
|
|
106
|
-
};
|
|
107
|
-
const loopText = (0, branch_annotation_helpers_1.gatherBranchCommentText)(sourceCodeLoop, forNode);
|
|
108
|
-
expect(sourceCodeLoop.getCommentsBefore).toHaveBeenCalledWith(forNode);
|
|
109
|
-
expect(loopText).toBe("@story loop branch story loop details");
|
|
110
|
-
});
|
|
111
|
-
it("[REQ-INSIDE-BRACE-PLACEMENT][REQ-PLACEMENT-CONFIG] uses inside-loop comments when annotationPlacement is 'inside' and ignores before-loop annotations", () => {
|
|
112
|
-
const sourceCode = {
|
|
113
|
-
lines: [
|
|
114
|
-
"// @story before-loop should be ignored in inside mode",
|
|
115
|
-
"for (const item of items) {",
|
|
116
|
-
" // @story docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md",
|
|
117
|
-
" // @req REQ-LOOP-INSIDE",
|
|
118
|
-
" process(item);",
|
|
119
|
-
"}",
|
|
120
|
-
],
|
|
121
|
-
getCommentsBefore: jest
|
|
122
|
-
.fn()
|
|
123
|
-
.mockReturnValue([
|
|
124
|
-
{ value: "@story before-loop should be ignored in inside mode" },
|
|
125
|
-
]),
|
|
126
|
-
};
|
|
127
|
-
const loopNode = {
|
|
128
|
-
type: "ForOfStatement",
|
|
129
|
-
loc: {
|
|
130
|
-
start: { line: 2, column: 0 },
|
|
131
|
-
end: { line: 5, column: 1 },
|
|
132
|
-
},
|
|
133
|
-
body: {
|
|
134
|
-
type: "BlockStatement",
|
|
135
|
-
loc: {
|
|
136
|
-
start: { line: 2, column: 27 },
|
|
137
|
-
end: { line: 5, column: 1 },
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
};
|
|
141
|
-
const parent = {
|
|
142
|
-
type: "BlockStatement",
|
|
143
|
-
body: [loopNode],
|
|
144
|
-
};
|
|
145
|
-
const insideText = (0, branch_annotation_helpers_1.gatherBranchCommentText)(sourceCode, loopNode, parent, "inside");
|
|
146
|
-
expect(insideText).toContain("@story docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md");
|
|
147
|
-
expect(insideText).toContain("@req REQ-LOOP-INSIDE");
|
|
148
|
-
expect(insideText).not.toContain("before-loop should be ignored");
|
|
149
|
-
});
|
|
150
|
-
it("[REQ-INSIDE-BRACE-PLACEMENT][REQ-PLACEMENT-CONFIG] uses inside-catch comments when annotationPlacement is 'inside' and ignores before-catch annotations", () => {
|
|
151
|
-
const sourceCode = {
|
|
152
|
-
lines: [
|
|
153
|
-
"// @story before-catch should be ignored in inside mode",
|
|
154
|
-
"try {",
|
|
155
|
-
" doSomething();",
|
|
156
|
-
"}",
|
|
157
|
-
"catch (error) {",
|
|
158
|
-
" // @story docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md",
|
|
159
|
-
" // @req REQ-CATCH-INSIDE",
|
|
160
|
-
" handleError(error);",
|
|
161
|
-
"}",
|
|
162
|
-
],
|
|
163
|
-
getCommentsBefore: jest
|
|
164
|
-
.fn()
|
|
165
|
-
.mockReturnValue([
|
|
166
|
-
{ value: "@story before-catch should be ignored in inside mode" },
|
|
167
|
-
]),
|
|
168
|
-
};
|
|
169
|
-
const catchNode = {
|
|
170
|
-
type: "CatchClause",
|
|
171
|
-
loc: {
|
|
172
|
-
start: { line: 5, column: 0 },
|
|
173
|
-
end: { line: 8, column: 1 },
|
|
174
|
-
},
|
|
175
|
-
body: {
|
|
176
|
-
type: "BlockStatement",
|
|
177
|
-
loc: {
|
|
178
|
-
start: { line: 5, column: 14 },
|
|
179
|
-
end: { line: 8, column: 1 },
|
|
180
|
-
},
|
|
181
|
-
},
|
|
182
|
-
};
|
|
183
|
-
const parent = {
|
|
184
|
-
type: "TryStatement",
|
|
185
|
-
handler: catchNode,
|
|
186
|
-
};
|
|
187
|
-
const insideText = (0, branch_annotation_helpers_1.gatherBranchCommentText)(sourceCode, catchNode, parent, "inside");
|
|
188
|
-
expect(insideText).toContain("@story docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md");
|
|
189
|
-
expect(insideText).toContain("@req REQ-CATCH-INSIDE");
|
|
190
|
-
expect(insideText).not.toContain("before-catch should be ignored");
|
|
191
|
-
});
|
|
192
|
-
it("[REQ-INSIDE-BRACE-PLACEMENT][REQ-PLACEMENT-CONFIG] uses inside-switch comments when annotationPlacement is 'inside' and ignores before-case annotations", () => {
|
|
193
|
-
const sourceCode = {
|
|
194
|
-
lines: [
|
|
195
|
-
"// @story before-switch should be ignored in inside mode",
|
|
196
|
-
"switch (value) {",
|
|
197
|
-
" case 'a': {",
|
|
198
|
-
" // @story docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md",
|
|
199
|
-
" // @req REQ-SWITCH-INSIDE",
|
|
200
|
-
" doSomething();",
|
|
201
|
-
" }",
|
|
202
|
-
"}",
|
|
203
|
-
],
|
|
204
|
-
getCommentsBefore: jest
|
|
205
|
-
.fn()
|
|
206
|
-
.mockReturnValue([
|
|
207
|
-
{ value: "@story before-switch should be ignored in inside mode" },
|
|
208
|
-
]),
|
|
209
|
-
};
|
|
210
|
-
const switchCaseNode = {
|
|
211
|
-
type: "SwitchCase",
|
|
212
|
-
loc: {
|
|
213
|
-
start: { line: 3, column: 2 },
|
|
214
|
-
end: { line: 7, column: 4 },
|
|
215
|
-
},
|
|
216
|
-
consequent: [
|
|
217
|
-
{
|
|
218
|
-
type: "BlockStatement",
|
|
219
|
-
loc: {
|
|
220
|
-
start: { line: 3, column: 16 },
|
|
221
|
-
end: { line: 7, column: 4 },
|
|
222
|
-
},
|
|
223
|
-
},
|
|
224
|
-
],
|
|
225
|
-
};
|
|
226
|
-
const parent = {
|
|
227
|
-
type: "SwitchStatement",
|
|
228
|
-
discriminant: { type: "Identifier", name: "value" },
|
|
229
|
-
cases: [switchCaseNode],
|
|
230
|
-
};
|
|
231
|
-
const insideText = (0, branch_annotation_helpers_1.gatherBranchCommentText)(sourceCode, switchCaseNode, parent, "inside");
|
|
232
|
-
expect(insideText).toContain("@story docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md");
|
|
233
|
-
expect(insideText).toContain("@req REQ-SWITCH-INSIDE");
|
|
234
|
-
expect(insideText).not.toContain("before-switch should be ignored");
|
|
235
|
-
});
|
|
236
|
-
});
|
|
237
|
-
/**
|
|
238
|
-
* Tests for annotationPlacement wiring at helper level
|
|
239
|
-
* @story docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md
|
|
240
|
-
* @supports docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md REQ-PLACEMENT-CONFIG
|
|
241
|
-
* @supports docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md REQ-DEFAULT-BACKWARD-COMPAT
|
|
242
|
-
*/
|
|
243
|
-
describe("gatherBranchCommentText annotationPlacement wiring (Story 028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION)", () => {
|
|
244
|
-
it("[REQ-PLACEMENT-CONFIG][REQ-DEFAULT-BACKWARD-COMPAT] honors configured placement for simple if-statements", () => {
|
|
245
|
-
const sourceCode = {
|
|
246
|
-
lines: [
|
|
247
|
-
"function demo() {",
|
|
248
|
-
" if (condition) {",
|
|
249
|
-
" // @story docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md",
|
|
250
|
-
" // @req REQ-INSIDE",
|
|
251
|
-
" doSomething();",
|
|
252
|
-
" }",
|
|
253
|
-
"}",
|
|
254
|
-
],
|
|
255
|
-
getCommentsBefore: jest
|
|
256
|
-
.fn()
|
|
257
|
-
.mockReturnValue([
|
|
258
|
-
{ value: "@story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md" },
|
|
259
|
-
{ value: "@req REQ-BEFORE" },
|
|
260
|
-
]),
|
|
261
|
-
};
|
|
262
|
-
const ifNode = {
|
|
263
|
-
type: "IfStatement",
|
|
264
|
-
loc: {
|
|
265
|
-
start: { line: 2, column: 2 },
|
|
266
|
-
end: { line: 5, column: 3 },
|
|
267
|
-
},
|
|
268
|
-
consequent: {
|
|
269
|
-
type: "BlockStatement",
|
|
270
|
-
loc: {
|
|
271
|
-
start: { line: 2, column: 18 },
|
|
272
|
-
end: { line: 5, column: 3 },
|
|
273
|
-
},
|
|
274
|
-
},
|
|
275
|
-
};
|
|
276
|
-
const parent = {
|
|
277
|
-
type: "BlockStatement",
|
|
278
|
-
body: [ifNode],
|
|
279
|
-
};
|
|
280
|
-
const beforeText = (0, branch_annotation_helpers_1.gatherBranchCommentText)(sourceCode, ifNode, parent, "before");
|
|
281
|
-
expect(beforeText).toContain("@story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md");
|
|
282
|
-
expect(beforeText).toContain("@req REQ-BEFORE");
|
|
283
|
-
const insideText = (0, branch_annotation_helpers_1.gatherBranchCommentText)(sourceCode, ifNode, parent, "inside");
|
|
284
|
-
expect(insideText).toContain("@story docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md");
|
|
285
|
-
expect(insideText).toContain("@req REQ-INSIDE");
|
|
286
|
-
expect(insideText).not.toContain("@req REQ-BEFORE");
|
|
287
|
-
});
|
|
288
|
-
it("[REQ-PLACEMENT-CONFIG][REQ-DEFAULT-BACKWARD-COMPAT] honors Story 028.0 inside-placement semantics for else-if branches while preserving Story 026.0 before-else behavior", () => {
|
|
289
|
-
const sourceCode = {
|
|
290
|
-
lines: [
|
|
291
|
-
"function demoElseIf(x) {", // 1
|
|
292
|
-
" if (x === 1) {", // 2
|
|
293
|
-
" // @story inside-if", // 3
|
|
294
|
-
" doOne();", // 4
|
|
295
|
-
" }", // 5
|
|
296
|
-
" // @story docs/stories/026.0-DEV-BRANCH-ANNOTATIONS-ELSE-BRANCHES.story.md", // 6 (before else-if)
|
|
297
|
-
" // @req REQ-BEFORE-ELSE", // 7
|
|
298
|
-
" else if (x === 2) {", // 8
|
|
299
|
-
" // @story docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md", // 9 (inside else-if)
|
|
300
|
-
" // @req REQ-ELSE-IF-INSIDE", // 10
|
|
301
|
-
" doTwo();", // 11
|
|
302
|
-
" }", // 12
|
|
303
|
-
"}", // 13
|
|
304
|
-
],
|
|
305
|
-
getCommentsBefore: jest.fn().mockImplementation((node) => {
|
|
306
|
-
// Simulate ESLint getCommentsBefore only returning comments that are truly
|
|
307
|
-
// "before" the node they are querying.
|
|
308
|
-
// Our chain has:
|
|
309
|
-
// - before-if comments not used in this test
|
|
310
|
-
// - line 6-7 as before-else-if comments
|
|
311
|
-
if (node && node.loc && node.loc.start && node.loc.start.line === 2) {
|
|
312
|
-
// before the initial if (not used in assertions here)
|
|
313
|
-
return [
|
|
314
|
-
{ value: "@story BEFORE-IF" },
|
|
315
|
-
{ value: "@req REQ-BEFORE-IF" },
|
|
316
|
-
];
|
|
317
|
-
}
|
|
318
|
-
if (node && node.loc && node.loc.start && node.loc.start.line === 8) {
|
|
319
|
-
// before the else-if branch (Story 026.0 semantics)
|
|
320
|
-
return [
|
|
321
|
-
{
|
|
322
|
-
value: "@story docs/stories/026.0-DEV-BRANCH-ANNOTATIONS-ELSE-BRANCHES.story.md",
|
|
323
|
-
},
|
|
324
|
-
{ value: "@req REQ-BEFORE-ELSE" },
|
|
325
|
-
];
|
|
326
|
-
}
|
|
327
|
-
return [];
|
|
328
|
-
}),
|
|
329
|
-
};
|
|
330
|
-
const elseIfNode = {
|
|
331
|
-
type: "IfStatement",
|
|
332
|
-
loc: {
|
|
333
|
-
start: { line: 8, column: 2 },
|
|
334
|
-
end: { line: 12, column: 3 },
|
|
335
|
-
},
|
|
336
|
-
consequent: {
|
|
337
|
-
type: "BlockStatement",
|
|
338
|
-
loc: {
|
|
339
|
-
start: { line: 8, column: 22 },
|
|
340
|
-
end: { line: 12, column: 3 },
|
|
341
|
-
},
|
|
342
|
-
},
|
|
343
|
-
};
|
|
344
|
-
const parent = {
|
|
345
|
-
type: "IfStatement",
|
|
346
|
-
alternate: elseIfNode,
|
|
347
|
-
};
|
|
348
|
-
const beforeText = (0, branch_annotation_helpers_1.gatherBranchCommentText)(sourceCode, elseIfNode, parent, "before");
|
|
349
|
-
expect(beforeText).toContain("@story docs/stories/026.0-DEV-BRANCH-ANNOTATIONS-ELSE-BRANCHES.story.md");
|
|
350
|
-
expect(beforeText).toContain("@req REQ-BEFORE-ELSE");
|
|
351
|
-
const insideText = (0, branch_annotation_helpers_1.gatherBranchCommentText)(sourceCode, elseIfNode, parent, "inside");
|
|
352
|
-
expect(insideText).toBe("");
|
|
353
|
-
expect(insideText).not.toContain("REQ-BEFORE-ELSE");
|
|
354
|
-
expect(insideText).not.toContain("docs/stories/026.0-DEV-BRANCH-ANNOTATIONS-ELSE-BRANCHES.story.md");
|
|
355
|
-
});
|
|
356
|
-
it("[REQ-PLACEMENT-CONFIG][REQ-DEFAULT-BACKWARD-COMPAT] honors configured placement for TryStatement branches in try/finally patterns", () => {
|
|
357
|
-
const sourceCode = {
|
|
358
|
-
lines: [
|
|
359
|
-
"function demoTry() {", // 1
|
|
360
|
-
" // @story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md", // 2 (before try)
|
|
361
|
-
" // @req REQ-BEFORE-TRY", // 3
|
|
362
|
-
" try {", // 4
|
|
363
|
-
" // @story docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md", // 5 (inside try)
|
|
364
|
-
" // @req REQ-TRY-INSIDE", // 6
|
|
365
|
-
" doWork();", // 7
|
|
366
|
-
" } finally {", // 8
|
|
367
|
-
" cleanup();", // 9
|
|
368
|
-
" }", // 10
|
|
369
|
-
"}", // 11
|
|
370
|
-
],
|
|
371
|
-
getCommentsBefore: jest.fn().mockImplementation((node) => {
|
|
372
|
-
if (node && node.loc && node.loc.start && node.loc.start.line === 4) {
|
|
373
|
-
return [
|
|
374
|
-
{
|
|
375
|
-
value: "@story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md",
|
|
376
|
-
},
|
|
377
|
-
{ value: "@req REQ-BEFORE-TRY" },
|
|
378
|
-
];
|
|
379
|
-
}
|
|
380
|
-
return [];
|
|
381
|
-
}),
|
|
382
|
-
};
|
|
383
|
-
const tryNode = {
|
|
384
|
-
type: "TryStatement",
|
|
385
|
-
loc: {
|
|
386
|
-
start: { line: 4, column: 2 },
|
|
387
|
-
end: { line: 9, column: 3 },
|
|
388
|
-
},
|
|
389
|
-
block: {
|
|
390
|
-
type: "BlockStatement",
|
|
391
|
-
loc: {
|
|
392
|
-
start: { line: 4, column: 8 },
|
|
393
|
-
end: { line: 7, column: 3 },
|
|
394
|
-
},
|
|
395
|
-
},
|
|
396
|
-
handler: null,
|
|
397
|
-
finalizer: {
|
|
398
|
-
type: "BlockStatement",
|
|
399
|
-
loc: {
|
|
400
|
-
start: { line: 8, column: 12 },
|
|
401
|
-
end: { line: 9, column: 3 },
|
|
402
|
-
},
|
|
403
|
-
},
|
|
404
|
-
};
|
|
405
|
-
const parent = {
|
|
406
|
-
type: "BlockStatement",
|
|
407
|
-
body: [tryNode],
|
|
408
|
-
};
|
|
409
|
-
const beforeText = (0, branch_annotation_helpers_1.gatherBranchCommentText)(sourceCode, tryNode, parent, "before");
|
|
410
|
-
expect(beforeText).toContain("@story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md");
|
|
411
|
-
expect(beforeText).toContain("@req REQ-BEFORE-TRY");
|
|
412
|
-
expect(beforeText).not.toContain("REQ-TRY-INSIDE");
|
|
413
|
-
const insideText = (0, branch_annotation_helpers_1.gatherBranchCommentText)(sourceCode, tryNode, parent, "inside");
|
|
414
|
-
expect(insideText).toContain("@story docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md");
|
|
415
|
-
expect(insideText).toContain("@req REQ-TRY-INSIDE");
|
|
416
|
-
expect(insideText).not.toContain("REQ-BEFORE-TRY");
|
|
417
|
-
});
|
|
418
|
-
it("[REQ-PLACEMENT-CONFIG][REQ-DEFAULT-BACKWARD-COMPAT] honors before-case annotations for SwitchCase in default placement mode", () => {
|
|
419
|
-
const sourceCode = {
|
|
420
|
-
lines: [
|
|
421
|
-
"// @story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md",
|
|
422
|
-
"// @req REQ-SWITCH-BEFORE",
|
|
423
|
-
"switch (value) {",
|
|
424
|
-
" case 'a':",
|
|
425
|
-
" doSomething();",
|
|
426
|
-
"}",
|
|
427
|
-
],
|
|
428
|
-
getCommentsBefore: jest
|
|
429
|
-
.fn()
|
|
430
|
-
.mockReturnValue([
|
|
431
|
-
{
|
|
432
|
-
value: "@story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md",
|
|
433
|
-
},
|
|
434
|
-
{ value: "@req REQ-SWITCH-BEFORE" },
|
|
435
|
-
]),
|
|
436
|
-
};
|
|
437
|
-
const switchCaseNode = {
|
|
438
|
-
type: "SwitchCase",
|
|
439
|
-
loc: {
|
|
440
|
-
start: { line: 4, column: 2 },
|
|
441
|
-
end: { line: 5, column: 18 },
|
|
442
|
-
},
|
|
443
|
-
consequent: [
|
|
444
|
-
{
|
|
445
|
-
type: "ExpressionStatement",
|
|
446
|
-
loc: {
|
|
447
|
-
start: { line: 5, column: 4 },
|
|
448
|
-
end: { line: 5, column: 18 },
|
|
449
|
-
},
|
|
450
|
-
},
|
|
451
|
-
],
|
|
452
|
-
};
|
|
453
|
-
const parent = {
|
|
454
|
-
type: "SwitchStatement",
|
|
455
|
-
discriminant: { type: "Identifier", name: "value" },
|
|
456
|
-
cases: [switchCaseNode],
|
|
457
|
-
};
|
|
458
|
-
const beforeText = (0, branch_annotation_helpers_1.gatherBranchCommentText)(sourceCode, switchCaseNode, parent, "before");
|
|
459
|
-
expect(beforeText).toContain("@story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md");
|
|
460
|
-
expect(beforeText).toContain("@req REQ-SWITCH-BEFORE");
|
|
461
|
-
});
|
|
462
|
-
});
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared filesystem mocking utilities for rule tests.
|
|
3
|
-
*
|
|
4
|
-
* @story docs/stories/006.0-DEV-FILE-VALIDATION.story.md
|
|
5
|
-
* @req REQ-TEST-UTILS-FS - Provide helpers to reduce duplication in fs-related tests
|
|
6
|
-
*/
|
|
7
|
-
export declare function mockFsForExistingFile(fs: typeof import("fs"), filePath: string): void;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mockFsForExistingFile = mockFsForExistingFile;
|
|
4
|
-
/**
|
|
5
|
-
* Shared filesystem mocking utilities for rule tests.
|
|
6
|
-
*
|
|
7
|
-
* @story docs/stories/006.0-DEV-FILE-VALIDATION.story.md
|
|
8
|
-
* @req REQ-TEST-UTILS-FS - Provide helpers to reduce duplication in fs-related tests
|
|
9
|
-
*/
|
|
10
|
-
function mockFsForExistingFile(fs, filePath) {
|
|
11
|
-
jest.spyOn(fs, "existsSync").mockImplementation((...args) => {
|
|
12
|
-
const p = args[0];
|
|
13
|
-
return p === filePath;
|
|
14
|
-
});
|
|
15
|
-
jest.spyOn(fs, "statSync").mockImplementation((...args) => {
|
|
16
|
-
const p = args[0];
|
|
17
|
-
if (p === filePath) {
|
|
18
|
-
return {
|
|
19
|
-
isFile: () => true,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
const err = new Error("ENOENT");
|
|
23
|
-
err.code = "ENOENT";
|
|
24
|
-
throw err;
|
|
25
|
-
});
|
|
26
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared IO helper tests for require-story-io behavior.
|
|
3
|
-
*
|
|
4
|
-
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
5
|
-
* @req REQ-TEST-UTILS-IO - Provide reusable helpers for IO-related edge case tests
|
|
6
|
-
*/
|
|
7
|
-
export declare function runFallbackTextBeforeHasStoryDetectsStoryTest(storyAnnotationOrFallbackFn?: string | ((_source: any, _node: any) => boolean), maybeFallbackFn?: (_source: any, _node: any) => boolean): void;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runFallbackTextBeforeHasStoryDetectsStoryTest = runFallbackTextBeforeHasStoryDetectsStoryTest;
|
|
4
|
-
/**
|
|
5
|
-
* Shared IO helper tests for require-story-io behavior.
|
|
6
|
-
*
|
|
7
|
-
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
8
|
-
* @req REQ-TEST-UTILS-IO - Provide reusable helpers for IO-related edge case tests
|
|
9
|
-
*/
|
|
10
|
-
function runFallbackTextBeforeHasStoryDetectsStoryTest(storyAnnotationOrFallbackFn = "@story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md", maybeFallbackFn) {
|
|
11
|
-
const isFirstArgFn = typeof storyAnnotationOrFallbackFn === "function";
|
|
12
|
-
const storyAnnotation = isFirstArgFn
|
|
13
|
-
? "@story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md"
|
|
14
|
-
: storyAnnotationOrFallbackFn;
|
|
15
|
-
const fallbackFn = isFirstArgFn
|
|
16
|
-
? storyAnnotationOrFallbackFn
|
|
17
|
-
: maybeFallbackFn;
|
|
18
|
-
const pre = `/* ${storyAnnotation} */\n`;
|
|
19
|
-
const rest = "function y() {}";
|
|
20
|
-
const full = pre + rest;
|
|
21
|
-
const fakeSource = { getText: () => full };
|
|
22
|
-
const node = { range: [full.indexOf("function"), full.length] };
|
|
23
|
-
expect(fallbackFn(fakeSource, node)).toBe(true);
|
|
24
|
-
}
|