@kashi-ui/stylelint-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,22 @@
1
+ export declare const rules: {
2
+ readonly "kashi/use-logical-properties": true;
3
+ readonly "kashi/use-logical-values": true;
4
+ readonly "kashi/no-physical-transform": true;
5
+ readonly "kashi/no-root-direction": true;
6
+ readonly "kashi/tailwind-logical": true;
7
+ readonly "kashi/persian-text": true;
8
+ readonly "kashi/persian-typography": true;
9
+ };
10
+ declare const _default: {
11
+ plugins: import("stylelint").Plugin[];
12
+ rules: {
13
+ readonly "kashi/use-logical-properties": true;
14
+ readonly "kashi/use-logical-values": true;
15
+ readonly "kashi/no-physical-transform": true;
16
+ readonly "kashi/no-root-direction": true;
17
+ readonly "kashi/tailwind-logical": true;
18
+ readonly "kashi/persian-text": true;
19
+ readonly "kashi/persian-typography": true;
20
+ };
21
+ };
22
+ export default _default;
package/dist/strict.js ADDED
@@ -0,0 +1,12 @@
1
+ // پیکربندی سخت‌گیر: همهٔ قانون‌های RTL و فارسی، همه خطا؛ extends: ["@kashi-ui/stylelint-plugin/strict"]
2
+ import plugins from "./index.js";
3
+ export const rules = {
4
+ "kashi/use-logical-properties": true,
5
+ "kashi/use-logical-values": true,
6
+ "kashi/no-physical-transform": true,
7
+ "kashi/no-root-direction": true,
8
+ "kashi/tailwind-logical": true,
9
+ "kashi/persian-text": true,
10
+ "kashi/persian-typography": true,
11
+ };
12
+ export default { plugins, rules };
package/dist/util.d.ts ADDED
@@ -0,0 +1,64 @@
1
+ import stylelint from "stylelint";
2
+ import type { Declaration, Node, Root, AtRule } from "postcss";
3
+ export declare const DOCS = "https://kashi.sepantapouya.com/docs/lint/";
4
+ export type Locale = "fa" | "en" | "both";
5
+ export type Bilingual = readonly [fa: string, en: string];
6
+ export declare function text(locale: Locale | undefined, [fa, en]: Bilingual, data?: Record<string, string>): string;
7
+ export interface CommonOptions {
8
+ /** زبان پیام‌ها @default "both" */
9
+ locale?: Locale;
10
+ /** جهت اصلی پروژه @default "rtl" */
11
+ direction?: "rtl" | "ltr";
12
+ /** selectorهایی که نادیده گرفته شوند (regex) */
13
+ ignoreSelectors?: string[];
14
+ }
15
+ export declare const COMMON_SCHEMA: {
16
+ locale: ((v: unknown) => v is "fa" | "en" | "both")[];
17
+ direction: ((v: unknown) => v is "rtl" | "ltr")[];
18
+ ignoreSelectors: ((v: unknown) => v is string)[];
19
+ };
20
+ export interface KashiRuleSpec<O extends CommonOptions> {
21
+ name: string;
22
+ description: string;
23
+ descriptionFa: string;
24
+ fixable: boolean;
25
+ messages: Record<string, Bilingual>;
26
+ optionSchema?: Record<string, unknown[]>;
27
+ run: (root: Root, ctx: RuleContext<O>) => void;
28
+ }
29
+ export interface RuleContext<O> {
30
+ options: O;
31
+ report: (args: {
32
+ node: Node;
33
+ messageId: string;
34
+ data?: Record<string, string>;
35
+ word?: string;
36
+ index?: number;
37
+ endIndex?: number;
38
+ fix?: () => void;
39
+ }) => void;
40
+ ignored: (node: Node) => boolean;
41
+ }
42
+ /** سازندهٔ قانون Stylelint با پیام دوزبانه و گزینه‌های مشترک */
43
+ export declare function createRule<O extends CommonOptions>(spec: KashiRuleSpec<O>): stylelint.Plugin;
44
+ /** selectorهای همهٔ rule های بالادست (برای تشخیص :dir()، [dir] و مانند آن) */
45
+ export declare function ancestorSelectors(node: Node): string[];
46
+ /** آیا قاعده خودش جهت را مدیریت می‌کند: :dir()، [dir=…]، .rtl/.ltr */
47
+ export declare function isDirectionAware(node: Node): boolean;
48
+ /** آیا selector عمداً سمت فیزیکی را نام می‌برد: [data-side="left"]، .tooltip--right، .placement-left */
49
+ export declare function namesPhysicalSide(node: Node, side?: string): boolean;
50
+ export declare function inKeyframes(node: Node): AtRule | undefined;
51
+ /** خواهر و برادرهای یک declaration در همان قاعده */
52
+ export declare function siblingDecls(decl: Declaration): Declaration[];
53
+ /** آیا این قاعده با left: 50% (یا inset: … 50%) + translate(-50%) وسط‌چین است (به جهت ربطی ندارد) */
54
+ export declare function isCentering(decl: Declaration): boolean;
55
+ /** عنصری که جهتش در همین قاعده یا قاعدهٔ بالادست ثابت شده (direction: ltr، مثل بلوک کد): سمت فیزیکی همان سمت منطقی است */
56
+ export declare function hasFixedDirection(node: Node): boolean;
57
+ /** selector لاتین یا کد (همیشه چپ‌به‌راست): pre، code، kbd، .k-code__pre، :lang(en)، [dir=ltr]، ورودی عددی */
58
+ export declare const LTR_CONTEXT: RegExp;
59
+ export declare function inLtrContext(node: Node): boolean;
60
+ /** selector بدون قید جهت: «[dir="ltr"] .toc a» ← «.toc a» */
61
+ export declare function stripDirection(selector: string): string;
62
+ /** offset شروع value در متن declaration (برای index گزارش) */
63
+ export declare function valueOffset(decl: Declaration): number;
64
+ export declare function tailwindVersion(setting: string | number | undefined, cwd?: string): [number, number] | null;
package/dist/util.js ADDED
@@ -0,0 +1,146 @@
1
+ import stylelint from "stylelint";
2
+ import { createRequire } from "node:module";
3
+ import { readFileSync } from "node:fs";
4
+ import { join } from "node:path";
5
+ export const DOCS = "https://kashi.sepantapouya.com/docs/lint/";
6
+ export function text(locale, [fa, en], data = {}) {
7
+ const fill = (s) => s.replace(/\{\{\s*(\w+)\s*\}\}/g, (_, k) => data[k] ?? "");
8
+ if (locale === "fa")
9
+ return fill(fa);
10
+ if (locale === "en")
11
+ return fill(en);
12
+ return `${fill(fa)} (${fill(en)})`;
13
+ }
14
+ export const COMMON_SCHEMA = {
15
+ locale: [(v) => v === "fa" || v === "en" || v === "both"],
16
+ direction: [(v) => v === "rtl" || v === "ltr"],
17
+ ignoreSelectors: [(v) => typeof v === "string"],
18
+ };
19
+ /** سازندهٔ قانون Stylelint با پیام دوزبانه و گزینه‌های مشترک */
20
+ export function createRule(spec) {
21
+ const ruleName = `kashi/${spec.name}`;
22
+ const messages = stylelint.utils.ruleMessages(ruleName, {
23
+ message: (msg) => msg,
24
+ });
25
+ const rule = (primary, secondary) => (root, result) => {
26
+ const valid = stylelint.utils.validateOptions(result, ruleName, { actual: primary, possible: [true] }, { actual: secondary, possible: { ...COMMON_SCHEMA, ...spec.optionSchema }, optional: true });
27
+ if (!valid || !primary)
28
+ return;
29
+ const options = (secondary ?? {});
30
+ const ignoreSelectors = (options.ignoreSelectors ?? []).map((s) => new RegExp(s));
31
+ const ignored = (node) => {
32
+ for (let p = node; p; p = p.parent) {
33
+ if (p.type === "rule" && ignoreSelectors.some((r) => r.test(p.selector)))
34
+ return true;
35
+ }
36
+ return false;
37
+ };
38
+ spec.run(root, {
39
+ options,
40
+ ignored,
41
+ report: ({ node, messageId, data, word, index, endIndex, fix }) => {
42
+ const message = messages.message(text(options.locale, spec.messages[messageId], data));
43
+ stylelint.utils.report({
44
+ result,
45
+ ruleName,
46
+ node,
47
+ message,
48
+ ...(word ? { word } : {}),
49
+ ...(index !== undefined ? { index, endIndex: endIndex ?? index + 1 } : {}),
50
+ ...(fix ? { fix } : {}),
51
+ });
52
+ },
53
+ });
54
+ };
55
+ rule.ruleName = ruleName;
56
+ rule.messages = messages;
57
+ rule.meta = { url: `${DOCS}#${spec.name}`, fixable: spec.fixable, ...{ description: spec.description, descriptionFa: spec.descriptionFa } };
58
+ return stylelint.createPlugin(ruleName, rule);
59
+ }
60
+ /** selectorهای همهٔ rule های بالادست (برای تشخیص :dir()، [dir] و مانند آن) */
61
+ export function ancestorSelectors(node) {
62
+ const out = [];
63
+ for (let p = node.parent; p; p = p.parent) {
64
+ if (p.type === "rule")
65
+ out.push(p.selector);
66
+ if (p.type === "atrule" && ["media", "supports", "container", "scope"].includes(p.name))
67
+ out.push(`@${p.name} ${p.params}`);
68
+ }
69
+ return out;
70
+ }
71
+ /** آیا قاعده خودش جهت را مدیریت می‌کند: :dir()، [dir=…]، .rtl/.ltr */
72
+ export function isDirectionAware(node) {
73
+ return ancestorSelectors(node).some((s) => /:dir\(|\[dir\b|\.(rtl|ltr)\b|:-moz-locale-dir|\[data-dir/.test(s));
74
+ }
75
+ /** آیا selector عمداً سمت فیزیکی را نام می‌برد: [data-side="left"]، .tooltip--right، .placement-left */
76
+ export function namesPhysicalSide(node, side) {
77
+ const re = side ? new RegExp(`(^|[^a-z])${side}([^a-z]|$)`, "i") : /(^|[^a-z])(left|right)([^a-z]|$)/i;
78
+ return ancestorSelectors(node).some((s) => re.test(s.replace(/\/\*[\s\S]*?\*\//g, "")));
79
+ }
80
+ export function inKeyframes(node) {
81
+ for (let p = node.parent; p; p = p.parent) {
82
+ if (p.type === "atrule" && /keyframes$/i.test(p.name))
83
+ return p;
84
+ }
85
+ return undefined;
86
+ }
87
+ /** خواهر و برادرهای یک declaration در همان قاعده */
88
+ export function siblingDecls(decl) {
89
+ return (decl.parent?.nodes ?? []).filter((n) => n.type === "decl");
90
+ }
91
+ /** آیا این قاعده با left: 50% (یا inset: … 50%) + translate(-50%) وسط‌چین است (به جهت ربطی ندارد) */
92
+ export function isCentering(decl) {
93
+ const sib = siblingDecls(decl);
94
+ const left = sib.some((d) => /^(left|right|inset-inline-start|inset-inline-end)$/i.test(d.prop) && d.value.trim() === "50%") ||
95
+ sib.some((d) => {
96
+ if (!/^inset$/i.test(d.prop))
97
+ return false;
98
+ const v = d.value.trim().split(/\s+/);
99
+ return (v.length === 4 && (v[1] === "50%" || v[3] === "50%")) || ((v.length === 2 || v.length === 3) && v[1] === "50%");
100
+ });
101
+ const tx = sib.some((d) => (/^transform$/i.test(d.prop) && /translate(?:x|3d)?\(\s*-50%/i.test(d.value)) || (/^translate$/i.test(d.prop) && /^\s*-50%/.test(d.value)));
102
+ return left && tx;
103
+ }
104
+ /** عنصری که جهتش در همین قاعده یا قاعدهٔ بالادست ثابت شده (direction: ltr، مثل بلوک کد): سمت فیزیکی همان سمت منطقی است */
105
+ export function hasFixedDirection(node) {
106
+ for (let p = node.parent; p; p = p.parent) {
107
+ if (p.type === "rule" && (p.nodes ?? []).some((n) => n.type === "decl" && /^direction$/i.test(n.prop) && /^(ltr|rtl)\b/i.test(n.value.trim())))
108
+ return true;
109
+ }
110
+ return false;
111
+ }
112
+ /** selector لاتین یا کد (همیشه چپ‌به‌راست): pre، code، kbd، .k-code__pre، :lang(en)، [dir=ltr]، ورودی عددی */
113
+ export const LTR_CONTEXT = /(^|[^a-z])(code|pre|kbd|samp|mono|monospace|latin|english|ltr)([^a-z]|$)|:lang\((?!fa)|\[lang[|^~*]?=["']?(?!fa)|:dir\(ltr\)|\[dir=["']?ltr|\[inputmode=["']?(numeric|tel|decimal)|\[type=["']?(number|tel)/i;
114
+ export function inLtrContext(node) {
115
+ return ancestorSelectors(node).some((s) => LTR_CONTEXT.test(s));
116
+ }
117
+ /** selector بدون قید جهت: «[dir="ltr"] .toc a» ← «.toc a» */
118
+ export function stripDirection(selector) {
119
+ return selector
120
+ .replace(/:dir\([^)]*\)|\[dir[^\]]*\]|\.(rtl|ltr)\b/g, "")
121
+ .replace(/\s+/g, " ")
122
+ .trim();
123
+ }
124
+ /** offset شروع value در متن declaration (برای index گزارش) */
125
+ export function valueOffset(decl) {
126
+ return decl.prop.length + (decl.raws.between ?? ":").length;
127
+ }
128
+ const twCache = new Map();
129
+ export function tailwindVersion(setting, cwd = process.cwd()) {
130
+ let s = setting !== undefined ? String(setting) : null;
131
+ if (s === null) {
132
+ if (twCache.has(cwd))
133
+ return twCache.get(cwd);
134
+ try {
135
+ s = JSON.parse(readFileSync(createRequire(join(cwd, "package.json")).resolve("tailwindcss/package.json"), "utf8")).version;
136
+ }
137
+ catch {
138
+ s = null;
139
+ }
140
+ }
141
+ const [maj, min] = (s ?? "").split(".").map((n) => Number.parseInt(n, 10));
142
+ const v = Number.isFinite(maj) ? [maj, Number.isFinite(min) ? min : 99] : null;
143
+ if (setting === undefined)
144
+ twCache.set(cwd, v);
145
+ return v;
146
+ }
package/package.json CHANGED
@@ -1,6 +1,42 @@
1
1
  {
2
2
  "name": "@kashi-ui/stylelint-plugin",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.29.0",
4
+ "description": "لینتر RTL و فارسی برای Stylelint: خاصیت‌ها و مقدارهای منطقی به‌جای left/right با اصلاح خودکار، translateX، direction روی ریشه، متن فارسی در content، @apply کلاس‌های فیزیکی Tailwind و توکن‌های کاشی",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": { "types": "./dist/index.d.ts", "default": "./dist/index.js" },
10
+ "./config": { "types": "./dist/config.d.ts", "default": "./dist/config.js" },
11
+ "./strict": { "types": "./dist/strict.d.ts", "default": "./dist/strict.js" },
12
+ "./kashi": { "types": "./dist/kashi.d.ts", "default": "./dist/kashi.js" },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": ["dist", "README.md"],
16
+ "sideEffects": false,
17
+ "scripts": {
18
+ "build": "node scripts/build.mjs && tsc -p tsconfig.json",
19
+ "test": "node --test test/*.test.mjs && node --import ./test/use-stylelint-16.mjs test/rules.test.mjs"
20
+ },
21
+ "dependencies": {
22
+ "@kashi-ui/persian": "^2.29.0",
23
+ "postcss-value-parser": "^4.2.0"
24
+ },
25
+ "peerDependencies": {
26
+ "stylelint": "^16.0.0 || ^17.0.0 || ^18.0.0"
27
+ },
28
+ "devDependencies": {
29
+ "stylelint": "^18.0.0",
30
+ "stylelint-v16": "npm:stylelint@^16.26.0",
31
+ "postcss-scss": "^4.0.9",
32
+ "typescript": "^5.6.0"
33
+ },
34
+ "publishConfig": { "access": "public" },
35
+ "keywords": ["stylelint", "stylelint-plugin", "rtl", "logical-properties", "persian", "farsi", "tailwind", "kashi"],
36
+ "repository": { "type": "git", "url": "git+https://github.com/Sepantapouya/Kashi.git", "directory": "packages/stylelint-plugin" },
37
+ "homepage": "https://kashi.sepantapouya.com/docs/lint/",
38
+ "bugs": "https://github.com/Sepantapouya/Kashi/issues",
39
+ "author": "Sepanta Pouya (https://sepantapouya.com)",
40
+ "license": "MIT",
41
+ "engines": { "node": ">=18.12" }
42
+ }