/** * Tailwind-aware rule matcher(P1a) * * rules.json の自動検出ルール(detectors.ts の capability 表で * autoDetectable=true と宣言された detector)を * Tailwind class string に対して適用するための共通 utility。 * check_rule と P1b の contract lint の双方が使う。 * * 旧実装(src/tools/check-rule.ts の cls.includes)の問題: * - "top-0" が pattern "p-0" (SPACE_NO_P0_CARDS) に誤検出される * - "hover:bg-blue-500" の variant prefix が剥がれず、prefix matcher の挙動が不安定 * * 新実装の方針: * - class token を Tailwind-aware に正規化(variant / important / arbitrary 対応) * - detector 別にマッチング規則を分離 * - tailwind-class: base との完全一致 * - tailwind-class-prefix: base の prefix 一致 */ import type { MatchSource } from "./detectors.js"; import type { MatchContext, RuleEntry } from "./types.js"; /** * Tailwind class string を MatchContext[] に正規化する。 * * 対応する変換: * - 通常 variant: "hover:bg-blue-500" → variants=["hover"], base="bg-blue-500" * - 複数 variant: "md:hover:bg-blue-500" → variants=["md","hover"], base="bg-blue-500" * - !important: "!text-black" → important=true, base="text-black" * - variant + !important: "md:!text-black" → variants=["md"], important=true, base="text-black" * - arbitrary variant: "[&>*]:p-0" → variants=["[&>*]"], base="p-0" * - arbitrary value: "space-x-[12px]" → base="space-x-[12px]" (variant にしない) */ export declare function tokenize(classString: string): MatchContext[]; /** * rule が ctx に対してマッチするか判定する。 * * - tailwind-class: base が pattern または matchPatterns のいずれかと完全一致 * - tailwind-class-prefix: base が pattern で始まる / matchPatterns と完全一致(+ /modifier)/ * prefixPatterns で始まる、のいずれか * - html-attr / manual: class matching では検出不可(false) */ /** * rule が matches() で自動検出可能か(= class 文字列マッチで判定できるか)の単一述語。 * * lint-core / check_rule(MCP) / getProhibitionRules / contract lint が * 各自で detector 名と pattern の有無を散在的に判定していたのを一本化する。 * detector を増やしたとき consumer 全体が追従するよう、判定はここ1箇所に集約する。 */ export declare function isAutoDetectable(rule: RuleEntry): boolean; /** * ルールを「実際に照合されるパターン文字列」の列へ展開する。 * * 展開規則は loader.getProhibitionRules の実装が正で、 * カバレッジ報告・legacy 互換レポートもここから数える * (かつて report 側が prefixPatterns を数えず、実数 65 に対し 44 と報告していた)。 */ export declare function expandRulePatterns(rule: RuleEntry): string[]; /** * rule が指定の pattern 系フィールドを実質的に持っているか。 * * 空文字は「持っていない」とみなす。matches() 側は `if (rule.pattern)` の * truthy 判定なので、pattern:"" を「有り」と数えると * 自動検査済みなのに永久に未検出(= passed:true)になる。 * 空文字宣言そのものは assertValidRules が不正として弾く。 */ export declare function hasMatchSource(rule: RuleEntry, field: MatchSource): boolean; /** * **フィールド併記時の実挙動(仕様として固定。tests/rule-diagnostics.spec.ts が回帰を守る)**: * - `prefixPatterns` は **ヒットしたときだけ** 判定を返す(外れたら次のフィールドへ進む = fallthrough) * - `matchPatterns` は **存在した時点で終端**(外れても false を返し、pattern は読まれない = short-circuit) * - `pattern` は matchPatterns が無いときにだけ読まれる * * この非対称は capability 表の matchSources の並び順だけでは表現できない。 * 「どのフィールドが必須か」ごと再定義するのは S1+S2 * (internal/phase2-plan.md の §S1+S2 に記録した三重不整合を参照)。 */ export declare function matches(rule: RuleEntry, ctx: MatchContext): boolean;