{"version":3,"file":"index.cjs","names":[],"sources":["../../../rules/unified-latex-lint-consistent-inline-math/index.ts"],"sourcesContent":["import { lintRule } from \"unified-lint-rule\";\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\";\n\ntype PluginOptions = { preferredStyle: \"tex\" | \"latex\" } | undefined;\n\nexport const DESCRIPTION = `## Lint Rule\n\nAvoid mixing TeX-style inline math \\`$...$\\` with LaTeX-style \\`\\\\(...\\\\)\\` inline math.\n`;\n\nexport const unifiedLatexLintConsistentInlineMath = lintRule<\n    Ast.Root,\n    PluginOptions\n>(\n    { origin: \"unified-latex-lint:consistent-inline-math\" },\n    (tree, file, options) => {\n        const inlineMath: Record<\"tex\" | \"latex\", Ast.Node[]> = {\n            tex: [],\n            latex: [],\n        };\n\n        visit(\n            tree,\n            (node) => {\n                if (node.type !== \"inlinemath\" || node.position == null) {\n                    return;\n                }\n                if (\n                    file.value &&\n                    file.value.slice(\n                        node.position.start.offset,\n                        node.position.start.offset + 1\n                    ) === \"$\"\n                ) {\n                    inlineMath.tex.push(node);\n                } else {\n                    inlineMath.latex.push(node);\n                }\n            },\n            { test: match.math }\n        );\n\n        if (options?.preferredStyle) {\n            // If a preferred style is specified, we only check for things not matching the preferred style.\n            if (options.preferredStyle === \"tex\") {\n                for (const node of inlineMath.latex) {\n                    file.message(\n                        `Prefer TeX-style $...$ inline math to LaTeX-style \\\\(...\\\\)`,\n                        node\n                    );\n                }\n            }\n            if (options.preferredStyle === \"latex\") {\n                for (const node of inlineMath.latex) {\n                    file.message(\n                        `Prefer LaTeX-style \\\\(...\\\\) inline math to LaTeX-style $...$`,\n                        node\n                    );\n                }\n            }\n        } else {\n            // If there's not preferred style, we prefer the most commonly used style of the document\n            const numTex = inlineMath.tex.length;\n            const numLatex = inlineMath.latex.length;\n            if (numTex > 0 && numLatex > 0) {\n                if (numLatex > numTex) {\n                    for (const node of inlineMath.tex) {\n                        file.message(\n                            `Inconsistent inline-math style. This document uses LaTeX-style \\\\(...\\\\) inline math more than TeX-style $...$ inline math`,\n                            node\n                        );\n                    }\n                } else {\n                    for (const node of inlineMath.latex) {\n                        file.message(\n                            `Inconsistent inline-math style. This document uses TeX-style $...$ inline math more than LaTeX-style \\\\(...\\\\) inline math`,\n                            node\n                        );\n                    }\n                }\n            }\n        }\n    }\n);\n"],"mappings":";;;;;AAOA,IAAa,cAAc;;;;AAK3B,IAAa,uCAAuC,YAAA,SAIhD,EAAE,QAAQ,6CAA6C,GACtD,MAAM,MAAM,YAAY;CACrB,MAAM,aAAkD;EACpD,KAAK,EAAE;EACP,OAAO,EAAE;EACZ;AAED,EAAA,GAAA,wCAAA,OACI,OACC,SAAS;AACN,MAAI,KAAK,SAAS,gBAAgB,KAAK,YAAY,KAC/C;AAEJ,MACI,KAAK,SACL,KAAK,MAAM,MACP,KAAK,SAAS,MAAM,QACpB,KAAK,SAAS,MAAM,SAAS,EAChC,KAAK,IAEN,YAAW,IAAI,KAAK,KAAK;MAEzB,YAAW,MAAM,KAAK,KAAK;IAGnC,EAAE,MAAM,wCAAA,MAAM,MAAM,CACvB;AAED,KAAI,SAAS,gBAAgB;AAEzB,MAAI,QAAQ,mBAAmB,MAC3B,MAAK,MAAM,QAAQ,WAAW,MAC1B,MAAK,QACD,+DACA,KACH;AAGT,MAAI,QAAQ,mBAAmB,QAC3B,MAAK,MAAM,QAAQ,WAAW,MAC1B,MAAK,QACD,iEACA,KACH;QAGN;EAEH,MAAM,SAAS,WAAW,IAAI;EAC9B,MAAM,WAAW,WAAW,MAAM;AAClC,MAAI,SAAS,KAAK,WAAW,EACzB,KAAI,WAAW,OACX,MAAK,MAAM,QAAQ,WAAW,IAC1B,MAAK,QACD,8HACA,KACH;MAGL,MAAK,MAAM,QAAQ,WAAW,MAC1B,MAAK,QACD,8HACA,KACH;;EAMxB"}