eslint-plugin-traceability 1.21.0 → 1.22.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.
- package/CHANGELOG.md +7 -2
- package/README.md +6 -6
- package/lib/src/maintenance/batch.js +0 -1
- package/lib/src/maintenance/cli.js +8 -10
- package/lib/src/maintenance/commands.d.ts +2 -2
- package/lib/src/maintenance/commands.js +2 -2
- package/lib/src/maintenance/detect.js +7 -7
- package/lib/src/maintenance/report.js +2 -2
- package/lib/src/maintenance/storyParser.d.ts +16 -0
- package/lib/src/maintenance/storyParser.js +167 -0
- package/lib/src/rules/helpers/pattern-validators.d.ts +42 -0
- package/lib/src/rules/helpers/pattern-validators.js +65 -0
- package/lib/src/rules/helpers/prefer-implements-inline.d.ts +16 -0
- package/lib/src/rules/helpers/prefer-implements-inline.js +146 -0
- package/lib/src/rules/helpers/require-story-comment-detection.d.ts +47 -0
- package/lib/src/rules/helpers/require-story-comment-detection.js +141 -0
- package/lib/src/rules/helpers/require-story-core.d.ts +6 -6
- package/lib/src/rules/helpers/require-story-core.js +10 -10
- package/lib/src/rules/helpers/require-story-helpers.d.ts +5 -63
- package/lib/src/rules/helpers/require-story-helpers.js +29 -337
- package/lib/src/rules/helpers/require-story-io.js +1 -0
- package/lib/src/rules/helpers/require-story-name-extraction.d.ts +35 -0
- package/lib/src/rules/helpers/require-story-name-extraction.js +107 -0
- package/lib/src/rules/helpers/require-story-node-utils.d.ts +43 -0
- package/lib/src/rules/helpers/require-story-node-utils.js +115 -0
- package/lib/src/rules/helpers/require-test-traceability-helpers.js +1 -0
- package/lib/src/rules/helpers/valid-annotation-format-internal.d.ts +2 -2
- package/lib/src/rules/helpers/valid-annotation-format-internal.js +13 -5
- package/lib/src/rules/helpers/valid-annotation-format-validators.d.ts +14 -14
- package/lib/src/rules/helpers/valid-annotation-format-validators.js +31 -22
- package/lib/src/rules/helpers/valid-annotation-options.d.ts +0 -10
- package/lib/src/rules/helpers/valid-annotation-options.js +22 -92
- package/lib/src/rules/helpers/valid-annotation-utils.js +1 -0
- package/lib/src/rules/helpers/valid-req-reference-helpers.js +1 -1
- package/lib/src/rules/no-redundant-annotation.js +4 -238
- package/lib/src/rules/prefer-implements-annotation.d.ts +12 -0
- package/lib/src/rules/prefer-implements-annotation.js +9 -164
- package/lib/src/rules/require-traceability.d.ts +8 -0
- package/lib/src/rules/require-traceability.js +8 -0
- package/lib/src/rules/valid-annotation-format.js +14 -10
- package/lib/src/utils/annotation-checker.d.ts +3 -2
- package/lib/src/utils/annotation-checker.js +4 -2
- package/lib/src/utils/branch-annotation-catch-helpers.d.ts +22 -0
- package/lib/src/utils/branch-annotation-catch-helpers.js +70 -0
- package/lib/src/utils/branch-annotation-helpers.js +11 -187
- package/lib/src/utils/branch-annotation-if-helpers.d.ts +1 -0
- package/lib/src/utils/branch-annotation-if-helpers.js +59 -0
- package/lib/src/utils/branch-annotation-indent-helpers.d.ts +1 -1
- package/lib/src/utils/branch-annotation-switch-helpers.d.ts +8 -2
- package/lib/src/utils/branch-annotation-switch-helpers.js +10 -4
- package/lib/src/utils/branch-validation.d.ts +9 -0
- package/lib/src/utils/branch-validation.js +58 -0
- package/lib/src/utils/comment-text-helpers.d.ts +31 -0
- package/lib/src/utils/comment-text-helpers.js +54 -0
- package/lib/src/utils/redundancy-detector.d.ts +85 -0
- package/lib/src/utils/redundancy-detector.js +235 -0
- package/lib/src/utils/reqAnnotationDetection.js +1 -0
- package/lib/tests/config/eslint-config-validation.test.js +1 -0
- package/lib/tests/config/flat-config-presets-integration.test.js +1 -0
- package/lib/tests/config/require-story-annotation-config.test.js +1 -0
- package/lib/tests/fixtures/stale/example.js +1 -0
- package/lib/tests/fixtures/update/example.js +1 -0
- package/lib/tests/integration/annotation-placement-inside-prettier.integration.test.js +1 -0
- package/lib/tests/integration/catch-annotation-prettier.integration.test.js +1 -0
- package/lib/tests/integration/else-if-annotation-prettier.integration.test.js +1 -0
- package/lib/tests/integration/prettier-test-helpers.js +1 -0
- package/lib/tests/integration/require-traceability-test-callbacks.integration.test.js +1 -0
- package/lib/tests/maintenance/detect-isolated.test.js +1 -0
- package/lib/tests/maintenance/storyParser.test.d.ts +8 -0
- package/lib/tests/maintenance/storyParser.test.js +505 -0
- package/lib/tests/perf/maintenance-large-workspace.test.js +1 -0
- package/lib/tests/perf/valid-annotation-format-large-file.test.js +1 -0
- package/lib/tests/plugin-setup.test.js +1 -0
- package/lib/tests/rules/error-reporting.test.js +1 -0
- package/lib/tests/rules/no-redundant-annotation.test.js +1 -0
- package/lib/tests/rules/require-story-helpers.test.js +3 -2
- package/lib/tests/rules/require-test-traceability.test.js +1 -0
- package/lib/tests/rules/valid-req-reference.test.js +2 -0
- package/lib/tests/utils/branch-annotation-catch-insert-position.test.js +1 -0
- package/lib/tests/utils/branch-annotation-else-if-insert-position.test.js +1 -0
- package/lib/tests/utils/branch-annotation-helpers.test.js +1 -0
- package/package.json +18 -10
- package/user-docs/api-reference.md +2 -2
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getInsideCatchCommentText = getInsideCatchCommentText;
|
|
4
|
+
exports.getInsideTryBlockCommentText = getInsideTryBlockCommentText;
|
|
5
|
+
const branch_annotation_helpers_1 = require("./branch-annotation-helpers");
|
|
6
|
+
const comment_text_helpers_1 = require("./comment-text-helpers");
|
|
7
|
+
/**
|
|
8
|
+
* Gather comment text from inside a CatchClause body.
|
|
9
|
+
*
|
|
10
|
+
* Uses dual-position detection strategy: first attempts getCommentsInside API,
|
|
11
|
+
* then falls back to line-based scanning if API is unavailable or returns empty.
|
|
12
|
+
*
|
|
13
|
+
* @story docs/stories/025.0-DEV-CATCH-ANNOTATION-POSITION.story.md
|
|
14
|
+
* @req REQ-DUAL-POSITION-DETECTION REQ-FALLBACK-LOGIC
|
|
15
|
+
* @param sourceCode - ESLint source code object providing comment access APIs
|
|
16
|
+
* @param node - CatchClause AST node whose body will be scanned for comments
|
|
17
|
+
* @returns Concatenated comment text from inside the catch body, or empty string if none found
|
|
18
|
+
*/
|
|
19
|
+
function getInsideCatchCommentText(sourceCode, node) {
|
|
20
|
+
const getCommentsInside = sourceCode.getCommentsInside;
|
|
21
|
+
if (node.body && typeof getCommentsInside === "function") {
|
|
22
|
+
try {
|
|
23
|
+
const insideComments = getCommentsInside(node.body) || [];
|
|
24
|
+
const insideText = insideComments.map(comment_text_helpers_1.extractCommentValue).join(" ");
|
|
25
|
+
if (insideText) {
|
|
26
|
+
return insideText;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// fall through to line-based fallback
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (node.body && node.body.loc && node.body.loc.start && node.body.loc.end) {
|
|
34
|
+
const lines = sourceCode.lines;
|
|
35
|
+
const startIndex = node.body.loc.start.line - 1;
|
|
36
|
+
const endIndex = node.body.loc.end.line - 1;
|
|
37
|
+
const insideText = (0, branch_annotation_helpers_1.scanCommentLinesInRange)(lines, startIndex + 1, endIndex);
|
|
38
|
+
if (insideText) {
|
|
39
|
+
return insideText;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return "";
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Gather comment text from the first contiguous comment lines inside a TryStatement block body.
|
|
46
|
+
* @supports docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md REQ-INSIDE-BRACE-PLACEMENT
|
|
47
|
+
* @param sourceCode - ESLint source code object providing line access
|
|
48
|
+
* @param node - TryStatement AST node whose block will be scanned for comments
|
|
49
|
+
* @returns Concatenated comment text from inside the try block, or empty string if none found
|
|
50
|
+
*/
|
|
51
|
+
function getInsideTryBlockCommentText(sourceCode, node) {
|
|
52
|
+
const block = node && node.block;
|
|
53
|
+
if (!block ||
|
|
54
|
+
block.type !== "BlockStatement" ||
|
|
55
|
+
!block.loc ||
|
|
56
|
+
!block.loc.start ||
|
|
57
|
+
!block.loc.end ||
|
|
58
|
+
typeof block.loc.start.line !== "number" ||
|
|
59
|
+
typeof block.loc.end.line !== "number") {
|
|
60
|
+
return "";
|
|
61
|
+
}
|
|
62
|
+
const lines = sourceCode.lines;
|
|
63
|
+
const startIndex = block.loc.start.line - 1;
|
|
64
|
+
const endIndex = block.loc.end.line - 1;
|
|
65
|
+
const insideText = (0, branch_annotation_helpers_1.scanCommentLinesInRange)(lines, startIndex + 1, endIndex);
|
|
66
|
+
if (insideText) {
|
|
67
|
+
return insideText;
|
|
68
|
+
}
|
|
69
|
+
return "";
|
|
70
|
+
}
|
|
@@ -12,6 +12,9 @@ const branch_annotation_loop_helpers_1 = require("./branch-annotation-loop-helpe
|
|
|
12
12
|
const branch_annotation_if_helpers_1 = require("./branch-annotation-if-helpers");
|
|
13
13
|
const branch_annotation_switch_helpers_1 = require("./branch-annotation-switch-helpers");
|
|
14
14
|
const branch_annotation_story_fix_helpers_1 = require("./branch-annotation-story-fix-helpers");
|
|
15
|
+
const branch_annotation_catch_helpers_1 = require("./branch-annotation-catch-helpers");
|
|
16
|
+
const branch_validation_1 = require("./branch-validation");
|
|
17
|
+
const comment_text_helpers_1 = require("./comment-text-helpers");
|
|
15
18
|
/**
|
|
16
19
|
* Valid branch types for require-branch-annotation rule.
|
|
17
20
|
* @story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md
|
|
@@ -35,96 +38,7 @@ exports.DEFAULT_BRANCH_TYPES = [
|
|
|
35
38
|
* @req REQ-CONFIGURABLE-SCOPE - Allow configuration of branch types for annotation enforcement
|
|
36
39
|
*/
|
|
37
40
|
function validateBranchTypes(context) {
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Conditional branch checking whether branchTypes option was provided.
|
|
41
|
-
* @story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md
|
|
42
|
-
* @req REQ-TRACEABILITY-CONDITIONAL - Trace configuration branch existence check
|
|
43
|
-
*/
|
|
44
|
-
if (Array.isArray(options.branchTypes)) {
|
|
45
|
-
/**
|
|
46
|
-
* Predicate to determine whether a provided branch type is invalid.
|
|
47
|
-
* @story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md
|
|
48
|
-
* @req REQ-TRACEABILITY-FILTER-CALLBACK - Trace filter callback for invalid branch type detection
|
|
49
|
-
*/
|
|
50
|
-
function isInvalidType(t) {
|
|
51
|
-
return !exports.DEFAULT_BRANCH_TYPES.includes(t);
|
|
52
|
-
}
|
|
53
|
-
const invalidTypes = options.branchTypes.filter(isInvalidType);
|
|
54
|
-
/**
|
|
55
|
-
* Conditional branch checking whether any invalid types were found.
|
|
56
|
-
* @story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md
|
|
57
|
-
* @req REQ-TRACEABILITY-INVALID-DETECTION - Trace handling when invalid types are detected
|
|
58
|
-
*/
|
|
59
|
-
if (invalidTypes.length > 0) {
|
|
60
|
-
/**
|
|
61
|
-
* Program listener produced when configuration is invalid.
|
|
62
|
-
* @story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md
|
|
63
|
-
* @req REQ-TRACEABILITY-PROGRAM-LISTENER - Trace Program listener reporting invalid config values
|
|
64
|
-
*/
|
|
65
|
-
function ProgramHandler(node) {
|
|
66
|
-
/**
|
|
67
|
-
* Report a single invalid type for the given Program node.
|
|
68
|
-
* @story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md
|
|
69
|
-
* @req REQ-TRACEABILITY-FOR-EACH-CALLBACK - Trace reporting for each invalid type
|
|
70
|
-
*/
|
|
71
|
-
function reportInvalidType(t) {
|
|
72
|
-
context.report({
|
|
73
|
-
node,
|
|
74
|
-
message: `Value "${t}" should be equal to one of the allowed values: ${exports.DEFAULT_BRANCH_TYPES.join(", ")}`,
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
invalidTypes.forEach(reportInvalidType);
|
|
78
|
-
}
|
|
79
|
-
return { Program: ProgramHandler };
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return Array.isArray(options.branchTypes)
|
|
83
|
-
? options.branchTypes
|
|
84
|
-
: Array.from(exports.DEFAULT_BRANCH_TYPES);
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Extract the raw value from a comment node.
|
|
88
|
-
* @story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md
|
|
89
|
-
* @req REQ-TRACEABILITY-MAP-CALLBACK - Trace mapping of comment nodes to their text values
|
|
90
|
-
*/
|
|
91
|
-
function extractCommentValue(_c) {
|
|
92
|
-
return _c.value;
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Extract trimmed comment text for a given source line index or return null
|
|
96
|
-
* when the line is blank or not a comment. This helper centralizes the
|
|
97
|
-
* formatter-aware rules used by branch helpers when scanning for contiguous
|
|
98
|
-
* comment lines around branches.
|
|
99
|
-
* @supports docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md REQ-COMMENT-ASSOCIATION
|
|
100
|
-
* @supports docs/stories/025.0-DEV-CATCH-ANNOTATION-POSITION.story.md REQ-DUAL-POSITION-DETECTION REQ-FALLBACK-LOGIC
|
|
101
|
-
* @supports docs/stories/026.0-DEV-ELSE-IF-ANNOTATION-POSITION.story.md REQ-DUAL-POSITION-DETECTION-ELSE-IF REQ-FALLBACK-LOGIC-ELSE-IF
|
|
102
|
-
*/
|
|
103
|
-
function getCommentTextAtLine(lines, index) {
|
|
104
|
-
const line = lines[index];
|
|
105
|
-
if (!line || !line.trim()) {
|
|
106
|
-
return null;
|
|
107
|
-
}
|
|
108
|
-
if (!/^\s*(\/\/|\/\*)/.test(line)) {
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
return line.trim();
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Collect a single contiguous comment line at the given index, appending its
|
|
115
|
-
* trimmed text to the accumulator. Returns true when a valid comment was
|
|
116
|
-
* collected and false when scanning should stop (blank or non-comment line).
|
|
117
|
-
* @supports docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md REQ-COMMENT-ASSOCIATION
|
|
118
|
-
* @supports docs/stories/025.0-DEV-CATCH-ANNOTATION-POSITION.story.md REQ-DUAL-POSITION-DETECTION REQ-FALLBACK-LOGIC
|
|
119
|
-
* @supports docs/stories/026.0-DEV-ELSE-IF-ANNOTATION-POSITION.story.md REQ-DUAL-POSITION-DETECTION-ELSE-IF REQ-FALLBACK-LOGIC-ELSE-IF
|
|
120
|
-
*/
|
|
121
|
-
function collectCommentLine(lines, index, comments) {
|
|
122
|
-
const commentText = getCommentTextAtLine(lines, index);
|
|
123
|
-
if (!commentText) {
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
comments.push(commentText);
|
|
127
|
-
return true;
|
|
41
|
+
return (0, branch_validation_1.validateBranchTypes)(context, exports.DEFAULT_BRANCH_TYPES);
|
|
128
42
|
}
|
|
129
43
|
/**
|
|
130
44
|
* Scan contiguous formatter-aware comment lines between the provided 0-based
|
|
@@ -148,62 +62,13 @@ function scanCommentLinesInRange(lines, startIndex, endIndexInclusive) {
|
|
|
148
62
|
const lastIndex = Math.min(endIndexInclusive, lines.length - 1);
|
|
149
63
|
let i = startIndex;
|
|
150
64
|
while (i <= lastIndex) {
|
|
151
|
-
if (!collectCommentLine(lines, i, comments)) {
|
|
65
|
+
if (!(0, comment_text_helpers_1.collectCommentLine)(lines, i, comments)) {
|
|
152
66
|
break;
|
|
153
67
|
}
|
|
154
68
|
i++;
|
|
155
69
|
}
|
|
156
70
|
return comments.join(" ");
|
|
157
71
|
}
|
|
158
|
-
function getInsideCatchCommentText(sourceCode, node) {
|
|
159
|
-
const getCommentsInside = sourceCode.getCommentsInside;
|
|
160
|
-
if (node.body && typeof getCommentsInside === "function") {
|
|
161
|
-
try {
|
|
162
|
-
const insideComments = getCommentsInside(node.body) || [];
|
|
163
|
-
const insideText = insideComments.map(extractCommentValue).join(" ");
|
|
164
|
-
if (insideText) {
|
|
165
|
-
return insideText;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
catch {
|
|
169
|
-
// fall through to line-based fallback
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
if (node.body && node.body.loc && node.body.loc.start && node.body.loc.end) {
|
|
173
|
-
const lines = sourceCode.lines;
|
|
174
|
-
const startIndex = node.body.loc.start.line - 1;
|
|
175
|
-
const endIndex = node.body.loc.end.line - 1;
|
|
176
|
-
const insideText = scanCommentLinesInRange(lines, startIndex + 1, endIndex);
|
|
177
|
-
if (insideText) {
|
|
178
|
-
return insideText;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
return "";
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Gather comment text from the first contiguous comment lines inside a TryStatement block body.
|
|
185
|
-
* @supports docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md REQ-INSIDE-BRACE-PLACEMENT REQ-PLACEMENT-CONFIG
|
|
186
|
-
*/
|
|
187
|
-
function getInsideTryBlockCommentText(sourceCode, node) {
|
|
188
|
-
const block = node && node.block;
|
|
189
|
-
if (!block ||
|
|
190
|
-
block.type !== "BlockStatement" ||
|
|
191
|
-
!block.loc ||
|
|
192
|
-
!block.loc.start ||
|
|
193
|
-
!block.loc.end ||
|
|
194
|
-
typeof block.loc.start.line !== "number" ||
|
|
195
|
-
typeof block.loc.end.line !== "number") {
|
|
196
|
-
return "";
|
|
197
|
-
}
|
|
198
|
-
const lines = sourceCode.lines;
|
|
199
|
-
const startIndex = block.loc.start.line - 1;
|
|
200
|
-
const endIndex = block.loc.end.line - 1;
|
|
201
|
-
const insideText = scanCommentLinesInRange(lines, startIndex + 1, endIndex);
|
|
202
|
-
if (insideText) {
|
|
203
|
-
return insideText;
|
|
204
|
-
}
|
|
205
|
-
return "";
|
|
206
|
-
}
|
|
207
72
|
/**
|
|
208
73
|
* Gather annotation text for CatchClause nodes, supporting both before-catch and inside-catch positions.
|
|
209
74
|
* @story docs/stories/025.0-DEV-CATCH-ANNOTATION-POSITION.story.md
|
|
@@ -212,7 +77,7 @@ function getInsideTryBlockCommentText(sourceCode, node) {
|
|
|
212
77
|
*/
|
|
213
78
|
function gatherCatchClauseCommentText(sourceCode, node, annotationPlacement, beforeText) {
|
|
214
79
|
if (annotationPlacement === "inside") {
|
|
215
|
-
const insideText = getInsideCatchCommentText(sourceCode, node);
|
|
80
|
+
const insideText = (0, branch_annotation_catch_helpers_1.getInsideCatchCommentText)(sourceCode, node);
|
|
216
81
|
if (insideText) {
|
|
217
82
|
return insideText;
|
|
218
83
|
}
|
|
@@ -223,7 +88,7 @@ function gatherCatchClauseCommentText(sourceCode, node, annotationPlacement, bef
|
|
|
223
88
|
/@supports\b/.test(beforeText)) {
|
|
224
89
|
return beforeText;
|
|
225
90
|
}
|
|
226
|
-
const insideText = getInsideCatchCommentText(sourceCode, node);
|
|
91
|
+
const insideText = (0, branch_annotation_catch_helpers_1.getInsideCatchCommentText)(sourceCode, node);
|
|
227
92
|
if (insideText) {
|
|
228
93
|
return insideText;
|
|
229
94
|
}
|
|
@@ -235,54 +100,13 @@ function gatherCatchClauseCommentText(sourceCode, node, annotationPlacement, bef
|
|
|
235
100
|
* leading comment text unchanged. When placement is "inside", it switches to inside-brace
|
|
236
101
|
* semantics and scans for comments at the top of the consequent block.
|
|
237
102
|
* @story docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md
|
|
238
|
-
* @supports REQ-INSIDE-BRACE-PLACEMENT
|
|
239
|
-
* @supports REQ-PLACEMENT-CONFIG
|
|
240
|
-
* @supports REQ-DEFAULT-BACKWARD-COMPAT
|
|
103
|
+
* @supports docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md REQ-INSIDE-BRACE-PLACEMENT REQ-PLACEMENT-CONFIG REQ-DEFAULT-BACKWARD-COMPAT
|
|
241
104
|
*/
|
|
242
|
-
function gatherSimpleIfCommentText(sourceCode, node, annotationPlacement, beforeText) {
|
|
243
|
-
if (annotationPlacement === "before") {
|
|
244
|
-
return beforeText;
|
|
245
|
-
}
|
|
246
|
-
if (annotationPlacement !== "inside") {
|
|
247
|
-
return beforeText;
|
|
248
|
-
}
|
|
249
|
-
if (!node.consequent || node.consequent.type !== "BlockStatement") {
|
|
250
|
-
return "";
|
|
251
|
-
}
|
|
252
|
-
const consequent = node.consequent;
|
|
253
|
-
const getCommentsInside = sourceCode.getCommentsInside;
|
|
254
|
-
if (typeof getCommentsInside === "function") {
|
|
255
|
-
try {
|
|
256
|
-
const insideComments = getCommentsInside(consequent) || [];
|
|
257
|
-
const insideText = insideComments.map(extractCommentValue).join(" ");
|
|
258
|
-
if (insideText) {
|
|
259
|
-
return insideText;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
catch {
|
|
263
|
-
// fall through to line-based fallback
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
if (consequent.loc &&
|
|
267
|
-
consequent.loc.start &&
|
|
268
|
-
consequent.loc.end &&
|
|
269
|
-
typeof consequent.loc.start.line === "number" &&
|
|
270
|
-
typeof consequent.loc.end.line === "number") {
|
|
271
|
-
const lines = sourceCode.lines;
|
|
272
|
-
const startIndex = consequent.loc.start.line - 1;
|
|
273
|
-
const endIndex = consequent.loc.end.line - 1;
|
|
274
|
-
const insideText = scanCommentLinesInRange(lines, startIndex + 1, endIndex);
|
|
275
|
-
if (insideText) {
|
|
276
|
-
return insideText;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
return "";
|
|
280
|
-
}
|
|
281
105
|
function handleTryCatchBranch(sourceCode, node, context) {
|
|
282
106
|
const { annotationPlacement, beforeText } = context;
|
|
283
107
|
if (node.type === "TryStatement") {
|
|
284
108
|
if (annotationPlacement === "inside") {
|
|
285
|
-
const insideText = getInsideTryBlockCommentText(sourceCode, node);
|
|
109
|
+
const insideText = (0, branch_annotation_catch_helpers_1.getInsideTryBlockCommentText)(sourceCode, node);
|
|
286
110
|
if (insideText) {
|
|
287
111
|
return insideText;
|
|
288
112
|
}
|
|
@@ -351,7 +175,7 @@ function gatherIfBranchCommentText(sourceCode, node, parent, context) {
|
|
|
351
175
|
beforeText,
|
|
352
176
|
});
|
|
353
177
|
}
|
|
354
|
-
return gatherSimpleIfCommentText(sourceCode, node, annotationPlacement, beforeText);
|
|
178
|
+
return (0, branch_annotation_if_helpers_1.gatherSimpleIfCommentText)(sourceCode, node, annotationPlacement, beforeText);
|
|
355
179
|
}
|
|
356
180
|
/**
|
|
357
181
|
* Internal helper that performs type-based dispatch for gathering branch comment text.
|
|
@@ -387,7 +211,7 @@ function gatherBranchCommentTextByType(sourceCode, node, parent, context) {
|
|
|
387
211
|
*/
|
|
388
212
|
function gatherBranchCommentText(sourceCode, node, parent, annotationPlacement = "before") {
|
|
389
213
|
const beforeComments = sourceCode.getCommentsBefore(node) || [];
|
|
390
|
-
const beforeText = beforeComments.map(extractCommentValue).join(" ");
|
|
214
|
+
const beforeText = beforeComments.map(comment_text_helpers_1.extractCommentValue).join(" ");
|
|
391
215
|
const handled = gatherBranchCommentTextByType(sourceCode, node, parent, {
|
|
392
216
|
annotationPlacement,
|
|
393
217
|
beforeText,
|
|
@@ -10,3 +10,4 @@ export declare function gatherElseIfCommentText(sourceCode: ReturnType<Rule.Rule
|
|
|
10
10
|
annotationPlacement: AnnotationPlacement;
|
|
11
11
|
beforeText: string;
|
|
12
12
|
}): string;
|
|
13
|
+
export declare function gatherSimpleIfCommentText(sourceCode: any, node: any, annotationPlacement: "before" | "inside", beforeText: string): string;
|
|
@@ -7,6 +7,7 @@ exports.scanElseIfBetweenConditionAndBody = scanElseIfBetweenConditionAndBody;
|
|
|
7
7
|
exports.scanElseIfInsideBlockComments = scanElseIfInsideBlockComments;
|
|
8
8
|
exports.getInsideElseIfCommentText = getInsideElseIfCommentText;
|
|
9
9
|
exports.gatherElseIfCommentText = gatherElseIfCommentText;
|
|
10
|
+
exports.gatherSimpleIfCommentText = gatherSimpleIfCommentText;
|
|
10
11
|
const branch_annotation_helpers_1 = require("./branch-annotation-helpers");
|
|
11
12
|
/**
|
|
12
13
|
* Small shared helpers for IfStatement/else-if specific annotation handling.
|
|
@@ -135,3 +136,61 @@ function gatherElseIfCommentText(sourceCode, node, parent, options) {
|
|
|
135
136
|
}
|
|
136
137
|
return beforeText;
|
|
137
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Try to get comments from inside a node using getCommentsInside if available.
|
|
141
|
+
*/
|
|
142
|
+
function tryGetCommentsInsideNode(sourceCode, consequent) {
|
|
143
|
+
const getCommentsInside = sourceCode.getCommentsInside;
|
|
144
|
+
if (typeof getCommentsInside !== "function") {
|
|
145
|
+
return "";
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
const insideComments = getCommentsInside(consequent) || [];
|
|
149
|
+
const extractCommentValue = (c) => c.value;
|
|
150
|
+
return insideComments.map(extractCommentValue).join(" ");
|
|
151
|
+
}
|
|
152
|
+
catch {
|
|
153
|
+
return "";
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Scan for comments at the start of a block using line-based fallback.
|
|
158
|
+
*/
|
|
159
|
+
function scanBlockStartComments(sourceCode, consequent) {
|
|
160
|
+
if (!consequent.loc ||
|
|
161
|
+
!consequent.loc.start ||
|
|
162
|
+
!consequent.loc.end ||
|
|
163
|
+
typeof consequent.loc.start.line !== "number" ||
|
|
164
|
+
typeof consequent.loc.end.line !== "number") {
|
|
165
|
+
return "";
|
|
166
|
+
}
|
|
167
|
+
const lines = sourceCode.lines;
|
|
168
|
+
const startIndex = consequent.loc.start.line - 1;
|
|
169
|
+
const endIndex = consequent.loc.end.line - 1;
|
|
170
|
+
const comments = [];
|
|
171
|
+
const lastIndex = Math.min(endIndex, lines.length - 1);
|
|
172
|
+
let i = startIndex + 1;
|
|
173
|
+
while (i <= lastIndex) {
|
|
174
|
+
const line = lines[i];
|
|
175
|
+
if (!line || !line.trim() || !/^\s*(\/\/|\/\*)/.test(line)) {
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
comments.push(line.trim());
|
|
179
|
+
i++;
|
|
180
|
+
}
|
|
181
|
+
return comments.join(" ");
|
|
182
|
+
}
|
|
183
|
+
function gatherSimpleIfCommentText(sourceCode, node, annotationPlacement, beforeText) {
|
|
184
|
+
if (annotationPlacement !== "inside") {
|
|
185
|
+
return beforeText;
|
|
186
|
+
}
|
|
187
|
+
if (!node.consequent || node.consequent.type !== "BlockStatement") {
|
|
188
|
+
return "";
|
|
189
|
+
}
|
|
190
|
+
const consequent = node.consequent;
|
|
191
|
+
const insideText = tryGetCommentsInsideNode(sourceCode, consequent);
|
|
192
|
+
if (insideText) {
|
|
193
|
+
return insideText;
|
|
194
|
+
}
|
|
195
|
+
return scanBlockStartComments(sourceCode, consequent);
|
|
196
|
+
}
|
|
@@ -7,7 +7,7 @@ import type { AnnotationPlacement } from "./branch-annotation-helpers";
|
|
|
7
7
|
* within ESLint's max-lines-per-function limits.
|
|
8
8
|
*
|
|
9
9
|
* @story docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md
|
|
10
|
-
* @supports REQ-INSIDE-BRACE-PLACEMENT REQ-PLACEMENT-CONFIG REQ-INDENTATION-CORRECT
|
|
10
|
+
* @supports docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md REQ-INSIDE-BRACE-PLACEMENT REQ-PLACEMENT-CONFIG REQ-INDENTATION-CORRECT
|
|
11
11
|
*/
|
|
12
12
|
type SourceCode = ReturnType<Rule.RuleContext["getSourceCode"]>;
|
|
13
13
|
type IndentHelperContext = {
|
|
@@ -3,9 +3,15 @@ import { type AnnotationPlacement } from "./branch-annotation-helpers";
|
|
|
3
3
|
/**
|
|
4
4
|
* Gather annotation text for SwitchCase branches, honoring the configured placement
|
|
5
5
|
* while preserving legacy before-branch behavior in the default mode.
|
|
6
|
+
*
|
|
6
7
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
7
8
|
* @story docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md
|
|
8
|
-
* @supports REQ-PLACEMENT-CONFIG
|
|
9
|
-
* @supports REQ-INSIDE-BRACE-PLACEMENT
|
|
9
|
+
* @supports docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md REQ-PLACEMENT-CONFIG
|
|
10
|
+
* @supports docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md REQ-INSIDE-BRACE-PLACEMENT
|
|
11
|
+
* @param sourceCode - ESLint source code object for accessing line/comment data
|
|
12
|
+
* @param node - SwitchCase AST node to gather annotations from
|
|
13
|
+
* @param annotationPlacement - Placement mode ("inside" or "before")
|
|
14
|
+
* @param beforeText - Pre-gathered text from before the case statement
|
|
15
|
+
* @returns Combined annotation text based on placement mode and detected annotations
|
|
10
16
|
*/
|
|
11
17
|
export declare function gatherSwitchCaseCommentText(sourceCode: ReturnType<Rule.RuleContext["getSourceCode"]>, node: any, annotationPlacement: AnnotationPlacement, beforeText: string): string;
|
|
@@ -6,8 +6,8 @@ const branch_annotation_helpers_1 = require("./branch-annotation-helpers");
|
|
|
6
6
|
* Gather comment text from the first contiguous comment lines "inside" a SwitchCase body.
|
|
7
7
|
* Prefers a BlockStatement consequent when present, with a fallback to the entire case range.
|
|
8
8
|
* @story docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md
|
|
9
|
-
* @supports REQ-INSIDE-BRACE-PLACEMENT
|
|
10
|
-
* @supports REQ-PLACEMENT-CONFIG
|
|
9
|
+
* @supports docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md REQ-INSIDE-BRACE-PLACEMENT
|
|
10
|
+
* @supports docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md REQ-PLACEMENT-CONFIG
|
|
11
11
|
*/
|
|
12
12
|
function getInsideSwitchCaseCommentText(sourceCode, node) {
|
|
13
13
|
const lines = sourceCode.lines;
|
|
@@ -44,10 +44,16 @@ function getInsideSwitchCaseCommentText(sourceCode, node) {
|
|
|
44
44
|
/**
|
|
45
45
|
* Gather annotation text for SwitchCase branches, honoring the configured placement
|
|
46
46
|
* while preserving legacy before-branch behavior in the default mode.
|
|
47
|
+
*
|
|
47
48
|
* @story docs/stories/003.0-DEV-FUNCTION-ANNOTATIONS.story.md
|
|
48
49
|
* @story docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md
|
|
49
|
-
* @supports REQ-PLACEMENT-CONFIG
|
|
50
|
-
* @supports REQ-INSIDE-BRACE-PLACEMENT
|
|
50
|
+
* @supports docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md REQ-PLACEMENT-CONFIG
|
|
51
|
+
* @supports docs/stories/028.0-DEV-ANNOTATION-PLACEMENT-STANDARDIZATION.story.md REQ-INSIDE-BRACE-PLACEMENT
|
|
52
|
+
* @param sourceCode - ESLint source code object for accessing line/comment data
|
|
53
|
+
* @param node - SwitchCase AST node to gather annotations from
|
|
54
|
+
* @param annotationPlacement - Placement mode ("inside" or "before")
|
|
55
|
+
* @param beforeText - Pre-gathered text from before the case statement
|
|
56
|
+
* @returns Combined annotation text based on placement mode and detected annotations
|
|
51
57
|
*/
|
|
52
58
|
function gatherSwitchCaseCommentText(sourceCode, node, annotationPlacement, beforeText) {
|
|
53
59
|
if (annotationPlacement === "inside") {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Rule } from "eslint";
|
|
2
|
+
import type { BranchType } from "./branch-annotation-helpers";
|
|
3
|
+
/**
|
|
4
|
+
* Validate branchTypes configuration option and return branch types to enforce,
|
|
5
|
+
* or return an ESLint listener if configuration is invalid.
|
|
6
|
+
* @story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md
|
|
7
|
+
* @req REQ-CONFIGURABLE-SCOPE - Allow configuration of branch types for annotation enforcement
|
|
8
|
+
*/
|
|
9
|
+
export declare function validateBranchTypes(context: Rule.RuleContext, DEFAULT_BRANCH_TYPES: readonly BranchType[]): BranchType[] | Rule.RuleListener;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateBranchTypes = validateBranchTypes;
|
|
4
|
+
/**
|
|
5
|
+
* Validate branchTypes configuration option and return branch types to enforce,
|
|
6
|
+
* or return an ESLint listener if configuration is invalid.
|
|
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
|
+
*/
|
|
10
|
+
function validateBranchTypes(context, DEFAULT_BRANCH_TYPES) {
|
|
11
|
+
const options = context.options[0] || {};
|
|
12
|
+
/**
|
|
13
|
+
* Conditional branch checking whether branchTypes option was provided.
|
|
14
|
+
* @story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md
|
|
15
|
+
* @req REQ-TRACEABILITY-CONDITIONAL - Trace configuration branch existence check
|
|
16
|
+
*/
|
|
17
|
+
if (Array.isArray(options.branchTypes)) {
|
|
18
|
+
/**
|
|
19
|
+
* Predicate to determine whether a provided branch type is invalid.
|
|
20
|
+
* @story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md
|
|
21
|
+
* @req REQ-TRACEABILITY-FILTER-CALLBACK - Trace filter callback for invalid branch type detection
|
|
22
|
+
*/
|
|
23
|
+
function isInvalidType(t) {
|
|
24
|
+
return !DEFAULT_BRANCH_TYPES.includes(t);
|
|
25
|
+
}
|
|
26
|
+
const invalidTypes = options.branchTypes.filter(isInvalidType);
|
|
27
|
+
/**
|
|
28
|
+
* Conditional branch checking whether any invalid types were found.
|
|
29
|
+
* @story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md
|
|
30
|
+
* @req REQ-TRACEABILITY-INVALID-DETECTION - Trace handling when invalid types are detected
|
|
31
|
+
*/
|
|
32
|
+
if (invalidTypes.length > 0) {
|
|
33
|
+
/**
|
|
34
|
+
* Program listener produced when configuration is invalid.
|
|
35
|
+
* @story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md
|
|
36
|
+
* @req REQ-TRACEABILITY-PROGRAM-LISTENER - Trace Program listener reporting invalid config values
|
|
37
|
+
*/
|
|
38
|
+
function ProgramHandler(node) {
|
|
39
|
+
/**
|
|
40
|
+
* Report a single invalid type for the given Program node.
|
|
41
|
+
* @story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md
|
|
42
|
+
* @req REQ-TRACEABILITY-FOR-EACH-CALLBACK - Trace reporting for each invalid type
|
|
43
|
+
*/
|
|
44
|
+
function reportInvalidType(t) {
|
|
45
|
+
context.report({
|
|
46
|
+
node,
|
|
47
|
+
message: `Value "${t}" should be equal to one of the allowed values: ${DEFAULT_BRANCH_TYPES.join(", ")}`,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
invalidTypes.forEach(reportInvalidType);
|
|
51
|
+
}
|
|
52
|
+
return { Program: ProgramHandler };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return Array.isArray(options.branchTypes)
|
|
56
|
+
? options.branchTypes
|
|
57
|
+
: Array.from(DEFAULT_BRANCH_TYPES);
|
|
58
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Low-level comment text extraction helpers for branch annotation processing.
|
|
3
|
+
*
|
|
4
|
+
* @story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md
|
|
5
|
+
* @req REQ-COMMENT-ASSOCIATION - Extract and normalize comment text from various comment node types
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Extract the raw value from a comment node.
|
|
9
|
+
* @story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md
|
|
10
|
+
* @req REQ-TRACEABILITY-MAP-CALLBACK - Trace mapping of comment nodes to their text values
|
|
11
|
+
*/
|
|
12
|
+
export declare function extractCommentValue(_c: any): string;
|
|
13
|
+
/**
|
|
14
|
+
* Extract trimmed comment text for a given source line index or return null
|
|
15
|
+
* when the line is blank or not a comment. This helper centralizes the
|
|
16
|
+
* formatter-aware rules used by branch helpers when scanning for contiguous
|
|
17
|
+
* comment lines around branches.
|
|
18
|
+
* @supports docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md REQ-COMMENT-ASSOCIATION
|
|
19
|
+
* @supports docs/stories/025.0-DEV-CATCH-ANNOTATION-POSITION.story.md REQ-DUAL-POSITION-DETECTION REQ-FALLBACK-LOGIC
|
|
20
|
+
* @supports docs/stories/026.0-DEV-ELSE-IF-ANNOTATION-POSITION.story.md REQ-DUAL-POSITION-DETECTION-ELSE-IF REQ-FALLBACK-LOGIC-ELSE-IF
|
|
21
|
+
*/
|
|
22
|
+
export declare function getCommentTextAtLine(lines: string[], index: number): string | null;
|
|
23
|
+
/**
|
|
24
|
+
* Collect a single contiguous comment line at the given index, appending its
|
|
25
|
+
* trimmed text to the accumulator. Returns true when a valid comment was
|
|
26
|
+
* collected and false when scanning should stop (blank or non-comment line).
|
|
27
|
+
* @supports docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md REQ-COMMENT-ASSOCIATION
|
|
28
|
+
* @supports docs/stories/025.0-DEV-CATCH-ANNOTATION-POSITION.story.md REQ-DUAL-POSITION-DETECTION REQ-FALLBACK-LOGIC
|
|
29
|
+
* @supports docs/stories/026.0-DEV-ELSE-IF-ANNOTATION-POSITION.story.md REQ-DUAL-POSITION-DETECTION-ELSE-IF REQ-FALLBACK-LOGIC-ELSE-IF
|
|
30
|
+
*/
|
|
31
|
+
export declare function collectCommentLine(lines: string[], index: number, comments: string[]): boolean;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Low-level comment text extraction helpers for branch annotation processing.
|
|
4
|
+
*
|
|
5
|
+
* @story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md
|
|
6
|
+
* @req REQ-COMMENT-ASSOCIATION - Extract and normalize comment text from various comment node types
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.extractCommentValue = extractCommentValue;
|
|
10
|
+
exports.getCommentTextAtLine = getCommentTextAtLine;
|
|
11
|
+
exports.collectCommentLine = collectCommentLine;
|
|
12
|
+
/**
|
|
13
|
+
* Extract the raw value from a comment node.
|
|
14
|
+
* @story docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md
|
|
15
|
+
* @req REQ-TRACEABILITY-MAP-CALLBACK - Trace mapping of comment nodes to their text values
|
|
16
|
+
*/
|
|
17
|
+
function extractCommentValue(_c) {
|
|
18
|
+
return _c.value;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Extract trimmed comment text for a given source line index or return null
|
|
22
|
+
* when the line is blank or not a comment. This helper centralizes the
|
|
23
|
+
* formatter-aware rules used by branch helpers when scanning for contiguous
|
|
24
|
+
* comment lines around branches.
|
|
25
|
+
* @supports docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md REQ-COMMENT-ASSOCIATION
|
|
26
|
+
* @supports docs/stories/025.0-DEV-CATCH-ANNOTATION-POSITION.story.md REQ-DUAL-POSITION-DETECTION REQ-FALLBACK-LOGIC
|
|
27
|
+
* @supports docs/stories/026.0-DEV-ELSE-IF-ANNOTATION-POSITION.story.md REQ-DUAL-POSITION-DETECTION-ELSE-IF REQ-FALLBACK-LOGIC-ELSE-IF
|
|
28
|
+
*/
|
|
29
|
+
function getCommentTextAtLine(lines, index) {
|
|
30
|
+
const line = lines[index];
|
|
31
|
+
if (!line || !line.trim()) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
if (!/^\s*(\/\/|\/\*)/.test(line)) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
return line.trim();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Collect a single contiguous comment line at the given index, appending its
|
|
41
|
+
* trimmed text to the accumulator. Returns true when a valid comment was
|
|
42
|
+
* collected and false when scanning should stop (blank or non-comment line).
|
|
43
|
+
* @supports docs/stories/004.0-DEV-BRANCH-ANNOTATIONS.story.md REQ-COMMENT-ASSOCIATION
|
|
44
|
+
* @supports docs/stories/025.0-DEV-CATCH-ANNOTATION-POSITION.story.md REQ-DUAL-POSITION-DETECTION REQ-FALLBACK-LOGIC
|
|
45
|
+
* @supports docs/stories/026.0-DEV-ELSE-IF-ANNOTATION-POSITION.story.md REQ-DUAL-POSITION-DETECTION-ELSE-IF REQ-FALLBACK-LOGIC-ELSE-IF
|
|
46
|
+
*/
|
|
47
|
+
function collectCommentLine(lines, index, comments) {
|
|
48
|
+
const commentText = getCommentTextAtLine(lines, index);
|
|
49
|
+
if (!commentText) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
comments.push(commentText);
|
|
53
|
+
return true;
|
|
54
|
+
}
|