eslint-plugin-comment-length
Version:
An ESLint plugin that provides rules that limit the line length of your comments
34 lines (30 loc) • 1.26 kB
JavaScript
;
var util_boilerplateSize = require('./util.boilerplate-size.cjs');
var util_formatBlock = require('./util.format-block.cjs');
function fixOverflowingBlock(fixer, fixableBlock, context) {
const newValue = util_formatBlock.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] + util_boilerplateSize.FIRST_LINE_BOILERPLATE_SIZE + rawLines.slice(0, fixableBlock.startIndex).join("\n").length;
const rangeEnd = context.comment.range[0] + util_boilerplateSize.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);
}
}
exports.fixOverflowingBlock = fixOverflowingBlock;
//# sourceMappingURL=fix.overflow.cjs.map