{"version":3,"file":"fix.overflow.cjs","sources":["../../../../src/rules/limit-multi-line-comments/fix.overflow.ts"],"sourcesContent":["import type { TSESLint } from \"@typescript-eslint/utils\";\n\nimport type { Context } from \"../../typings.context.js\";\n\nimport type { MultilineBlock } from \"./typings.block.js\";\nimport { FIRST_LINE_BOILERPLATE_SIZE } from \"./util.boilerplate-size.js\";\nimport { formatBlock } from \"./util.format-block.js\";\n\nexport function fixOverflowingBlock(\n  fixer: TSESLint.RuleFixer,\n  fixableBlock: MultilineBlock,\n  context: Context,\n) {\n  const newValue = formatBlock(fixableBlock, context);\n\n  // Now, in case the entire block is only a single line\n  // (e.g. /** text... */), then we should expand it into a multi-line\n  // comment to preserve space.\n  if (context.comment.lines.length === 1) {\n    return fixer.replaceTextRange(\n      context.comment.range,\n      `/**\\n${newValue}\\n${context.whitespace.string} */`,\n    );\n  } else {\n    // ... else we should simply replace the part of the comment which\n    // overflows.\n    const rawLines = context.comment.value.split(\"\\n\");\n    const rangeStart =\n      context.comment.range[0] +\n      FIRST_LINE_BOILERPLATE_SIZE +\n      rawLines.slice(0, fixableBlock.startIndex).join(\"\\n\").length;\n    const rangeEnd =\n      context.comment.range[0] +\n      FIRST_LINE_BOILERPLATE_SIZE -\n      1 +\n      rawLines.slice(0, fixableBlock.endIndex + 1).join(\"\\n\").length;\n\n    let paddedValue = newValue;\n\n    // and, in the rare case where the violating block starts on\n    // the same line as the start of the multi-comment\n    // (i.e. /** my-comment...), then move it down to the next line,\n    // to maximize the available space.\n    if (fixableBlock.startIndex === 0) {\n      paddedValue = `\\n${paddedValue}`;\n    }\n\n    // ... and ensure that the end of the comment is actually pushed to the\n    // final line if it isn't already.\n    if (fixableBlock.endIndex === rawLines.length - 1) {\n      paddedValue = `${paddedValue}\\n${context.whitespace.string} `;\n    }\n\n    return fixer.replaceTextRange([rangeStart, rangeEnd], paddedValue);\n  }\n}\n"],"names":["formatBlock","FIRST_LINE_BOILERPLATE_SIZE"],"mappings":";;;;;AAQO,SAAS,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