eslint-plugin-comment-length
Version:
An ESLint plugin that provides rules that limit the line length of your comments
25 lines (22 loc) • 1.19 kB
JavaScript
import { isLineOverflowing } from '../../utils/is-line-overflowing.js';
import { isCommentOnOwnLine } from '../../utils/is-on-own-line.js';
import { isSemanticComment } from '../../utils/is-semantic-comment.js';
import { mergeComments } from './util.merge-comments.js';
function captureRelevantCommentsIntoBlock(sourceCode, comments, startIndex, context) {
let comment = comments[startIndex];
if (!comment) {
return { mergedComment: void 0, startIndex, endIndex: startIndex };
}
let endIndex = startIndex;
for (let i = startIndex + 1; i < comments.length; i++) {
const nextComment = comments[i];
if (context.mode === "overflow-only" && !isLineOverflowing(comment.value, context) || !nextComment || nextComment.value.trim() === "" || nextComment.loc?.start.line !== (comment.loc?.end.line ?? 0) + 1 || isSemanticComment(nextComment, context.semanticComments) || !isCommentOnOwnLine(sourceCode, nextComment)) {
break;
}
comment = mergeComments(comment, nextComment);
endIndex = i;
}
return { mergedComment: comment, startIndex, endIndex };
}
export { captureRelevantCommentsIntoBlock };
//# sourceMappingURL=util.capture-relevant-comments.js.map