@kashi-ui/eslint-plugin 0.0.0-stage → 2.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,112 @@
1
+ import { logicalProperty, logicalValue } from "@kashi-ui/persian";
2
+ import { DOCS, metaMessages, reporter, settings } from "../util.js";
3
+ const MESSAGES = {
4
+ property: [
5
+ "{{found}} فیزیکی است و در صفحهٔ چپ‌به‌راست جای اشتباه می‌نشیند؛ {{replacement}} بنویسید",
6
+ "{{found}} is physical and lands on the wrong side when direction flips; use {{replacement}}",
7
+ ],
8
+ value: ["{{prop}}: \"{{found}}\" فیزیکی است؛ \"{{replacement}}\" بنویسید", "{{prop}}: \"{{found}}\" is physical; use \"{{replacement}}\""],
9
+ direction: [
10
+ "direction در style؛ جهت را با attribute dir روی عنصر بدهید تا صفحه‌خوان و مرورگر هم بدانند",
11
+ "direction in style; set the dir attribute on the element instead so assistive tech and the browser know it",
12
+ ],
13
+ };
14
+ function keyName(p) {
15
+ if (p.type !== "Property" || p.computed)
16
+ return null;
17
+ if (p.key.type === "Identifier")
18
+ return p.key.name;
19
+ if (p.key.type === "Literal" && typeof p.key.value === "string")
20
+ return p.key.value;
21
+ return null;
22
+ }
23
+ const isLiteral = (n) => n?.type === "Literal" || (n?.type === "TemplateLiteral" && n.expressions.length === 0) || (n?.type === "UnaryExpression" && n.argument?.type === "Literal");
24
+ const strValue = (n) => n?.type === "Literal" ? String(n.value) : n?.type === "TemplateLiteral" && n.expressions.length === 0 ? n.quasis[0].value.cooked : null;
25
+ export const noPhysicalStyle = {
26
+ meta: {
27
+ type: "suggestion",
28
+ fixable: "code",
29
+ docs: {
30
+ description: "Use logical properties in inline styles (marginInlineStart, not marginLeft)",
31
+ descriptionFa: "style درون‌خطی با خاصیت فیزیکی (marginLeft، paddingRight، left، textAlign: \"left\"، float) ← معادل منطقی؛ و direction در style ← attribute dir.",
32
+ recommended: true,
33
+ url: `${DOCS}#no-physical-style`,
34
+ },
35
+ schema: [
36
+ {
37
+ type: "object",
38
+ properties: {
39
+ attributes: { type: "array", items: { type: "string" }, description: "attributeهای style (پیش‌فرض: style)" },
40
+ ignoreComputedPosition: { type: "boolean", description: "left/right با مقدار محاسبه‌شده (مختصات اندازه‌گیری‌شده با JS) نادیده گرفته شود؛ پیش‌فرض true" },
41
+ },
42
+ additionalProperties: false,
43
+ },
44
+ ],
45
+ messages: metaMessages(MESSAGES),
46
+ },
47
+ create(context) {
48
+ const opts = (context.options[0] ?? {});
49
+ const attributes = new Set(opts.attributes ?? ["style"]);
50
+ const ignoreComputed = opts.ignoreComputedPosition ?? true;
51
+ const projectDir = settings(context).direction ?? "rtl";
52
+ const report = reporter(context, MESSAGES);
53
+ const source = context.sourceCode;
54
+ const check = (obj, elementDir) => {
55
+ const props = obj.properties.filter((p) => keyName(p) !== null);
56
+ const valueOf = (name) => strValue(props.find((p) => keyName(p) === name)?.value);
57
+ // جهتِ خود عنصر (dir="ltr" یا direction در همین style) بر جهت پروژه مقدم است: left در عنصر ltr یعنی start
58
+ const own = elementDir ?? valueOf("direction");
59
+ const dir = own === "ltr" || own === "rtl" ? own : projectDir;
60
+ // left: 50% + translate(-50%) یعنی وسط‌چین، که به جهت ربطی ندارد
61
+ const transform = `${valueOf("transform") ?? ""} ${valueOf("translate") ?? ""}`;
62
+ const centered = /translate(X|3d)?\(\s*-50%|^\s*-50%/.test(transform.trim()) || /(^|\s)-50%/.test(valueOf("translate") ?? "");
63
+ for (const p of props) {
64
+ const name = keyName(p);
65
+ if (name === "direction" && isLiteral(p.value)) {
66
+ report({ node: p, messageId: "direction" });
67
+ continue;
68
+ }
69
+ const kebabOut = logicalProperty(name, dir);
70
+ // در style شیء React همه‌چیز camelCase است، حتی left ← insetInlineEnd
71
+ const logical = kebabOut && !name.includes("-") ? kebabOut.replace(/-([a-z])/g, (_, c) => c.toUpperCase()) : kebabOut;
72
+ if (logical) {
73
+ if ((name === "left" || name === "right") && ((ignoreComputed && !isLiteral(p.value)) || (centered && strValue(p.value) === "50%")))
74
+ continue;
75
+ const keyText = source.getText(p.key);
76
+ const quote = p.key.type === "Literal" ? keyText[0] : "";
77
+ const newKey = quote ? `${quote}${logical}${quote}` : /-/.test(logical) ? `"${logical}"` : logical;
78
+ report({
79
+ node: p.key,
80
+ messageId: "property",
81
+ data: { found: name, replacement: logical },
82
+ fix: (f) => (p.shorthand ? f.replaceText(p, `${newKey}: ${keyText}`) : f.replaceText(p.key, newKey)),
83
+ });
84
+ continue;
85
+ }
86
+ const v = strValue(p.value);
87
+ if (v !== null) {
88
+ const lv = logicalValue(name, v, dir);
89
+ if (lv) {
90
+ const raw = source.getText(p.value);
91
+ report({ node: p.value, messageId: "value", data: { prop: name, found: v, replacement: lv }, fix: (f) => f.replaceText(p.value, raw[0] + lv + raw[raw.length - 1]) });
92
+ }
93
+ }
94
+ }
95
+ };
96
+ return {
97
+ JSXAttribute(node) {
98
+ const name = node.name?.type === "JSXIdentifier" ? node.name.name : null;
99
+ if (!name || !attributes.has(name))
100
+ return;
101
+ let expr = node.value?.type === "JSXExpressionContainer" ? node.value.expression : null;
102
+ while (expr && (expr.type === "TSAsExpression" || expr.type === "TSSatisfiesExpression"))
103
+ expr = expr.expression;
104
+ if (expr?.type !== "ObjectExpression")
105
+ return;
106
+ const dirAttr = node.parent?.attributes?.find((a) => a.type === "JSXAttribute" && a.name?.name === "dir");
107
+ const elementDir = dirAttr?.value?.type === "Literal" && typeof dirAttr.value.value === "string" ? dirAttr.value.value.toLowerCase() : null;
108
+ check(expr, elementDir);
109
+ },
110
+ };
111
+ },
112
+ };
@@ -0,0 +1,60 @@
1
+ import type { Rule } from "eslint";
2
+ /**
3
+ * هر نوع اعتبارسنجی دستی و ابزار جایگزینش در @kashi-ui/persian و @kashi-ui/schemas.
4
+ * test/sync.test.mjs بررسی می‌کند همهٔ این ابزارها واقعاً از @kashi-ui/persian صادر می‌شوند،
5
+ * و هر اعتبارسنج تازهٔ isValid* در آن پکیج یا این‌جا آمده یا در فهرست UNCOVERED آن تست است.
6
+ */
7
+ export declare const VALIDATORS: {
8
+ readonly mobile: {
9
+ readonly tool: "isValidMobile / normalizeMobile";
10
+ readonly schema: "iranMobile()";
11
+ readonly context: RegExp;
12
+ };
13
+ readonly nationalId: {
14
+ readonly tool: "isValidNationalId";
15
+ readonly schema: "nationalId()";
16
+ readonly context: RegExp;
17
+ };
18
+ readonly card: {
19
+ readonly tool: "isValidCardNumber";
20
+ readonly schema: "cardNumber()";
21
+ readonly context: RegExp;
22
+ };
23
+ readonly iban: {
24
+ readonly tool: "isValidIban";
25
+ readonly schema: "iban()";
26
+ readonly context: RegExp;
27
+ };
28
+ readonly postal: {
29
+ readonly tool: "isValidPostalCode";
30
+ readonly schema: "postalCode()";
31
+ readonly context: RegExp;
32
+ };
33
+ readonly landline: {
34
+ readonly tool: "isValidLandline";
35
+ readonly schema: "landline()";
36
+ readonly context: RegExp;
37
+ };
38
+ readonly legalId: {
39
+ readonly tool: "isValidLegalId";
40
+ readonly schema: "legalId()";
41
+ readonly context: RegExp;
42
+ };
43
+ readonly sayad: {
44
+ readonly tool: "isValidSayad";
45
+ readonly schema: "sayad()";
46
+ readonly context: RegExp;
47
+ };
48
+ };
49
+ export declare const HELPERS: {
50
+ readonly toEnDigits: "toEnDigits";
51
+ readonly toFaDigits: "toFaDigits";
52
+ readonly normalizePersian: "normalizePersian";
53
+ };
54
+ export declare function classifyPattern(pattern: string, near: string): keyof typeof VALIDATORS | null;
55
+ export declare const preferKashiValidators: Rule.RuleModule;
56
+ /** همهٔ نام‌هایی که پیام‌ها پیشنهاد می‌دهند؛ test/sync.test.mjs بررسی می‌کند در @kashi-ui/persian و @kashi-ui/schemas هستند */
57
+ export declare const SUGGESTED_TOOLS: {
58
+ persian: string[];
59
+ schemas: string[];
60
+ };
@@ -0,0 +1,169 @@
1
+ import { DOCS, metaMessages, reporter } from "../util.js";
2
+ /**
3
+ * هر نوع اعتبارسنجی دستی و ابزار جایگزینش در @kashi-ui/persian و @kashi-ui/schemas.
4
+ * test/sync.test.mjs بررسی می‌کند همهٔ این ابزارها واقعاً از @kashi-ui/persian صادر می‌شوند،
5
+ * و هر اعتبارسنج تازهٔ isValid* در آن پکیج یا این‌جا آمده یا در فهرست UNCOVERED آن تست است.
6
+ */
7
+ export const VALIDATORS = {
8
+ mobile: { tool: "isValidMobile / normalizeMobile", schema: "iranMobile()", context: /mobile|cell|phone|tel|mob|موبایل|همراه/i },
9
+ nationalId: { tool: "isValidNationalId", schema: "nationalId()", context: /national|melli|meli|code_?melli|nid|ssn|کدملی|کد_ملی/i },
10
+ card: { tool: "isValidCardNumber", schema: "cardNumber()", context: /card|pan|کارت/i },
11
+ iban: { tool: "isValidIban", schema: "iban()", context: /iban|sheba|shaba|شبا/i },
12
+ postal: { tool: "isValidPostalCode", schema: "postalCode()", context: /postal|post_?code|zip|کدپستی|کد_پستی/i },
13
+ landline: { tool: "isValidLandline", schema: "landline()", context: /landline|tel|phone|تلفن/i },
14
+ legalId: { tool: "isValidLegalId", schema: "legalId()", context: /legal|shenase|شناسه_?ملی/i },
15
+ sayad: { tool: "isValidSayad", schema: "sayad()", context: /sayad|cheque|check_?id|صیاد|چک/i },
16
+ };
17
+ export const HELPERS = {
18
+ toEnDigits: "toEnDigits",
19
+ toFaDigits: "toFaDigits",
20
+ normalizePersian: "normalizePersian",
21
+ };
22
+ const MESSAGES = {
23
+ validator: [
24
+ "اعتبارسنجی دستی {{what}} با regex؛ regex رقم کنترل را نمی‌سنجد و ارقام فارسی را رد می‌کند. از {{tool}} در @kashi-ui/persian (یا {{schema}} در @kashi-ui/schemas) استفاده کنید",
25
+ "Hand-written {{what}} regex; it doesn't verify the checksum and rejects Persian digits. Use {{tool}} from @kashi-ui/persian (or {{schema}} from @kashi-ui/schemas)",
26
+ ],
27
+ helper: [
28
+ "تبدیل دستی {{what}}؛ {{tool}} از @kashi-ui/persian همین کار را با همهٔ حالت‌ها (ارقام عربی، «ى»، «ة»…) می‌کند",
29
+ "Hand-written {{what}} conversion; {{tool}} from @kashi-ui/persian handles every case (Arabic digits, «ى», «ة»…)",
30
+ ],
31
+ };
32
+ const WHAT = {
33
+ mobile: ["شمارهٔ موبایل", "mobile number"],
34
+ nationalId: ["کد ملی", "national ID"],
35
+ card: ["شمارهٔ کارت", "card number"],
36
+ iban: ["شبا", "IBAN (Sheba)"],
37
+ postal: ["کد پستی", "postal code"],
38
+ landline: ["تلفن ثابت", "landline number"],
39
+ legalId: ["شناسهٔ ملی", "legal ID"],
40
+ sayad: ["شناسهٔ صیادی", "Sayad cheque ID"],
41
+ toEnDigits: ["ارقام فارسی به لاتین", "Persian digits to Latin"],
42
+ toFaDigits: ["ارقام لاتین به فارسی", "Latin digits to Persian"],
43
+ normalizePersian: ["«ي/ك» عربی به فارسی", "Arabic Yeh/Kaf to Persian"],
44
+ };
45
+ /** الگوی regex را برای مقایسه یکدست می‌کند: [0-9] ← \d، [۰-۹0-9] ← \d */
46
+ function canon(pattern) {
47
+ return pattern
48
+ .replace(/\[0-9\]|\[\\d\]|\[۰-۹0-9\]|\[0-9۰-۹\]|\[\\d۰-۹\]|\[۰-۹\\d\]/g, "\\d")
49
+ .replace(/\\u06[fF]0-\\u06[fF]9/g, "۰-۹");
50
+ }
51
+ function nameNear(node) {
52
+ const names = [];
53
+ for (let p = node.parent, depth = 0; p && depth < 6; p = p.parent, depth++) {
54
+ if (p.type === "VariableDeclarator" && p.id.type === "Identifier")
55
+ names.push(p.id.name);
56
+ if ((p.type === "Property" || p.type === "PropertyDefinition") && p.key?.type === "Identifier")
57
+ names.push(p.key.name);
58
+ if (p.type === "AssignmentExpression" && p.left.type === "Identifier")
59
+ names.push(p.left.name);
60
+ if (p.type === "AssignmentExpression" && p.left.type === "MemberExpression" && p.left.property.type === "Identifier")
61
+ names.push(p.left.property.name);
62
+ if ((p.type === "FunctionDeclaration" || p.type === "FunctionExpression") && p.id)
63
+ names.push(p.id.name);
64
+ if (p.type === "JSXAttribute")
65
+ names.push(String(p.name?.name ?? ""));
66
+ if (p.type === "CallExpression") {
67
+ // re.test(nationalId)
68
+ for (const a of p.arguments) {
69
+ if (a.type === "Identifier")
70
+ names.push(a.name);
71
+ if (a.type === "MemberExpression" && a.property.type === "Identifier")
72
+ names.push(a.property.name);
73
+ }
74
+ }
75
+ }
76
+ return names.join(" ");
77
+ }
78
+ export function classifyPattern(pattern, near) {
79
+ const p = canon(pattern);
80
+ if (/IR\\d\{24\}|IR\[?\\d|\[Ii\]\[Rr\]/.test(p) && /24/.test(p))
81
+ return "iban";
82
+ if (/(^|[^\d])0?9\\d\{9\}|09\\d\{9\}|\(\?:\\\+98\|0\)|\\\+98|\(\\\+98\||0098|\(0\|\\\+98\)|9\[0-9\]\{9\}|09\[0-9\]/.test(p))
83
+ return "mobile";
84
+ if (/\\d\{16\}|\\d\{4\}[-\s\\s?\[\]]*[?]?\\d\{4\}[-\s\\s?\[\]]*[?]?\\d\{4\}/.test(p))
85
+ return VALIDATORS.card.context.test(near) ? "card" : null;
86
+ const ten = /\\d\{10\}|\\d\{5\}-\?\\d\{5\}|\\d\{5\}\[-\s\]\?\\d\{5\}/.test(p);
87
+ if (ten) {
88
+ if (VALIDATORS.postal.context.test(near))
89
+ return "postal";
90
+ if (VALIDATORS.nationalId.context.test(near))
91
+ return "nationalId";
92
+ }
93
+ if (/\\d\{11\}/.test(p)) {
94
+ if (VALIDATORS.legalId.context.test(near))
95
+ return "legalId";
96
+ if (VALIDATORS.landline.context.test(near))
97
+ return "landline";
98
+ }
99
+ if (/\\d\{16\}/.test(p) && VALIDATORS.sayad.context.test(near))
100
+ return "sayad";
101
+ return null;
102
+ }
103
+ const PERSIAN_DIGIT_CLASS = /^\[(?:۰-۹|٠-٩|۰-۹٠-٩|٠-٩۰-۹|\\u06[fF]0-\\u06[fF]9|\\u0660-\\u0669)+\]$/;
104
+ export const preferKashiValidators = {
105
+ meta: {
106
+ type: "suggestion",
107
+ docs: {
108
+ description: "Prefer @kashi-ui/persian validators and helpers over hand-written regexes for Iranian data",
109
+ descriptionFa: "regex دستی برای موبایل، کد ملی، کارت، شبا، کد پستی… یا تبدیل دستی ارقام و «ي/ك» ← ابزار آمادهٔ @kashi-ui/persian (که رقم کنترل را هم می‌سنجد).",
110
+ recommended: false,
111
+ url: `${DOCS}#prefer-kashi-validators`,
112
+ },
113
+ schema: [],
114
+ messages: metaMessages(MESSAGES),
115
+ },
116
+ create(context) {
117
+ const report = reporter(context, MESSAGES);
118
+ const reported = new WeakSet();
119
+ const fa = (k) => WHAT[k][0];
120
+ const en = (k) => WHAT[k][1];
121
+ const validator = (node, pattern) => {
122
+ const kind = classifyPattern(pattern, nameNear(node));
123
+ if (!kind || reported.has(node))
124
+ return;
125
+ reported.add(node);
126
+ const v = VALIDATORS[kind];
127
+ report({ node, messageId: "validator", data: { what: `${fa(kind)} / ${en(kind)}`, tool: v.tool, schema: v.schema } });
128
+ };
129
+ const helper = (node, kind) => {
130
+ if (reported.has(node))
131
+ return;
132
+ reported.add(node);
133
+ report({ node, messageId: "helper", data: { what: `${fa(kind)} / ${en(kind)}`, tool: HELPERS[kind] } });
134
+ };
135
+ return {
136
+ Literal(node) {
137
+ if (node.regex)
138
+ validator(node, node.regex.pattern);
139
+ },
140
+ "NewExpression, CallExpression"(node) {
141
+ if (node.callee.type === "Identifier" && node.callee.name === "RegExp" && node.arguments[0]?.type === "Literal" && typeof node.arguments[0].value === "string") {
142
+ validator(node, node.arguments[0].value);
143
+ return;
144
+ }
145
+ // s.replace(/[۰-۹]/g, …) یا s.replace(/ي/g, "ی")
146
+ const callee = node.callee;
147
+ if (callee.type !== "MemberExpression" || !["replace", "replaceAll"].includes(callee.property?.name))
148
+ return;
149
+ const first = node.arguments[0];
150
+ const second = node.arguments[1];
151
+ const pat = first?.regex ? first.regex.pattern : typeof first?.value === "string" ? first.value : null;
152
+ if (pat === null)
153
+ return;
154
+ const secondText = second ? context.sourceCode.getText(second) : "";
155
+ if (/^\[?[يىك]+\]?$|^\[?ي\]?$|^ك$/.test(pat))
156
+ return helper(node, "normalizePersian");
157
+ if (PERSIAN_DIGIT_CLASS.test(pat))
158
+ return helper(node, "toEnDigits");
159
+ if (/^(\\d|\[0-9\])$/.test(pat) && /۰|1776|0x6f0|06f0|\\u06f0/i.test(secondText))
160
+ return helper(node, "toFaDigits");
161
+ },
162
+ };
163
+ },
164
+ };
165
+ /** همهٔ نام‌هایی که پیام‌ها پیشنهاد می‌دهند؛ test/sync.test.mjs بررسی می‌کند در @kashi-ui/persian و @kashi-ui/schemas هستند */
166
+ export const SUGGESTED_TOOLS = {
167
+ persian: [...Object.values(VALIDATORS).flatMap((v) => v.tool.split(" / ")), ...Object.values(HELPERS)],
168
+ schemas: Object.values(VALIDATORS).map((v) => v.schema.replace("()", "")),
169
+ };
@@ -0,0 +1,14 @@
1
+ import type { Rule } from "eslint";
2
+ import type { AnyNode } from "../text.js";
3
+ export interface ClassString {
4
+ node: AnyNode;
5
+ /** جای شروع متن در کد */
6
+ start: number;
7
+ text: string;
8
+ }
9
+ /** همهٔ رشته‌های کلاس فایل: attribute کلاس، و آرگومان cn/clsx/cva/… (شامل شرط‌ها، آرایه‌ها، کلید و مقدار شیء) */
10
+ export declare function classStringVisitors(context: Rule.RuleContext, options: {
11
+ callees?: string[];
12
+ attributes?: string;
13
+ }, onString: (s: ClassString, owner: AnyNode) => void): Rule.RuleListener;
14
+ export declare const tailwindLogical: Rule.RuleModule;
@@ -0,0 +1,171 @@
1
+ import { logicalTailwindClass, splitTailwindClass } from "@kashi-ui/persian";
2
+ import { DOCS, metaMessages, reporter, settings, tailwindVersion } from "../util.js";
3
+ const MESSAGES = {
4
+ physical: [
5
+ "کلاس فیزیکی «{{found}}»؛ در جهت مخالف سمت اشتباه می‌نشیند. «{{replacement}}» بنویسید",
6
+ "Physical class “{{found}}” lands on the wrong side when direction flips; use “{{replacement}}”",
7
+ ],
8
+ removed: [
9
+ "«{{found}}» در Tailwind ۴٫۳ حذف شده و هیچ CSSی نمی‌سازد؛ «{{replacement}}» بنویسید",
10
+ "“{{found}}” was removed in Tailwind 4.3 and generates no CSS; use “{{replacement}}”",
11
+ ],
12
+ translate: [
13
+ "«{{found}}» در صفحهٔ راست‌به‌چپ به سمت اشتباه حرکت می‌کند؛ برای rtl قرینه‌اش را هم بگذارید (مثل rtl:{{mirror}})",
14
+ "“{{found}}” moves the wrong way in right-to-left pages; add the mirrored class for rtl (e.g. rtl:{{mirror}})",
15
+ ],
16
+ spaceX: [
17
+ "«{{found}}» در Tailwind 3 با margin-left کار می‌کند و در صفحهٔ راست‌به‌چپ فاصله را سمت اشتباه می‌گذارد؛ gap-x یا rtl:space-x-reverse",
18
+ "“{{found}}” uses margin-left in Tailwind 3 and puts the space on the wrong side in RTL; use gap-x or rtl:space-x-reverse",
19
+ ],
20
+ };
21
+ const DEFAULT_CALLEES = ["cn", "clsx", "classnames", "classNames", "cx", "twMerge", "twJoin", "cva", "tv", "ctl", "tw", "twc", "classList"];
22
+ const DEFAULT_ATTRIBUTES = "^(class|className|class:list|[a-zA-Z]+ClassName)$";
23
+ /** همهٔ رشته‌های کلاس فایل: attribute کلاس، و آرگومان cn/clsx/cva/… (شامل شرط‌ها، آرایه‌ها، کلید و مقدار شیء) */
24
+ export function classStringVisitors(context, options, onString) {
25
+ const callees = new Set(options.callees ?? DEFAULT_CALLEES);
26
+ const attrRe = new RegExp(options.attributes ?? DEFAULT_ATTRIBUTES);
27
+ const text = context.sourceCode.text;
28
+ const walk = (n, owner, depth = 0) => {
29
+ if (!n || depth > 8)
30
+ return;
31
+ switch (n.type) {
32
+ case "Literal":
33
+ if (typeof n.value === "string")
34
+ onString({ node: n, start: n.range[0] + 1, text: text.slice(n.range[0] + 1, n.range[1] - 1) }, owner);
35
+ return;
36
+ case "TemplateLiteral":
37
+ for (const q of n.quasis)
38
+ onString({ node: q, start: q.range[0] + 1, text: text.slice(q.range[0] + 1, q.range[1] - (q.tail ? 1 : 2)) }, owner);
39
+ for (const e of n.expressions)
40
+ walk(e, owner, depth + 1);
41
+ return;
42
+ case "JSXExpressionContainer":
43
+ return walk(n.expression, owner, depth + 1);
44
+ case "ConditionalExpression":
45
+ walk(n.consequent, owner, depth + 1);
46
+ return walk(n.alternate, owner, depth + 1);
47
+ case "LogicalExpression":
48
+ return walk(n.right, owner, depth + 1);
49
+ case "ArrayExpression":
50
+ for (const e of n.elements)
51
+ walk(e, owner, depth + 1);
52
+ return;
53
+ case "ObjectExpression":
54
+ for (const p of n.properties) {
55
+ if (p.type !== "Property")
56
+ continue;
57
+ if (!p.computed && p.key.type === "Literal")
58
+ walk(p.key, owner, depth + 1);
59
+ walk(p.value, owner, depth + 1);
60
+ }
61
+ return;
62
+ case "CallExpression":
63
+ if (n.callee.type === "Identifier" && callees.has(n.callee.name))
64
+ for (const a of n.arguments)
65
+ walk(a, owner, depth + 1);
66
+ return;
67
+ case "TSAsExpression":
68
+ case "TSSatisfiesExpression":
69
+ return walk(n.expression, owner, depth + 1);
70
+ }
71
+ };
72
+ return {
73
+ JSXAttribute(node) {
74
+ const name = node.name?.type === "JSXNamespacedName" ? `${node.name.namespace.name}:${node.name.name.name}` : node.name?.name;
75
+ if (typeof name === "string" && attrRe.test(name))
76
+ walk(node.value, node.parent);
77
+ },
78
+ CallExpression(node) {
79
+ // فقط فراخوانی بیرونی؛ cn داخل className از مسیر JSXAttribute دیده می‌شود
80
+ if (node.callee.type !== "Identifier" || !callees.has(node.callee.name))
81
+ return;
82
+ let p = node.parent;
83
+ while (p && p.type !== "JSXAttribute" && p.type !== "Program") {
84
+ if (p.type === "CallExpression" && p.callee.type === "Identifier" && callees.has(p.callee.name))
85
+ return;
86
+ p = p.parent;
87
+ }
88
+ if (p?.type === "JSXAttribute")
89
+ return;
90
+ for (const a of node.arguments)
91
+ walk(a, node);
92
+ },
93
+ };
94
+ }
95
+ const mirrorTranslate = (base) => (base.startsWith("-") ? base.slice(1) : "-" + base);
96
+ export const tailwindLogical = {
97
+ meta: {
98
+ type: "suggestion",
99
+ fixable: "code",
100
+ docs: {
101
+ description: "Use logical Tailwind classes (ms-, pe-, inset-s-, text-start, rounded-s…) instead of physical ones",
102
+ descriptionFa: "کلاس‌های فیزیکی Tailwind (ml-، pr-، left-، text-right، rounded-l، border-r، float-left…) ← معادل منطقی (ms-، pe-، inset-s-، text-start…)؛ translate-x بدون قرینهٔ rtl؛ و در Tailwind 3، space-x.",
103
+ recommended: true,
104
+ url: `${DOCS}#tailwind-logical`,
105
+ },
106
+ schema: [
107
+ {
108
+ type: "object",
109
+ properties: {
110
+ callees: { type: "array", items: { type: "string" } },
111
+ attributes: { type: "string", description: "regex نام attributeهای کلاس" },
112
+ translate: { type: "boolean", description: "گزارش translate-x بدون قرینهٔ rtl؛ پیش‌فرض true" },
113
+ },
114
+ additionalProperties: false,
115
+ },
116
+ ],
117
+ messages: metaMessages(MESSAGES),
118
+ },
119
+ create(context) {
120
+ const opts = (context.options[0] ?? {});
121
+ const s = settings(context);
122
+ const dir = s.direction ?? "rtl";
123
+ const prefix = s.tailwind?.prefix ?? "";
124
+ const version = tailwindVersion(context);
125
+ // start-*/end-* از 3.3 تا 4.2؛ inset-s-*/inset-e-* از 4.2؛ start-* در 4.3 حذف شد
126
+ const modern = !version || version[0] > 4 || (version[0] === 4 && version[1] >= 2);
127
+ const removedStart = !!version && (version[0] > 4 || (version[0] === 4 && version[1] >= 3));
128
+ const v3 = !!version && version[0] === 3;
129
+ const report = reporter(context, MESSAGES);
130
+ return classStringVisitors(context, opts, (str) => {
131
+ const classes = [...str.text.matchAll(/\S+/g)];
132
+ const names = classes.map((m) => m[0]);
133
+ // کسی که خودش rtl:/ltr: نوشته جهت را دستی مدیریت می‌کند
134
+ const manual = names.some((c) => /(^|:)(rtl|ltr):/.test(c) || /(^|:)\[dir=/.test(c));
135
+ const bases = names.map((c) => splitTailwindClass(c));
136
+ const centerX = bases.some((b) => b.negative && /^translate-x-1\/2$/.test(b.base)) || bases.some((b) => !b.negative && b.base === "translate-x-1/2");
137
+ for (let k = 0; k < classes.length; k++) {
138
+ const cls = names[k];
139
+ const at = str.start + classes[k].index;
140
+ const range = [at, at + cls.length];
141
+ const loc = { start: context.sourceCode.getLocFromIndex(range[0]), end: context.sourceCode.getLocFromIndex(range[1]) };
142
+ const b = bases[k];
143
+ const base = b.base.slice(prefix.length);
144
+ if (prefix && !b.base.startsWith(prefix))
145
+ continue;
146
+ if (/(^|:)(rtl|ltr):/.test(b.variants))
147
+ continue;
148
+ if (removedStart && /^(start|end)-.+/.test(base)) {
149
+ const rep = cls.replace(/(start|end)-/, (m) => (m === "start-" ? "inset-s-" : "inset-e-"));
150
+ report({ loc, messageId: "removed", data: { found: cls, replacement: rep }, fix: (f) => f.replaceTextRange(range, rep) });
151
+ continue;
152
+ }
153
+ if (manual)
154
+ continue;
155
+ if (centerX && /^(left|right)-1\/2$/.test(base))
156
+ continue;
157
+ const rep = logicalTailwindClass(cls, { dir, inset: modern ? "inset-s" : "start", prefix });
158
+ if (rep) {
159
+ report({ loc, messageId: "physical", data: { found: cls, replacement: rep }, fix: (f) => f.replaceTextRange(range, rep) });
160
+ continue;
161
+ }
162
+ if ((opts.translate ?? true) && /^translate-x-(?!0$)/.test(base) && !(centerX && base === "translate-x-1/2")) {
163
+ report({ loc, messageId: "translate", data: { found: cls, mirror: mirrorTranslate((b.negative ? "-" : "") + b.base) } });
164
+ continue;
165
+ }
166
+ if (v3 && /^(space|divide)-x-(?!reverse)/.test(base))
167
+ report({ loc, messageId: "spaceX", data: { found: cls } });
168
+ }
169
+ });
170
+ },
171
+ };
@@ -0,0 +1,9 @@
1
+ import type { Rule } from "eslint";
2
+ export declare const noArabicChars: Rule.RuleModule;
3
+ export declare const persianDigits: Rule.RuleModule;
4
+ export declare const zwnj: Rule.RuleModule;
5
+ export declare const noInvalidZwnj: Rule.RuleModule;
6
+ export declare const punctuationSpacing: Rule.RuleModule;
7
+ export declare const persianPunctuation: Rule.RuleModule;
8
+ export declare const noKashida: Rule.RuleModule;
9
+ export declare const noExtraDiacritics: Rule.RuleModule;