@moheng-design/ui-skill 1.0.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.
- package/README.md +227 -0
- package/bin/cli.js +35 -0
- package/bin/lib/audit.mjs +138 -0
- package/bin/lib/feedback.mjs +82 -0
- package/bin/lib/install.mjs +61 -0
- package/bin/lib/paths.mjs +47 -0
- package/bin/lib/upgrade.mjs +86 -0
- package/eslint/index.js +94 -0
- package/eslint/lib/factories.js +313 -0
- package/eslint/lib/match.js +188 -0
- package/eslint/lib/tiers.js +27 -0
- package/generated/SKILL.md +696 -0
- package/generated/contracts.json +9270 -0
- package/generated/mappings.schema.json +333 -0
- package/generated/plugin-data.js +6994 -0
- package/generated/reference.md +5651 -0
- package/generated/rules.json +3864 -0
- package/generated/skills/moheng-ui-audit/SKILL.md +66 -0
- package/generated/skills/moheng-ui-bootstrap/SKILL.md +109 -0
- package/generated/skills/moheng-ui-feedback/SKILL.md +65 -0
- package/generated/skills/moheng-ui-page/SKILL.md +75 -0
- package/generated/skills/moheng-ui-review/SKILL.md +55 -0
- package/generated/skills/moheng-ui-upgrade/SKILL.md +40 -0
- package/generated/unenforced.json +57 -0
- package/handwritten/anti-patterns.md +239 -0
- package/handwritten/canvas-model.md +98 -0
- package/handwritten/conventions.md +2082 -0
- package/handwritten/skills/audit.md +54 -0
- package/handwritten/skills/bootstrap.md +99 -0
- package/handwritten/skills/feedback.md +63 -0
- package/handwritten/skills/page.md +44 -0
- package/handwritten/skills/review.md +43 -0
- package/handwritten/skills/upgrade.md +38 -0
- package/handwritten/unenforced.md +27 -0
- package/package.json +66 -0
- package/stylelint/index.js +121 -0
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://moheng.dev/schemas/mappings-1.json",
|
|
4
|
+
"title": "@moheng-design/ui 替换规则",
|
|
5
|
+
"description": "Skill 替换表与 ESLint / stylelint 规则的共同输入(01 §1.5、§5)。两边各自维护必然出现「Skill 让用 A、lint 让用 B」的矛盾,agent 会卡在改了被打回、按 lint 改又违反 skill 的死循环里 —— 本 schema 存在的唯一理由就是杜绝这一点。schema 覆盖 5 类规则,是设计系统现有 _adherence.oxlintrc.json 的超集(§5.4)。",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"additionalProperties": false,
|
|
8
|
+
"required": ["version", "rules"],
|
|
9
|
+
"properties": {
|
|
10
|
+
"$schema": {
|
|
11
|
+
"type": "string",
|
|
12
|
+
"description": "指向本 schema 的相对路径,供编辑器补全。"
|
|
13
|
+
},
|
|
14
|
+
"version": {
|
|
15
|
+
"const": "1",
|
|
16
|
+
"description": "schema 版本。破坏性变更时递增,生成器按此分支。"
|
|
17
|
+
},
|
|
18
|
+
"rules": {
|
|
19
|
+
"type": "array",
|
|
20
|
+
"minItems": 1,
|
|
21
|
+
"items": { "$ref": "#/$defs/rule" }
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"$defs": {
|
|
25
|
+
"rule": {
|
|
26
|
+
"oneOf": [
|
|
27
|
+
{ "$ref": "#/$defs/forbidElement" },
|
|
28
|
+
{ "$ref": "#/$defs/forbidImport" },
|
|
29
|
+
{ "$ref": "#/$defs/forbidValue" },
|
|
30
|
+
{ "$ref": "#/$defs/propsWhitelist" },
|
|
31
|
+
{ "$ref": "#/$defs/propEnum" }
|
|
32
|
+
]
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
"id": {
|
|
36
|
+
"type": "string",
|
|
37
|
+
"pattern": "^[a-z][a-z0-9]*(-[a-z0-9]+)*$",
|
|
38
|
+
"description": "kebab-case,全局唯一。同时是生成出的 ESLint 规则名。"
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
"scope": {
|
|
42
|
+
"enum": ["internal", "consumer", "both"],
|
|
43
|
+
"description": "生效范围(§7.3)。internal 仅库内部,例如禁止硬编码色值 —— 组件源码必须用 token。consumer 仅消费方项目,例如禁止裸 <button>。把 internal 类规则发给用户会吵到无法使用,用户第一反应是整条关掉,连带把真正有价值的一起关了。"
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
"severity": {
|
|
47
|
+
"enum": ["error", "warn"],
|
|
48
|
+
"description": "recommended 档下的级别(§7.4)。strict 档把全部规则提为 error,migration 档全部降为 warn,因此本字段只决定 recommended 的表现。"
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
"message": {
|
|
52
|
+
"type": "string",
|
|
53
|
+
"minLength": 12,
|
|
54
|
+
"description": "报错文案,必须是可直接执行的替换指令(§5.2)。反例:'prefer-moheng-button' —— agent 读到不知道该怎么改。正例:'请使用 Button 组件替代原生 <button>。导入方式:import { Button } from \\'@moheng-design/ui\\''。这是整套机制的核心,不要写敷衍的文案。"
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
"example": {
|
|
58
|
+
"type": "object",
|
|
59
|
+
"additionalProperties": false,
|
|
60
|
+
"required": ["bad", "good"],
|
|
61
|
+
"description": "成对的反例与正例。经验上比正面描述有效得多(§6.2),生成 SKILL.md 时直接引用。",
|
|
62
|
+
"properties": {
|
|
63
|
+
"bad": { "type": "string", "minLength": 1 },
|
|
64
|
+
"good": { "type": "string", "minLength": 1 }
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
"targets": {
|
|
69
|
+
"type": "array",
|
|
70
|
+
"minItems": 1,
|
|
71
|
+
"uniqueItems": true,
|
|
72
|
+
"items": { "enum": ["js", "css"] },
|
|
73
|
+
"description": "规则在哪种文件上生效,决定生成到哪个工具。js → ESLint(JS / JSX / TS / TSX 字面量与 JSX 结构)。css → stylelint。ESLint 不处理 .css 文件,所以「组件 CSS 不得出现硬编码值」(§4.1)只有标了 css 才真正落地。"
|
|
74
|
+
},
|
|
75
|
+
|
|
76
|
+
"rationale": {
|
|
77
|
+
"type": "string",
|
|
78
|
+
"description": "可选。为什么有这条规则。写进 SKILL.md 的说明段,不进报错文案。"
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
"componentName": {
|
|
82
|
+
"type": "string",
|
|
83
|
+
"pattern": "^[A-Z][A-Za-z0-9]*$",
|
|
84
|
+
"description": "组件名,必须是 contracts/ 中某个 <Name>Props 接口去掉 Props 后缀的结果。check-mappings 会校验其存在。"
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
"autofix": {
|
|
88
|
+
"type": "object",
|
|
89
|
+
"additionalProperties": false,
|
|
90
|
+
"required": ["enabled"],
|
|
91
|
+
"description": "autofix 必须保守(§5.3)。<button className=\"px-4 py-2\">提交</button> → <Button variant=\"primary\">提交</Button> 会丢弃 className,agent 一句 --fix 就吃掉用户样式且不报错。静默的样式丢失比 lint 报错难查得多。",
|
|
92
|
+
"properties": {
|
|
93
|
+
"enabled": { "type": "boolean" },
|
|
94
|
+
"onlyWhenNoStyling": {
|
|
95
|
+
"const": true,
|
|
96
|
+
"description": "启用 autofix 时必须为 true,schema 层面不允许写 false —— §5.3 的约束若只写在文档里,即触犯 §1.4 定义的反模式。含义:仅当元素不带 className 与 style 时才自动替换。"
|
|
97
|
+
},
|
|
98
|
+
"classToProps": {
|
|
99
|
+
"type": "object",
|
|
100
|
+
"minProperties": 1,
|
|
101
|
+
"additionalProperties": {
|
|
102
|
+
"type": "object",
|
|
103
|
+
"minProperties": 1,
|
|
104
|
+
"additionalProperties": { "type": ["string", "number", "boolean"] }
|
|
105
|
+
},
|
|
106
|
+
"description": "可选。§5.3 允许的第二种 autofix 条件:class 能被完整映射到目标组件的 variant。键是 class 字符串,值是要写入的 props。未在此表中出现的 class 一律不 autofix。"
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
"if": {
|
|
110
|
+
"required": ["enabled"],
|
|
111
|
+
"properties": { "enabled": { "const": true } }
|
|
112
|
+
},
|
|
113
|
+
"then": { "required": ["onlyWhenNoStyling"] }
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
"forbidElement": {
|
|
117
|
+
"type": "object",
|
|
118
|
+
"additionalProperties": false,
|
|
119
|
+
"required": ["id", "kind", "scope", "severity", "message", "example", "targets", "match", "replacement", "autofix"],
|
|
120
|
+
"description": "禁止裸原生元素,报错指向对应组件。这是设计系统现有 lint 配置中唯一缺失的部分 —— _adherence.oxlintrc.json 的 react/forbid-elements 是空数组(§5.4、§7.2 第 1 类)。",
|
|
121
|
+
"properties": {
|
|
122
|
+
"id": { "$ref": "#/$defs/id" },
|
|
123
|
+
"kind": { "const": "forbid-element" },
|
|
124
|
+
"scope": { "$ref": "#/$defs/scope" },
|
|
125
|
+
"severity": { "$ref": "#/$defs/severity" },
|
|
126
|
+
"message": { "$ref": "#/$defs/message" },
|
|
127
|
+
"example": { "$ref": "#/$defs/example" },
|
|
128
|
+
"targets": { "$ref": "#/$defs/targets" },
|
|
129
|
+
"rationale": { "$ref": "#/$defs/rationale" },
|
|
130
|
+
"autofix": { "$ref": "#/$defs/autofix" },
|
|
131
|
+
"match": {
|
|
132
|
+
"type": "object",
|
|
133
|
+
"additionalProperties": false,
|
|
134
|
+
"required": ["element"],
|
|
135
|
+
"properties": {
|
|
136
|
+
"element": {
|
|
137
|
+
"type": "string",
|
|
138
|
+
"pattern": "^[a-z][a-z0-9-]*$",
|
|
139
|
+
"description": "原生 HTML 标签名,小写。"
|
|
140
|
+
},
|
|
141
|
+
"attributes": {
|
|
142
|
+
"type": "object",
|
|
143
|
+
"minProperties": 1,
|
|
144
|
+
"additionalProperties": { "type": "string" },
|
|
145
|
+
"description": "可选。同一标签按属性分流到不同组件时使用,例如 <input type=\"checkbox\"> → Checkbox 而 <input type=\"text\"> → Input。省略则匹配该标签的全部用法。"
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
"replacement": {
|
|
150
|
+
"type": "object",
|
|
151
|
+
"additionalProperties": false,
|
|
152
|
+
"required": ["component", "from"],
|
|
153
|
+
"properties": {
|
|
154
|
+
"component": { "$ref": "#/$defs/componentName" },
|
|
155
|
+
"from": { "type": "string", "minLength": 1 }
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
|
|
161
|
+
"forbidImport": {
|
|
162
|
+
"type": "object",
|
|
163
|
+
"additionalProperties": false,
|
|
164
|
+
"required": ["id", "kind", "scope", "severity", "message", "example", "targets", "match", "replacement"],
|
|
165
|
+
"description": "禁止从特定路径导入(§7.2 第 3 类)。两种用途:禁止深引组件内部路径(要求从入口导入),以及禁止从 @/components/ui/* 导入 —— 后者专门防 agent 顺手执行 npx shadcn add 引入平行的组件实现。",
|
|
166
|
+
"properties": {
|
|
167
|
+
"id": { "$ref": "#/$defs/id" },
|
|
168
|
+
"kind": { "const": "forbid-import" },
|
|
169
|
+
"scope": { "$ref": "#/$defs/scope" },
|
|
170
|
+
"severity": { "$ref": "#/$defs/severity" },
|
|
171
|
+
"message": { "$ref": "#/$defs/message" },
|
|
172
|
+
"example": { "$ref": "#/$defs/example" },
|
|
173
|
+
"targets": { "$ref": "#/$defs/targets" },
|
|
174
|
+
"rationale": { "$ref": "#/$defs/rationale" },
|
|
175
|
+
"match": {
|
|
176
|
+
"type": "object",
|
|
177
|
+
"additionalProperties": false,
|
|
178
|
+
"required": ["importPatterns"],
|
|
179
|
+
"properties": {
|
|
180
|
+
"importPatterns": {
|
|
181
|
+
"type": "array",
|
|
182
|
+
"minItems": 1,
|
|
183
|
+
"uniqueItems": true,
|
|
184
|
+
"items": { "type": "string", "minLength": 1 },
|
|
185
|
+
"description": "glob 形式的模块路径,语法同 ESLint no-restricted-imports 的 patterns.group。"
|
|
186
|
+
},
|
|
187
|
+
"exceptFiles": {
|
|
188
|
+
"type": "array",
|
|
189
|
+
"minItems": 1,
|
|
190
|
+
"uniqueItems": true,
|
|
191
|
+
"items": { "type": "string", "minLength": 1 },
|
|
192
|
+
"description": "可选。豁免文件 glob,生成 ESLint 的 overrides。例如库入口自身必然要深引各组件。"
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
"replacement": {
|
|
197
|
+
"type": "object",
|
|
198
|
+
"additionalProperties": false,
|
|
199
|
+
"required": ["from"],
|
|
200
|
+
"properties": {
|
|
201
|
+
"from": { "type": "string", "minLength": 1 },
|
|
202
|
+
"component": { "$ref": "#/$defs/componentName" }
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
|
|
208
|
+
"forbidValue": {
|
|
209
|
+
"type": "object",
|
|
210
|
+
"additionalProperties": false,
|
|
211
|
+
"required": ["id", "kind", "scope", "severity", "message", "example", "targets", "match"],
|
|
212
|
+
"description": "禁止硬编码样式值(§7.2 第 2 类)。scope 必须是 internal —— 用户业务代码里出现色值是完全正常的,全量禁止会吵到无法使用(§7.3)。",
|
|
213
|
+
"properties": {
|
|
214
|
+
"id": { "$ref": "#/$defs/id" },
|
|
215
|
+
"kind": { "const": "forbid-value" },
|
|
216
|
+
"scope": { "$ref": "#/$defs/scope" },
|
|
217
|
+
"severity": { "$ref": "#/$defs/severity" },
|
|
218
|
+
"message": { "$ref": "#/$defs/message" },
|
|
219
|
+
"example": { "$ref": "#/$defs/example" },
|
|
220
|
+
"targets": { "$ref": "#/$defs/targets" },
|
|
221
|
+
"rationale": { "$ref": "#/$defs/rationale" },
|
|
222
|
+
"match": {
|
|
223
|
+
"type": "object",
|
|
224
|
+
"additionalProperties": false,
|
|
225
|
+
"required": ["valuePattern"],
|
|
226
|
+
"properties": {
|
|
227
|
+
"valuePattern": {
|
|
228
|
+
"type": "string",
|
|
229
|
+
"minLength": 1,
|
|
230
|
+
"description": "正则源码,不含首尾斜杠。ESLint 侧包成 Literal[value=/.../],stylelint 侧用作声明值的禁用模式。"
|
|
231
|
+
},
|
|
232
|
+
"flags": {
|
|
233
|
+
"type": "string",
|
|
234
|
+
"pattern": "^[gimsuy]*$",
|
|
235
|
+
"description": "可选正则标志。"
|
|
236
|
+
},
|
|
237
|
+
"cssProperties": {
|
|
238
|
+
"type": "array",
|
|
239
|
+
"minItems": 1,
|
|
240
|
+
"uniqueItems": true,
|
|
241
|
+
"items": { "type": "string", "minLength": 1 },
|
|
242
|
+
"description": "可选,仅 targets 含 css 时有意义。限定只检查这些 CSS 属性;省略则检查全部声明。"
|
|
243
|
+
},
|
|
244
|
+
"exceptFiles": {
|
|
245
|
+
"type": "array",
|
|
246
|
+
"minItems": 1,
|
|
247
|
+
"uniqueItems": true,
|
|
248
|
+
"items": { "type": "string", "minLength": 1 },
|
|
249
|
+
"description": "可选。豁免文件 glob。token 源文件必然要写字面值,是这条的天然豁免对象。"
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
"replacement": {
|
|
254
|
+
"type": "object",
|
|
255
|
+
"additionalProperties": false,
|
|
256
|
+
"description": "可选。没有目标组件,只有该用哪层 token 的提示。",
|
|
257
|
+
"properties": {
|
|
258
|
+
"tokenPrefix": {
|
|
259
|
+
"type": "string",
|
|
260
|
+
"minLength": 1,
|
|
261
|
+
"description": "应当改用的 token 前缀,例如 --ds-color- 或 --application-space-。"
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
|
|
268
|
+
"propsWhitelist": {
|
|
269
|
+
"type": "object",
|
|
270
|
+
"additionalProperties": false,
|
|
271
|
+
"required": ["id", "kind", "generated", "scope", "severity", "message", "targets", "match", "allowed"],
|
|
272
|
+
"description": "每组件的 props 白名单。generated 恒为 true —— 本类规则由 contracts/*.d.ts 自动生成后与手写规则合并输出(§5.4),手写的 mappings.json 中不得出现,否则即制造 §1.5 要杜绝的第二处事实来源。schema 收录它只为满足超集要求。",
|
|
273
|
+
"properties": {
|
|
274
|
+
"id": { "$ref": "#/$defs/id" },
|
|
275
|
+
"kind": { "const": "props-whitelist" },
|
|
276
|
+
"generated": { "const": true },
|
|
277
|
+
"scope": { "$ref": "#/$defs/scope" },
|
|
278
|
+
"severity": { "$ref": "#/$defs/severity" },
|
|
279
|
+
"message": { "$ref": "#/$defs/message" },
|
|
280
|
+
"example": { "$ref": "#/$defs/example" },
|
|
281
|
+
"targets": { "$ref": "#/$defs/targets" },
|
|
282
|
+
"rationale": { "$ref": "#/$defs/rationale" },
|
|
283
|
+
"match": {
|
|
284
|
+
"type": "object",
|
|
285
|
+
"additionalProperties": false,
|
|
286
|
+
"required": ["component"],
|
|
287
|
+
"properties": { "component": { "$ref": "#/$defs/componentName" } }
|
|
288
|
+
},
|
|
289
|
+
"allowed": {
|
|
290
|
+
"type": "array",
|
|
291
|
+
"minItems": 1,
|
|
292
|
+
"uniqueItems": true,
|
|
293
|
+
"items": { "type": "string", "minLength": 1 },
|
|
294
|
+
"description": "允许的 prop 名。须含 React 保留项 key / ref / className / style / children。"
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
},
|
|
298
|
+
|
|
299
|
+
"propEnum": {
|
|
300
|
+
"type": "object",
|
|
301
|
+
"additionalProperties": false,
|
|
302
|
+
"required": ["id", "kind", "generated", "scope", "severity", "message", "targets", "match", "allowed"],
|
|
303
|
+
"description": "枚举 prop 的取值校验。与 props-whitelist 同为生成类,理由见该条。",
|
|
304
|
+
"properties": {
|
|
305
|
+
"id": { "$ref": "#/$defs/id" },
|
|
306
|
+
"kind": { "const": "prop-enum" },
|
|
307
|
+
"generated": { "const": true },
|
|
308
|
+
"scope": { "$ref": "#/$defs/scope" },
|
|
309
|
+
"severity": { "$ref": "#/$defs/severity" },
|
|
310
|
+
"message": { "$ref": "#/$defs/message" },
|
|
311
|
+
"example": { "$ref": "#/$defs/example" },
|
|
312
|
+
"targets": { "$ref": "#/$defs/targets" },
|
|
313
|
+
"rationale": { "$ref": "#/$defs/rationale" },
|
|
314
|
+
"match": {
|
|
315
|
+
"type": "object",
|
|
316
|
+
"additionalProperties": false,
|
|
317
|
+
"required": ["component", "prop"],
|
|
318
|
+
"properties": {
|
|
319
|
+
"component": { "$ref": "#/$defs/componentName" },
|
|
320
|
+
"prop": { "type": "string", "minLength": 1 }
|
|
321
|
+
}
|
|
322
|
+
},
|
|
323
|
+
"allowed": {
|
|
324
|
+
"type": "array",
|
|
325
|
+
"minItems": 1,
|
|
326
|
+
"uniqueItems": true,
|
|
327
|
+
"items": { "type": "string", "minLength": 1 },
|
|
328
|
+
"description": "字面量联合类型的全部取值,取自契约。"
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|