@longzai-intelligence-oxlint/design-rules-plugin 0.1.17
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.
- package/README.md +30 -0
- package/dist/configs/recommended.d.ts +8 -0
- package/dist/configs/recommended.js +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +4 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# @longzai-intelligence-oxlint/design-rules-plugin
|
|
2
|
+
|
|
3
|
+
Longzai Intelligence Design 设计专用 Oxlint 规则插件。强制消费方使用设计令牌,杜绝硬编码颜色 / 间距 / z-index,作为 design 域代码规范契约的真实承载(替代历史幻影 `eslint-config`)。
|
|
4
|
+
|
|
5
|
+
## 规则
|
|
6
|
+
|
|
7
|
+
| 规则 | 说明 | 推荐级别 |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| `no-hardcoded-color` | 禁止在 className 中硬编码颜色(`bg-[#fff]`、`text-[rgb(...)]`),强制用语义令牌(`bg-primary`) | error |
|
|
10
|
+
| `no-hardcoded-spacing` | 禁止任意值间距(`p-[22px]`、`gap-[7px]`),强制用间距刻度(`p-6`、`gap-2`) | error |
|
|
11
|
+
| `no-magic-z-index` | 禁止魔法 z-index(`z-[999]`、`zIndex: 100`),强制用层级令牌(`z-dropdown`) | error |
|
|
12
|
+
|
|
13
|
+
## 消费方式
|
|
14
|
+
|
|
15
|
+
design 项目不直接引用本插件,而是经 `@longzai-intelligence-oxlint/presets` 的 `library` 预设间接消费(presets 的 `JS_PLUGINS` 已聚合本插件)。新增 design package 默认生效,无需改 `oxlint.config.ts`。
|
|
16
|
+
|
|
17
|
+
## 规则键名
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
@longzai-intelligence-oxlint/design-rules-plugin/no-hardcoded-color
|
|
21
|
+
@longzai-intelligence-oxlint/design-rules-plugin/no-hardcoded-spacing
|
|
22
|
+
@longzai-intelligence-oxlint/design-rules-plugin/no-magic-z-index
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## 相关
|
|
26
|
+
|
|
27
|
+
- [design 色彩规范](../../../../longzai-intelligence-design/docs/foundations/color.md)
|
|
28
|
+
- [design 间距规范](../../../../longzai-intelligence-design/docs/foundations/spacing.md)
|
|
29
|
+
- [design 层级规范](../../../../longzai-intelligence-design/docs/foundations/elevation.md)
|
|
30
|
+
- ADR-0078(设计专用代码规范契约,待补)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e={"@longzai-intelligence-oxlint/design-rules-plugin/no-hardcoded-color":`error`,"@longzai-intelligence-oxlint/design-rules-plugin/no-hardcoded-spacing":`error`,"@longzai-intelligence-oxlint/design-rules-plugin/no-magic-z-index":`error`};export{e as recommended};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
//#region src/rules/no-hardcoded-color.rule.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* 禁止硬编码颜色的 Oxlint 规则
|
|
4
|
+
*
|
|
5
|
+
* 扫描源码每行,检测 Tailwind 任意值颜色模式。命中则报告,提示改用语义令牌。
|
|
6
|
+
*/
|
|
7
|
+
declare const noHardcodedColorRule: import("@oxlint/plugins").Rule;
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/rules/no-hardcoded-spacing.rule.d.ts
|
|
10
|
+
/**
|
|
11
|
+
* 禁止硬编码间距的 Oxlint 规则
|
|
12
|
+
*
|
|
13
|
+
* 扫描源码每行,检测 Tailwind 任意值间距模式。命中则报告,提示改用间距刻度。
|
|
14
|
+
*/
|
|
15
|
+
declare const noHardcodedSpacingRule: import("@oxlint/plugins").Rule;
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/rules/no-magic-z-index.rule.d.ts
|
|
18
|
+
/**
|
|
19
|
+
* 禁止魔法 z-index 的 Oxlint 规则
|
|
20
|
+
*
|
|
21
|
+
* 扫描源码每行,检测任意值 z-index 与 inline zIndex 数值。命中则报告,提示改用层级令牌。
|
|
22
|
+
*/
|
|
23
|
+
declare const noMagicZIndexRule: import("@oxlint/plugins").Rule;
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/index.d.ts
|
|
26
|
+
/**
|
|
27
|
+
* design-rules 插件
|
|
28
|
+
*/
|
|
29
|
+
declare const designRulesPlugin: import("@oxlint/plugins").Plugin;
|
|
30
|
+
//#endregion
|
|
31
|
+
export { designRulesPlugin as default, designRulesPlugin, noHardcodedColorRule, noHardcodedSpacingRule, noMagicZIndexRule };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{defineRule as e,eslintCompatPlugin as t}from"@oxlint/plugins";const n=/(?:bg|text|border|fill|stroke|ring|outline|from|to|via|caret|accent|decoration|shadow)-\[(?:#[0-9a-fA-F]{3,8}|(?:rgb|rgba|hsl|hsla|oklch)\([^)]*\))\]/g;function r(e){let t=e.trim();return t.startsWith(`//`)||t.startsWith(`*`)||t.startsWith(`/*`)||t.startsWith(`<!--`)}const i=e({meta:{type:`problem`,docs:{description:`禁止在 className 中硬编码颜色,强制使用设计令牌语义色(如 bg-primary)`}},createOnce(e){return{Program(t){let i=e.sourceCode.text.split(`
|
|
2
|
+
`);for(let a=0;a<i.length;a+=1){if(r(i[a]))continue;n.lastIndex=0;let o=n.exec(i[a]);o&&e.report({node:t,message:`禁止硬编码颜色 "${o[0]}":请使用设计令牌语义色(如 bg-primary / text-muted-foreground),见 foundations/color 规范。`})}}}}}),a=/\b(?:p|px|py|pt|pb|pl|pr|m|mx|my|mt|mb|ml|mr|gap|gap-x|gap-y|w|h|min-w|min-h|max-w|max-h|space-x|space-y|inset|top|right|bottom|left)-\[\d+(?:\.\d+)?(?:px|rem|em)\]/g;function o(e){let t=e.trim();return t.startsWith(`//`)||t.startsWith(`*`)||t.startsWith(`/*`)||t.startsWith(`<!--`)}const s=e({meta:{type:`problem`,docs:{description:`禁止在 className 中使用任意值间距,强制使用间距刻度(如 p-6 / gap-2)`}},createOnce(e){return{Program(t){let n=e.sourceCode.text.split(`
|
|
3
|
+
`);for(let r=0;r<n.length;r+=1){if(o(n[r]))continue;a.lastIndex=0;let i=a.exec(n[r]);i&&e.report({node:t,message:`禁止任意值间距 "${i[0]}":请使用间距刻度(如 p-6 / gap-2)或语义别名,见 foundations/spacing 规范。`})}}}}}),c=/\bz-\[\d+\]/g,l=/zIndex\s*:\s*\d+/g;function u(e){let t=e.trim();return t.startsWith(`//`)||t.startsWith(`*`)||t.startsWith(`/*`)||t.startsWith(`<!--`)}const d=e({meta:{type:`problem`,docs:{description:`禁止硬编码 z-index,强制使用层级令牌(如 z-dropdown / z-modal / z-toast)`}},createOnce(e){return{Program(t){let n=e.sourceCode.text.split(`
|
|
4
|
+
`);for(let r=0;r<n.length;r+=1){if(u(n[r]))continue;c.lastIndex=0;let i=c.exec(n[r]);if(i){e.report({node:t,message:`禁止魔法 z-index "${i[0]}":请使用层级令牌(如 z-dropdown / z-modal / z-toast),见 foundations/elevation 规范。`});continue}l.lastIndex=0;let a=l.exec(n[r]);a&&e.report({node:t,message:`禁止硬编码 zIndex "${a[0]}":请使用层级令牌(如 z-dropdown / z-modal / z-toast),见 foundations/elevation 规范。`})}}}}}),f=t({meta:{name:`@longzai-intelligence-oxlint/design-rules-plugin`},rules:{"no-hardcoded-color":i,"no-hardcoded-spacing":s,"no-magic-z-index":d}});export{f as default,f as designRulesPlugin,i as noHardcodedColorRule,s as noHardcodedSpacingRule,d as noMagicZIndexRule};
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@longzai-intelligence-oxlint/design-rules-plugin",
|
|
3
|
+
"version": "0.1.17",
|
|
4
|
+
"license": "UNLICENSED",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
|
+
},
|
|
16
|
+
"./configs/recommended": {
|
|
17
|
+
"types": "./dist/configs/recommended.d.ts",
|
|
18
|
+
"import": "./dist/configs/recommended.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "lzi-builder",
|
|
23
|
+
"build:prod": "NODE_ENV=production bun run build",
|
|
24
|
+
"prepublishOnly": "bun run build:prod",
|
|
25
|
+
"dev": "lzi-builder --watch",
|
|
26
|
+
"clean": "lzi-dev-cli clean",
|
|
27
|
+
"test": "vitest run",
|
|
28
|
+
"test:watch": "vitest",
|
|
29
|
+
"test:coverage": "vitest run --coverage",
|
|
30
|
+
"lint": "oxlint && oxfmt --check",
|
|
31
|
+
"lint:fix": "oxlint --fix && oxfmt",
|
|
32
|
+
"typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
|
|
33
|
+
"typecheck:app": "lzi-tsgo typecheck tsconfig/app.json",
|
|
34
|
+
"typecheck:node": "lzi-tsgo typecheck tsconfig/node.json",
|
|
35
|
+
"typecheck:test": "lzi-tsgo typecheck tsconfig/test.json"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@longzai-intelligence-oxlint/core": "0.1.17",
|
|
39
|
+
"@longzai-intelligence-oxlint/utils": "0.1.17",
|
|
40
|
+
"@oxlint/plugins": "^1.74.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@vitest/coverage-v8": "^4.1.10"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"oxlint": ">=1.0.0"
|
|
47
|
+
}
|
|
48
|
+
}
|