122 lines
3.9 KiB
TypeScript
122 lines
3.9 KiB
TypeScript
/**
|
|
* 单一真值源: 反模式字典.
|
|
* 由 TS 自动生成 dacli/docs/anti-patterns.md (单向).
|
|
* installHelpHook 通过 enrichHelp() 注入到 --help.
|
|
*/
|
|
|
|
export interface AntiPattern {
|
|
/** 唯一 ID, 格式 AP-<command>-<n> */
|
|
id: string
|
|
/** 严重程度 */
|
|
severity: 'P0' | 'P1' | 'P2'
|
|
/** 反例 (1 行) */
|
|
wrong: string
|
|
/** 正例 (1-2 行) */
|
|
right: string
|
|
/** 根因 (1-2 句) */
|
|
rationale: string
|
|
/** 来源 (drift round / CLAUDE.md / decision number) */
|
|
source: string
|
|
/** 跨引用 (decisions 编号等) */
|
|
crossRefs?: string[]
|
|
}
|
|
|
|
export type CommandKey =
|
|
| 'form create'
|
|
| 'form update'
|
|
| 'form info'
|
|
| 'form delete'
|
|
| 'menu create'
|
|
| 'dict typeCreate'
|
|
| 'workflow create'
|
|
| 'dm create'
|
|
| 'di create'
|
|
| 'test run'
|
|
| 'app context'
|
|
|
|
/** 中央反模式字典 (按命令分组) */
|
|
export const ANTI_PATTERNS: Record<CommandKey, AntiPattern[]> = {
|
|
'form create': [
|
|
{
|
|
id: 'AP-fc-1',
|
|
severity: 'P0',
|
|
wrong: 'f_user_id (BIGINT 必填, 未指定FK关联关系)',
|
|
right: 'f_user_id (BIGINT FK 必填 relationForm 关联 user 表 显示字段 f_user_name)',
|
|
rationale: 'AI 默认推成 inputNumber, 列表显示 ID 数字而非名称',
|
|
source: 'drift/R17',
|
|
crossRefs: ['decisions/0001-fk-relation-form-required'],
|
|
},
|
|
{
|
|
id: 'AP-fc-2',
|
|
severity: 'P0',
|
|
wrong: 'f_status (int 必填)',
|
|
right: 'f_status (int 字典 userstatus:0正常/1冻结, 必填 select 组件)',
|
|
rationale: 'int + dictType 不会自动转 select 组件 (BS-新117 限制 1)',
|
|
source: 'drift/R17',
|
|
crossRefs: ['decisions/0002-form-create-ai-4-limitations'],
|
|
},
|
|
{
|
|
id: 'AP-fc-3',
|
|
severity: 'P1',
|
|
wrong: 'f_create_time (datetime 必填)',
|
|
right: 'f_create_time (datetime 必填 datePicker 列 format=yyyy-MM-dd HH:mm:ss)',
|
|
rationale: '列缺 format 时显示 ISO 时间戳 (BS-新117 限制 2)',
|
|
source: 'drift/R17',
|
|
crossRefs: ['decisions/0002-form-create-ai-4-limitations'],
|
|
},
|
|
{
|
|
id: 'AP-fc-4',
|
|
severity: 'P0',
|
|
wrong: '1 句话建多表 (含 FK 字段)',
|
|
right: '拆步: 先建被关联表 (不含 FK), 再 form update --fields 补 FK',
|
|
rationale: '主表先建时 FK 字段无 modelId, step machine 校验失败',
|
|
source: 'drift/R17',
|
|
crossRefs: ['decisions/0007-dacli-form-ai-not-in-dependency'],
|
|
},
|
|
{
|
|
id: 'AP-fc-5',
|
|
severity: 'P1',
|
|
wrong: '--tables 简化版 (缺 use*Permission 等关键字段)',
|
|
right: '传完整 JSON (含 usePermission/createPermission 等 16+ 字段)',
|
|
rationale: 'dacli 自动推导的 --tables 简化版会报 "Database exception"',
|
|
source: 'blindspots/BS-48',
|
|
},
|
|
{
|
|
id: 'AP-fc-6',
|
|
severity: 'P0',
|
|
wrong: 'AI 描述未提 FK 处理',
|
|
right: 'AI 描述结尾加 "本表不建FK字段"',
|
|
rationale: '物理表缺 varchar FK 列, form POST 报 "Field cannot be empty"',
|
|
source: 'drift/R17',
|
|
crossRefs: ['decisions/0003-form-update-fields-no-alter-table'],
|
|
},
|
|
{
|
|
id: 'AP-fc-7',
|
|
severity: 'P1',
|
|
wrong: '--enCode 含 - / _ / 空格 / 括号',
|
|
right: 'camelCase 无下划线, 例: tdsmyform / tdscompetition',
|
|
rationale: 'BS-56 正则 `[一-龥a-z0-9]+` 严格, 不允许这些字符',
|
|
source: 'drift/R12 BS-新38',
|
|
},
|
|
{
|
|
id: 'AP-fc-8',
|
|
severity: 'P0',
|
|
wrong: '建表后未跑 dacli form info 验证',
|
|
right: '必跑 `dacli form info <enCode>` 验证 4 项 (字段数/jnpfKey/relationForm/required)',
|
|
rationale: 'BS-新117 4 限制入生产会报 "Field cannot be empty"',
|
|
source: 'drift/R17',
|
|
crossRefs: ['decisions/0002-form-create-ai-4-limitations'],
|
|
},
|
|
],
|
|
'form update': [],
|
|
'form info': [],
|
|
'form delete': [],
|
|
'menu create': [],
|
|
'dict typeCreate': [],
|
|
'workflow create': [],
|
|
'dm create': [],
|
|
'di create': [],
|
|
'test run': [],
|
|
'app context': [],
|
|
}
|