{"version":3,"file":"root.cjs","sources":["../../../../src/rules/limit-single-line-comments/root.ts"],"sourcesContent":["import type { TSESTree } from \"@typescript-eslint/utils\";\nimport type { RuleContext } from \"@typescript-eslint/utils/ts-eslint\";\n\nimport { MessageIds } from \"../../const.message-ids.js\";\nimport type { Context } from \"../../typings.context.js\";\nimport type { Options } from \"../../typings.options.js\";\nimport { isCodeInComment } from \"../../utils/is-code-in-comment.js\";\nimport { isCommentInComment } from \"../../utils/is-comment-in-comment.js\";\nimport { isLineOverflowing } from \"../../utils/is-line-overflowing.js\";\nimport { isCommentOnOwnLine } from \"../../utils/is-on-own-line.js\";\nimport { isSemanticComment } from \"../../utils/is-semantic-comment.js\";\n\nimport { SINGLE_LINE_COMMENT_BOILERPLATE_SIZE } from \"./const.boilerplate-size.js\";\nimport { fixOverflow } from \"./fix.overflow.js\";\nimport { canBlockBeCompated } from \"./util.can-block-be-compacted.js\";\nimport { captureNearbyComments } from \"./util.capture-nearby-comments.js\";\nimport { captureRelevantCommentsIntoBlock } from \"./util.capture-relevant-comments.js\";\n\nexport function limitSingleLineComments(\n  ruleContext: RuleContext<string, unknown[]>,\n  options: Options,\n  comments: TSESTree.LineComment[],\n) {\n  const sourceCode = ruleContext.sourceCode;\n  const lines = sourceCode.getLines();\n\n  for (let i = 0; i < comments.length; i++) {\n    const currentCommentLine = comments[i];\n\n    if (\n      !currentCommentLine?.range ||\n      !currentCommentLine.value ||\n      !isCommentOnOwnLine(sourceCode, currentCommentLine) ||\n      isSemanticComment(currentCommentLine, options.semanticComments)\n    ) {\n      continue;\n    }\n\n    const line = lines[currentCommentLine.loc.start.line - 1];\n    const whitespaceString = line?.split(\"//\")[0] ?? \"\";\n\n    let context = {\n      ...options,\n      whitespace: {\n        string: whitespaceString,\n        size: whitespaceString\n          .split(\"\")\n          .reduce(\n            (acc, curr) => acc + (curr === \"\\t\" ? options.tabSize : 1),\n            0,\n          ),\n      },\n      boilerplateSize: SINGLE_LINE_COMMENT_BOILERPLATE_SIZE,\n      comment: {\n        range: currentCommentLine.range,\n        lines: [currentCommentLine.value],\n        value: currentCommentLine.value,\n      },\n    } satisfies Context;\n\n    const currentBlock = captureRelevantCommentsIntoBlock(\n      sourceCode,\n      comments,\n      i,\n      context,\n    );\n    const fixableComment = currentBlock.mergedComment;\n\n    // ensure that we only visit a captured block once\n    i += currentBlock.endIndex - currentBlock.startIndex;\n\n    const nearbyComments = captureNearbyComments(comments, i);\n    const wrappedByBackticks =\n      (nearbyComments?.value.trimStart().startsWith(\"` \") ||\n        nearbyComments?.value.trimStart().startsWith(\"``\")) &&\n      nearbyComments?.value.trimEnd().endsWith(\"`\");\n\n    if (\n      !fixableComment ||\n      wrappedByBackticks ||\n      isCommentInComment(fixableComment.value) ||\n      isCodeInComment(nearbyComments?.value, context)\n    ) {\n      continue;\n    }\n\n    // Update our context to reflect that we may have merged multiple comment\n    // lines into a singular block.\n    context = {\n      ...context,\n      comment: {\n        range: fixableComment.range,\n        lines: [fixableComment.value],\n        value: fixableComment.value,\n      },\n    };\n\n    // In case any lines in our current block overflows, then we need to warn\n    // that overflow has been detected\n    if (\n      comments\n        .slice(currentBlock.startIndex, currentBlock.endIndex + 1)\n        .some((line) => isLineOverflowing(line.value, context))\n    ) {\n      ruleContext.report({\n        loc: fixableComment.loc,\n        messageId: MessageIds.EXCEEDS_MAX_LENGTH,\n        data: {\n          maxLength: context.maxLength,\n        },\n        fix: (fixer) => fixOverflow(fixer, fixableComment, context),\n      });\n    } else if (\n      context.mode === \"compact\" &&\n      canBlockBeCompated(comments, currentBlock, context)\n    ) {\n      ruleContext.report({\n        loc: fixableComment.loc,\n        messageId: MessageIds.CAN_COMPACT,\n        data: {\n          maxLength: context.maxLength,\n        },\n        fix: (fixer) => fixOverflow(fixer, fixableComment, context),\n      });\n    }\n  }\n}\n"],"names":["isCommentOnOwnLine","isSemanticComment","SINGLE_LINE_COMMENT_BOILERPLATE_SIZE","captureRelevantCommentsIntoBlock","captureNearbyComments","isCommentInComment","isCodeInCom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