{"version":3,"file":"util.format-block.cjs","sources":["../../../../src/rules/limit-single-line-comments/util.format-block.ts"],"sourcesContent":["import type { TSESTree } from \"@typescript-eslint/utils\";\n\nimport type { Context } from \"../../typings.context.js\";\nimport { isAnotherWrapPointComing } from \"../../utils/is-another-wrap-point-coming.js\";\nimport { isPunctuation } from \"../../utils/is-punctuation.js\";\nimport { isURL } from \"../../utils/is-url.js\";\n\nimport { SINGLE_LINE_COMMENT_BOILERPLATE_SIZE } from \"./const.boilerplate-size.js\";\n\nexport function formatBlock(\n  block: TSESTree.LineComment,\n  context: Context,\n): string {\n  const lineStartSize =\n    context.whitespace.size + SINGLE_LINE_COMMENT_BOILERPLATE_SIZE;\n  const words = block.value.trim().split(\" \");\n  const newValue = words.reduce(\n    (acc, curr, index) => {\n      const currentWordIsURL = isURL(curr);\n      const lengthIfAdded = acc.currentLineLength + curr.length + 1;\n\n      // We can safely split to a new line in case we are reaching and\n      // overflowing line AND if there is at least one word on the current line.\n      const splitToNewline =\n        lengthIfAdded >= context.maxLength &&\n        acc.currentLineLength !== lineStartSize &&\n        (!context.ignoreUrls || !currentWordIsURL);\n\n      const previousWord = words[index - 1];\n\n      const splitEarly =\n        context.logicalWrap &&\n        acc.currentLineLength >= context.maxLength / 2 &&\n        previousWord &&\n        isPunctuation(previousWord.at(-1)) &&\n        previousWord.length > 1 &&\n        !isAnotherWrapPointComing(\n          acc.currentLineLength,\n          context.maxLength,\n          words.slice(index),\n        );\n\n      if (splitToNewline || splitEarly) {\n        return {\n          value: `${acc.value}\\n${context.whitespace.string}// ${curr}`,\n          currentLineLength: lineStartSize + curr.length,\n        };\n      } else {\n        return {\n          value: `${acc.value} ${curr}`,\n          currentLineLength: lengthIfAdded,\n        };\n      }\n    },\n    { value: \"//\", currentLineLength: lineStartSize },\n  );\n  return newValue.value;\n}\n"],"names":["SINGLE_LINE_COMMENT_BOILERPLATE_SIZE","isURL","isPunctuation","isAnotherWrapPointComing"],"mappings":";;;;;;;AASO,SAAS,WAA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