{"version":3,"file":"rule.cjs","sources":["../../../../src/rules/limit-tagged-template-literal-comments/rule.ts"],"sourcesContent":["import {\n  AST_TOKEN_TYPES,\n  type TSESTree,\n  ESLintUtils,\n} from \"@typescript-eslint/utils\";\nimport { isIdentifier } from \"@typescript-eslint/utils/ast-utils\";\n\nimport type { MessageIds } from \"../../const.message-ids.js\";\nimport { reportMessages } from \"../../const.message-ids.js\";\nimport {\n  type Options,\n  defaultOptions,\n  optionsSchema,\n} from \"../../typings.options.js\";\nimport { resolveDocsRoute } from \"../../utils/resolve-docs-route.js\";\nimport { limitMultiLineComments } from \"../limit-multi-line-comments/root.js\";\nimport { limitSingleLineComments } from \"../limit-single-line-comments/root.js\";\n\nconst createRule = ESLintUtils.RuleCreator(resolveDocsRoute);\n\nexport const limitTaggedTemplateLiteralCommentsRule = createRule<\n  [Options & { tags: string[] }],\n  MessageIds\n>({\n  name: \"limit-tagged-template-literal-comments\",\n  defaultOptions: [{ ...defaultOptions[0], tags: [\"css\"] }],\n  meta: {\n    type: \"layout\",\n    fixable: \"whitespace\",\n    messages: reportMessages,\n    docs: {\n      description:\n        \"Reflows javascript comments within tagged template literals to ensure that blocks never exceed the configured length\",\n    },\n    schema: [\n      {\n        ...optionsSchema,\n        type: \"object\",\n        properties: {\n          ...optionsSchema[0].properties,\n          tags: { type: \"array\", items: { type: \"string\" } },\n        },\n      },\n    ],\n  },\n\n  create: (ruleContext, [options]) => {\n    return {\n      TaggedTemplateExpression: (node) => {\n        if (!isIdentifier(node.tag) || !options.tags.includes(node.tag.name)) {\n          return;\n        }\n\n        const blockComments = [] as TSESTree.BlockComment[];\n        const lineComments = [] as TSESTree.LineComment[];\n\n        for (const quasi of node.quasi.quasis) {\n          let column = quasi.loc.start.column;\n          let line = quasi.loc.start.line;\n          let rangeIndex = quasi.range[0];\n\n          let currentBlockComment: undefined | TSESTree.BlockComment;\n          let currentLineComment: undefined | TSESTree.LineComment;\n\n          for (\n            let cursor = 0;\n            cursor < (quasi.value.cooked ?? []).length;\n            cursor++\n          ) {\n            const currentChar = quasi.value.cooked?.[cursor];\n            const nextChar = quasi.value.cooked?.[cursor + 1];\n\n            rangeIndex++;\n\n            if (currentChar === \"/\" && nextChar === \"*\") {\n              currentBlockComment = {\n                type: AST_TOKEN_TYPES.Block,\n                value: \"\",\n                loc: {\n                  start: {\n                    column,\n                    line,\n                  },\n                  end: {\n                    column: 0,\n                    line: 0,\n                  },\n                },\n                range: [rangeIndex, 0],\n              };\n\n              // Skip the next char which is also part of the start of our\n              // comment.\n              cursor++;\n              column += 2;\n              rangeIndex++;\n              continue;\n            }\n\n            if (\n              currentChar === \"*\" &&\n              nextChar === \"/\" &&\n              currentBlockComment\n            ) {\n              cursor++;\n              column += 2;\n              rangeIndex++;\n\n              currentBlockComment.loc.end.line = line;\n              currentBlockComment.loc.end.column = column;\n              currentBlockComment.range[1] = rangeIndex + 1;\n\n              blockComments.push(currentBlockComment);\n              currentBlockComment = undefined;\n\n              continue;\n            }\n\n            if (\n              currentChar === \"/\" &&\n              nextChar === \"/\" &&\n              quasi.value.cooked?.[cursor + 2] === \" \"\n            ) {\n              currentLineComment = {\n                type: AST_TOKEN_TYPES.Line,\n                value: \"\",\n                loc: {\n                  start: {\n                    column,\n                    line,\n                  },\n                  end: {\n                    column: 0,\n                    line: 0,\n                  },\n                },\n                range: [rangeIndex, 0],\n              };\n\n              cursor++;\n              column += 2;\n              rangeIndex++;\n              continue;\n            }\n\n            if (currentBlockComment) {\n              currentBlockComment.value += currentChar;\n            }\n\n            if (currentLineComment) {\n              currentLineComment.value += currentChar;\n            }\n\n            if (currentChar === \"\\n\") {\n              if (currentLineComment) {\n                currentLineComment.loc.end.line = line;\n                currentLineComment.loc.end.column = column;\n                currentLineComment.range[1] = rangeIndex;\n\n                lineComments.push(currentLineComment);\n\n                currentLineComment = undefined;\n              }\n\n              line++;\n              column = 0;\n            } else {\n              column++;\n            }\n          }\n        }\n\n        limitSingleLineComments(ruleContext, options, lineComments);\n        limitMultiLineComments(ruleContext, options, blockComments);\n      },\n    };\n  },\n});\n"],"names":["ESLintUtils","resolveDocsRoute","defaultOptions","reportMessages","optionsSchema","isIdentifier","AST_TOKEN_TYPES","limitSingleLineComments","limitMultiLineComments"],"mappings":";;;;;;;;;;AAkBA,MAAM,UAAA,GAAaA,iBAAA,CAAY,WAAA,CAAYC,iCAAgB,CAAA;AAEpD,MAAM,yCAAyC,UAAA,CAGpD;AAAA,EACA,IAAA,EAAM,wCAAA;AAAA,EACN,cAAA,EAAgB,CAAC,EAAE,GAAGC,8BAAA,CAAe,CAAC,CAAA,EAAG,IAAA,EAAM,CAAC,KAAK,CAAA,EAAG,CAAA;AAAA,EACxD,IAAA,EAAM;AAAA,IACJ,IAAA,EAAM,QAAA;AAAA,IACN,OAAA,EAAS,YAAA;AAAA,IACT,QAAA,EAAUC,+BAAA;AAAA,IACV,IAAA,EAAM;AAAA,MACJ,WAAA,EACE;AAAA,KACJ;AAAA,IACA,MAAA,EAAQ;AAAA,MACN;AAAA,QACE,GAAGC,6BAAA;AAAA,QACH,IAAA,EAAM,QAAA;AAAA,QACN,UAAA,EAAY;AAAA,UACV,GAAGA,6BAAA,CAAc,CAAC,CAAA,CAAE,UAAA;AAAA,UACpB,IAAA,EAAM,EAAE,IAAA,EAAM,OAAA,EAAS,OAAO,EAAE,IAAA,EAAM,UAAS;AAAE;AACnD;AACF;AACF,GACF;AAAA,EAEA,MAAA,EAAQ,CAAC,WAAA,EAAa,CAAC,OAAO,CAAA,KAAM;AAClC,IAAA,OAAO;AAAA,MACL,wBAAA,EAA0B,CAAC,IAAA,KAAS;AAClC,QAAA,IAAI,CAACC,qBAAA,CAAa,IAAA,CAAK,GAAG,CAAA,IAAK,CAAC,OAAA,CAAQ,IAAA,CAAK,QAAA,CAAS,IAAA,CAAK,GAAA,CAAI,IAAI,CAAA,EAAG;AACpE,UAAA;AAAA,QACF;AAEA,QAAA,MAAM,gBAAgB,EAAC;AACvB,QAAA,MAAM,eAAe,EAAC;AAEtB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