UNPKG

eslint-plugin-comment-length

Version:

An ESLint plugin that provides rules that limit the line length of your comments

95 lines (91 loc) 2.98 kB
'use strict'; var isLineOverflowing = require('../../utils/is-line-overflowing.cjs'); function captureNextBlock(ignoreFollowingLines, initialStartIndex, context) { let ignoreLines = ignoreFollowingLines; let startIndex = initialStartIndex; for (let i = initialStartIndex; i < context.comment.lines.length; i++) { const line = context.comment.lines[i]; if (line?.trimStart().startsWith("` ") || line?.trimStart().startsWith("``")) { ignoreLines = !ignoreLines; continue; } startIndex = i; if (line && line.trim() !== "" && !ignoreLines) { break; } } const blockLines = context.comment.lines.slice( startIndex, startIndex + 1 ); if (blockLines.length === 0) { return [ { lines: blockLines, startIndex, endIndex: startIndex, lineOffsets: [] }, ignoreLines ]; } for (let i = startIndex; i < context.comment.lines.length; i++) { const currLine = context.comment.lines[i]; const nextLine = context.comment.lines[i + 1]; if (!currLine) { break; } const currLineOffset = currLine.match(/^( |\t)*/)?.[0]?.split("").reduce( (acc, curr) => acc + (curr === " " ? context.tabSize : 1), 0 ) ?? 0; const nextLineOffset = nextLine?.match(/^( |\t)*/)?.[0]?.split("").reduce( (acc, curr) => acc + (curr === " " ? context.tabSize : 1), 0 ) ?? 0; if (!nextLine || nextLine.trim() === "" || currLineOffset !== nextLineOffset || context.mode === "overflow-only" && !isLineOverflowing.isLineOverflowing( `${currLine} ${nextLine.trimStart().split(" ")[0] ?? ""}`.trimEnd(), context )) { return [ { lines: blockLines, startIndex, endIndex: i, lineOffsets: blockLines.map((it, lineIndex) => { const whitespaceString = context.comment.value.split("\n")[startIndex + lineIndex]?.includes("*") ? it.match(/^( |\t)*/)?.[0] ?? "" : " "; return { string: whitespaceString, size: whitespaceString.split("").reduce( (acc, curr) => acc + (curr === " " ? context.tabSize : 1), 0 ) ?? 0 }; }) }, ignoreLines ]; } blockLines.push(nextLine); } return [ { lines: blockLines, startIndex, endIndex: context.comment.lines.length, lineOffsets: blockLines.map((it, lineIndex) => { const whitespaceString = context.comment.value.split("\n")[startIndex + lineIndex]?.includes("*") ? it.match(/^( |\t)*/)?.[0] ?? "" : " "; return { string: whitespaceString, size: whitespaceString.split("").reduce( (acc, curr) => acc + (curr === " " ? context.tabSize : 1), 0 ) ?? 0 }; }) }, ignoreLines ]; } exports.captureNextBlock = captureNextBlock; //# sourceMappingURL=util.capture-next-block.cjs.map