{"version":3,"file":"index.cjs","names":[],"sources":["../../../rules/unified-latex-lint-no-tex-font-shaping-commands/index.ts"],"sourcesContent":["import { lintRule } from \"unified-lint-rule\";\nimport { m } from \"@unified-latex/unified-latex-builder\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\nimport { replaceNodeDuringVisit } from \"@unified-latex/unified-latex-util-replace\";\n\nconst REPLACEMENTS: Record<string, string> = {\n    bf: \"bfseries\",\n    it: \"itshape\",\n    rm: \"rmfamily\",\n    sc: \"scshape\",\n    sf: \"sffamily\",\n    sl: \"slshape\",\n    tt: \"ttfamily\",\n};\n\nconst isReplaceable = match.createMacroMatcher(REPLACEMENTS);\n\ntype PluginOptions =\n    | {\n          /**\n           * Whether or not to fix the lint\n           *\n           * @type {boolean}\n           */\n          fix?: boolean;\n      }\n    | undefined;\n\nexport const DESCRIPTION = `## Lint Rule\n\nAvoid using TeX font changing commands like \\\\bf, \\\\it, etc. Prefer LaTeX \\\\bfseries, \\\\itshape, etc.. \n\nThis rule flags any usage of \\`${Object.keys(REPLACEMENTS)\n    .map((r) => printRaw(m(r)))\n    .join(\"` `\")}\\`\n\n### See\n\nCTAN l2tabuen Section 2.`;\n\nexport const unifiedLatexLintNoTexFontShapingCommands = lintRule<\n    Ast.Root,\n    PluginOptions\n>(\n    { origin: \"unified-latex-lint:no-tex-font-shaping-commands\" },\n    (tree, file, options) => {\n        visit(\n            tree,\n            (node, info) => {\n                const macroName = node.content;\n                file.message(\n                    `Replace \"${printRaw(node)}\" with \"${printRaw(\n                        m(REPLACEMENTS[macroName])\n                    )}\"`,\n                    node\n                );\n\n                if (options?.fix) {\n                    replaceNodeDuringVisit(m(REPLACEMENTS[macroName]), info);\n                }\n            },\n            { test: isReplaceable }\n        );\n    }\n);\n"],"mappings":";;;;;;;;AAQA,IAAM,eAAuC;CACzC,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACP;AAED,IAAM,gBAAgB,wCAAA,MAAM,mBAAmB,aAAa;AAa5D,IAAa,cAAc;;;;iCAIM,OAAO,KAAK,aAAa,CACrD,KAAK,OAAA,GAAA,4CAAA,WAAA,GAAA,qCAAA,GAAiB,EAAE,CAAC,CAAC,CAC1B,KAAK,MAAM,CAAC;;;;;AAMjB,IAAa,2CAA2C,YAAA,SAIpD,EAAE,QAAQ,mDAAmD,GAC5D,MAAM,MAAM,YAAY;AACrB,EAAA,GAAA,wCAAA,OACI,OACC,MAAM,SAAS;EACZ,MAAM,YAAY,KAAK;AACvB,OAAK,QACD,aAAA,GAAA,4CAAA,UAAqB,KAAK,CAAC,WAAA,GAAA,4CAAA,WAAA,GAAA,qCAAA,GACrB,aAAa,WAAW,CAC7B,CAAC,IACF,KACH;AAED,MAAI,SAAS,IACT,EAAA,GAAA,0CAAA,yBAAA,GAAA,qCAAA,GAAyB,aAAa,WAAW,EAAE,KAAK;IAGhE,EAAE,MAAM,eAAe,CAC1B;EAER"}