eslint-plugin-comment-length
Version:
An ESLint plugin that provides rules that limit the line length of your comments
32 lines (29 loc) • 1.17 kB
JavaScript
import { FIRST_LINE_BOILERPLATE_SIZE } from './util.boilerplate-size.js';
import { formatBlock } from './util.format-block.js';
function fixOverflowingBlock(fixer, fixableBlock, context) {
const newValue = formatBlock(fixableBlock, context);
if (context.comment.lines.length === 1) {
return fixer.replaceTextRange(
context.comment.range,
`/**
${newValue}
${context.whitespace.string} */`
);
} else {
const rawLines = context.comment.value.split("\n");
const rangeStart = context.comment.range[0] + FIRST_LINE_BOILERPLATE_SIZE + rawLines.slice(0, fixableBlock.startIndex).join("\n").length;
const rangeEnd = context.comment.range[0] + FIRST_LINE_BOILERPLATE_SIZE - 1 + rawLines.slice(0, fixableBlock.endIndex + 1).join("\n").length;
let paddedValue = newValue;
if (fixableBlock.startIndex === 0) {
paddedValue = `
${paddedValue}`;
}
if (fixableBlock.endIndex === rawLines.length - 1) {
paddedValue = `${paddedValue}
${context.whitespace.string} `;
}
return fixer.replaceTextRange([rangeStart, rangeEnd], paddedValue);
}
}
export { fixOverflowingBlock };
//# sourceMappingURL=fix.overflow.js.map