{"version":3,"file":"index.cjs","names":[],"sources":["../../../rules/unified-latex-lint-prefer-setlength/index.ts"],"sourcesContent":["import { lintRule } from \"unified-lint-rule\";\nimport { arg, m } from \"@unified-latex/unified-latex-builder\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { extractFormattedGlue } from \"@unified-latex/unified-latex-util-glue\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\nimport { scan } from \"@unified-latex/unified-latex-util-scan\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\n\nconst LENGTH_MACROS = [\n    \"abovecaptionskip\",\n    \"arraycolsep\",\n    \"arrayrulewidth\",\n    \"belowcaptionskip\",\n    \"captionindent\",\n    \"columnsep\",\n    \"columnseprule\",\n    \"doublerulsep\",\n    \"fboxrule\",\n    \"fboxsep\",\n    \"itemsep\",\n    \"itemindent\",\n    \"labelsep\",\n    \"labelwidth\",\n    \"leftmargin\",\n    \"leftmargini\",\n    \"leftmarginii\",\n    \"leftmarginiii\",\n    \"leftmarginiv\",\n    \"leftmarginv\",\n    \"leftmarginvi\",\n    \"lineskip\",\n    \"linewidth\",\n    \"listparindent\",\n    \"marginparsep\",\n    \"marginparwidth\",\n    \"@mpfootins\",\n    \"normallineskip\",\n    \"overfullrule\",\n    \"paperwidth\",\n    \"paperheight\",\n    \"parsep\",\n    \"partopsep\",\n    \"parskip\",\n    \"parindent\",\n    \"parfillskip\",\n    \"tabbingsep\",\n    \"tabcolsep\",\n];\n\nconst isLengthMacro = match.createMacroMatcher(LENGTH_MACROS);\n\ntype PluginOptions = { fix?: boolean } | undefined;\n\nexport const DESCRIPTION = `## Lint Rule\n\nAvoid using TeX-style \\`\\\\parskip=1em\\` length assignments and instead\nuse LaTeX-style \\`\\\\setlength{\\\\parskip}{1em}\\`.\n\n### See\n\nCTAN l2tabuen Section 1.5\n`;\n\nexport const unifiedLatexLintPreferSetlength = lintRule<\n    Ast.Root,\n    PluginOptions\n>({ origin: \"unified-latex-lint:prefer-setlength\" }, (tree, file, options) => {\n    visit(\n        tree,\n        (node, info) => {\n            if (info.index == null) {\n                return;\n            }\n            const containingArray = info.containingArray;\n            if (!containingArray) {\n                return;\n            }\n            const equalsIndex = scan(containingArray, \"=\", {\n                startIndex: info.index + 1,\n                onlySkipWhitespaceAndComments: true,\n            });\n            if (equalsIndex == null) {\n                return;\n            }\n\n            // If we made it here, there was a length macro that was followed by an equals sign\n            file.message(\n                `TeX-style assignment to length \\`${printRaw(\n                    node\n                )}\\`; prefer LaTeX \\`\\\\setlength{${printRaw(node)}}{...}\\``,\n                node\n            );\n\n            if (options?.fix) {\n                const glue = extractFormattedGlue(\n                    containingArray,\n                    equalsIndex + 1\n                );\n                if (!glue) {\n                    console.warn(\n                        \"Expected to find glue following `=` but couldn't\"\n                    );\n                    return;\n                }\n                const numReplacements = glue.span.end - info.index + 1;\n                // splice our fancy glue in!\n                containingArray.splice(\n                    info.index,\n                    numReplacements,\n                    ...[\n                        m(\"setlength\", [arg(node), arg(glue.glue)]),\n                        ...glue.trailingStrings,\n                    ]\n                );\n                return info.index + 1;\n            }\n        },\n        { test: isLengthMacro }\n    );\n});\n"],"mappings":";;;;;;;;;AAkDA,IAAM,gBAAgB,wCAAA,MAAM,mBAzCN;CAClB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACH,CAE4D;AAI7D,IAAa,cAAc;;;;;;;;;AAU3B,IAAa,kCAAkC,YAAA,SAG7C,EAAE,QAAQ,uCAAuC,GAAG,MAAM,MAAM,YAAY;AAC1E,EAAA,GAAA,wCAAA,OACI,OACC,MAAM,SAAS;AACZ,MAAI,KAAK,SAAS,KACd;EAEJ,MAAM,kBAAkB,KAAK;AAC7B,MAAI,CAAC,gBACD;EAEJ,MAAM,eAAA,GAAA,uCAAA,MAAmB,iBAAiB,KAAK;GAC3C,YAAY,KAAK,QAAQ;GACzB,+BAA+B;GAClC,CAAC;AACF,MAAI,eAAe,KACf;AAIJ,OAAK,QACD,qCAAA,GAAA,4CAAA,UACI,KACH,CAAC,kCAAA,GAAA,4CAAA,UAA0C,KAAK,CAAC,WAClD,KACH;AAED,MAAI,SAAS,KAAK;GACd,MAAM,QAAA,GAAA,uCAAA,sBACF,iBACA,cAAc,EACjB;AACD,OAAI,CAAC,MAAM;AACP,YAAQ,KACJ,mDACH;AACD;;GAEJ,MAAM,kBAAkB,KAAK,KAAK,MAAM,KAAK,QAAQ;AAErD,mBAAgB,OACZ,KAAK,OACL,iBACA,GAAG,EAAA,GAAA,qCAAA,GACG,aAAa,EAAA,GAAA,qCAAA,KAAK,KAAK,GAAA,GAAA,qCAAA,KAAM,KAAK,KAAK,CAAC,CAAC,EAC3C,GAAG,KAAK,gBACX,CACJ;AACD,UAAO,KAAK,QAAQ;;IAG5B,EAAE,MAAM,eAAe,CAC1B;EACH"}