gatelight 0.39.1 → 0.40.1

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gatelight",
3
3
  "displayName": "gatelight",
4
- "version": "0.39.1",
4
+ "version": "0.40.1",
5
5
  "description": "Gates for coding agents: tests actually ran before code lands, code stays inside its module boundaries, standards (types, lint, format, secrets) are not quietly loosened, plus test-writing conventions and a change-triggered checklist",
6
6
  "author": {
7
7
  "name": "coffeecoproject"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gatelight",
3
3
  "displayName": "gatelight",
4
- "version": "0.39.1",
4
+ "version": "0.40.1",
5
5
  "description": "Gates for coding agents: tests actually ran before code lands, code stays inside its module boundaries, standards (types, lint, format, secrets) are not quietly loosened, plus test-writing conventions and a change-triggered checklist",
6
6
  "author": {
7
7
  "name": "coffeecoproject"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gatelight",
3
- "version": "0.39.1",
3
+ "version": "0.40.1",
4
4
  "description": "Gates for coding agents: tests actually ran before code lands, code stays inside its module boundaries, standards (types, lint, format, secrets) are not quietly loosened, plus test-writing conventions and a change-triggered checklist",
5
5
  "author": {
6
6
  "name": "coffeecoproject"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gatelight",
3
- "version": "0.39.1",
3
+ "version": "0.40.1",
4
4
  "description": "Gates for coding agents: tests actually ran before code lands, code stays inside its module boundaries, standards (types, lint, format, secrets) are not quietly loosened, plus test-writing conventions and a change-triggered checklist",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/coffeecoproject/gatelight#readme",
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: setup-codekeep
3
- description: 给项目接入 codekeep:确认已接入 testpace、testpace 的 ignore 没盖住规范配置;按项目现有的工具配好严格类型、lint(长度和复杂度上限、"这里不查"的注释要写理由)、格式检查,有前端代码的加上前端规则(页面不加说明文字、不写样式和具体的值去补),旧代码超标的改到全过(不用批量豁免);写 .codekeep/config.json,把规范检查从 full 挪过来;没装 gitleaks 的问用户要不要装;跑一次 codekeep check 和整组。用户要给项目接入 codekeep、或给已接入的项目加前端规则时使用。
3
+ description: 给项目接入 codekeep:确认已接入 testpace、testpace 的 ignore 没盖住规范配置;按项目现有的工具配好严格类型、lint(长度和复杂度上限、"这里不查"的注释要写理由)、格式检查,有前端代码的加上前端规则(不写样式和具体的值去补;页面不加说明文字只提示),旧代码超标的改到全过(不用批量豁免);写 .codekeep/config.json,把规范检查从 full 挪过来;没装 gitleaks 的问用户要不要装;跑一次 codekeep check 和整组。用户要给项目接入 codekeep、或给已接入的项目加前端规则时使用。
4
4
  ---
5
5
 
6
6
  # 接入 codekeep
@@ -78,7 +78,7 @@ codekeep 管代码本身的规范:类型查得严不严、lint 和格式检查
78
78
 
79
79
  ## 有前端代码的项目:前端规则
80
80
 
81
- 只管两件事:页面上不加没必要的说明文字;用了组件,不在页面里写样式、写具体的值去补。规则是"默认都不准,只放行少数几种":只列不准用的写法列不全,agent 被拦住一种,会换成清单外最近的那种。模板只认 React(JSX),和组件库、界面语言无关:哪些组件、参数放说明,哪些放正文,还有哪些参数能写样式,各家不同,接入时照项目用的组件库的文档填(见第 2 步)。Vue 模板、微信小程序的 wxml、wxss,eslint 管不到,不配。
81
+ 只管两件事:用了组件,不在页面里写样式、写具体的值去补(error,拦下);页面上不加没必要的说明文字(warn,只提示)。文字的字数、标点、是不是说明,要看用途才判断得了,程序只能按位置和长相猜,猜错了会逼着改业务文字(丢掉原因、办法和数据),所以文字规则是警告:`codekeep check` 只把落在这次改到的行上的列出来,不拦。规则是"默认都不准,只放行少数几种":只列不准用的写法列不全,agent 被拦住一种,会换成清单外最近的那种。模板只认 React(JSX),和组件库、界面语言无关:哪些组件、参数放说明,哪些放正文,还有哪些参数能写样式,各家不同,接入时照项目用的组件库的文档填(见第 2 步)。Vue 模板、微信小程序的 wxml、wxss,eslint 管不到,不配。
82
82
 
83
83
  规则模板在这个技能目录的 [frontend.eslint.mjs](frontend.eslint.mjs):复制到项目里(比如 `eslint.frontend.mjs`),改好开头"按项目填"的几项,在 eslint 配置里 `...frontend` 接进去。模板用到 `@eslint-community/eslint-plugin-eslint-comments`(上一节"这里不查"的注释要写理由时已经装了)。项目自己的配置里也用了 `no-restricted-syntax` 的,同一个文件只认最后一份,要把两边的条目合进一份。
84
84
 
@@ -100,7 +100,7 @@ codekeep 管代码本身的规范:类型查得严不严、lint 和格式检查
100
100
  - 放正文的(按正文算,一句,字数上限比名字宽):`NOTICE_CALLS`(提示)、`CONFIRM_CALLS`(确认框;用 hook 拿实例、起了别的名字的按项目里的名字加)、`RULE_MESSAGES`(表单校验没过时的那一句)、`ENTRY_PROPS`、`ENTRY_CHILDREN`(确认框、出错、空状态组件的正文)。
101
101
  - 写样式的:`STYLE_PROPS`(`style`、`className` 以外能写样式、改布局的参数,比如 `sx`、`css`、`styles`、栅格的 `offset`,一个都不能漏:漏了 agent 就会换到那里写)、`UI_CLASS_PROPS`(组件层里也能指向同目录样式文件的)、`THEME_PROVIDERS`(主题提供者)。
102
102
  - 显示出来的文字参数:`TEXT_PROPS`(`[组件名, 参数名]`,比如按钮、弹窗上的 `okText`)、`TEXT_ANY`(这个库里不管哪个组件上都是显示文字的参数名)。`title`、`label`、`placeholder` 已经算了。没列的参数里的文字不查。
103
- - 管外观的参数:`VALUE_PROPS`(`[组件名, 参数名]`,比如间距、头像尺寸、栅格宽度、弹窗宽度、标签颜色)、`VALUE_ANY`(这个库里所有组件上都只管外观的参数名)。里面写死的数字、颜色、长度会报,写组件给的档位(`size="small"`)不报。原生元素上的 `width`、`height`、`fill` 这类已经算了。只照文档写明管外观的填,分页大小、小数位数、选项的值这类不填。
103
+ - 管外观的参数:`VALUE_PROPS`(`[组件名, 参数名]`,比如间距、头像尺寸、栅格宽度、弹窗宽度、标签颜色)、`VALUE_ANY`(这个库里所有组件上都只管外观的参数名)。里面写死的数字、颜色、长度会报,写组件给的档位(`size="small"`)不报。SVG 元素上的 `fill`、`stroke` 这类已经算了;原生元素的 `width`、`height`、`size` 不算(`canvas` 的是分辨率,`img` 的是固有尺寸,`input` 的是字数)。只照文档写明管外观的填,分页大小、小数位数、选项的值这类不填。
104
104
  - `UI_LANGUAGE`:页面文字用的语言,写 `LANGUAGES` 里的一套(`'zh'`、`'en'`),不写模板会报错。别的语言照这两套在 `LANGUAGES` 里加一套:认得出是给人看的文字的正则(不能把标识符、URL、样式类名认成文字)、按字还是按词数、名字和正文里不准的标点、上限。上限是默认值,不用改。几种语言的界面,写主要那种。
105
105
  3. **写进 `.codekeep/config.json`**:
106
106
 
@@ -109,7 +109,7 @@ codekeep 管代码本身的规范:类型查得严不严、lint 和格式检查
109
109
  ```
110
110
 
111
111
  `theme` 是主题文件,`ui` 是组件层目录,从仓库根目录写起,几个应用各写各的。以后主题文件、组件层目录里的样式文件(`.css`、`.less`、`.scss` 这类)新加、删掉、改了,整组都要用户在弹窗里同意,按行列出原来和现在;组件层里别的文件(组件代码、取数)改了不问。会话开始时 agent 也会听到前端的约定。
112
- 4. **旧代码**:模板给页面、业务组件、组件层、主题开了 `noInlineConfig`,这些文件里原有的"这里不查"注释(比如 `react-hooks/exhaustive-deps` 的)不再起作用,那几处和旧代码里别的超标的一样照第 5 步改到全过。先用白话告诉用户:这些注释不起作用了,那几处只能改代码。
112
+ 4. **旧代码**:模板给页面、业务组件、组件层、主题开了 `noInlineConfig`,这些文件里原有的"这里不查"注释(比如 `react-hooks/exhaustive-deps` 的)不再起作用,那几处和旧代码里别的超标的一样照第 5 步改到全过。文字规则是警告,旧代码里的文字不用改。先用白话告诉用户:这些注释不起作用了,那几处只能改代码。
113
113
 
114
114
  ## 完成时用白话告诉用户
115
115
 
@@ -119,6 +119,6 @@ codekeep 管代码本身的规范:类型查得严不严、lint 和格式检查
119
119
 
120
120
  配了前端规则的,加一句:
121
121
 
122
- > 页面上的说明文字、页面里写样式和写死的数字,lint 都会拦;颜色、尺寸只能写在主题和组件层的样式里,改它们合并前会弹窗问你。
122
+ > 页面里写样式和写死的数字,lint 会拦;页面上的说明文字只提示,改到的地方 agent 会对着页面看一眼;颜色、尺寸只能写在主题和组件层的样式里,改它们合并前会弹窗问你。
123
123
 
124
124
  有没接上的(没装 gitleaks、项目用 biome 所以 lint 规则没在比、小程序的页面管不到),也在这里说清楚。
@@ -1,9 +1,11 @@
1
1
  // codekeep 的前端规则模板(React,和组件库无关):照 setup-codekeep 技能"有前端代码的项目"一节,复制到项目里(比如 eslint.frontend.mjs),
2
2
  // 改好"按项目填"的几项(组件库那几项照项目用的组件库的文档填),在 eslint.config.mjs 里 `...frontend` 接进去。只用 eslint 自带的 no-restricted-syntax 和 eslint-comments 插件。
3
- // 管两件事:页面上不加说明文字;用了组件不在页面里写样式、写具体的值去补。规则是"默认都不准,只放行少数几种"。
3
+ // 管两件事:用了组件不在页面里写样式、写具体的值去补(拦下);页面上不加说明文字(只提示)。规则是"默认都不准,只放行少数几种"。
4
+ // 文字(字数、标点、放说明的位置)要看用途才判断得了,程序只能按位置和长相猜,猜错了逼着改业务文字,所以是警告,codekeep check 只在改到的行上列出来。
4
5
  // 项目自己的配置里也用了 no-restricted-syntax 的:同一个文件只认最后一份,要把两边的条目合进一份。
5
6
 
6
7
  import comments from '@eslint-community/eslint-plugin-eslint-comments'
8
+ import { builtinRules } from 'eslint/use-at-your-own-risk'
7
9
 
8
10
  // ==== 按项目填 ====
9
11
  /** 前端代码(页面、业务组件、组件层、主题都在里面)。 */
@@ -60,7 +62,7 @@ const DESC_PROPS = []
60
62
  const DESC_ANY = []
61
63
  /** 出错条:[组件名, 级别参数, [出错的级别...], 正文参数]。只准标成这几种级别(级别参数只写一次、不用展开写法),正文按正文算;别的级别是放说明的横幅,不准。 */
62
64
  const ERROR_BANNERS = []
63
- /** 提示:[调用的对象名, [参数对象里放正文的字段...]](toast('…')、notify.error({ message }) 这种),直接写在参数里的文字也算。 */
65
+ /** 提示:[调用的名字, [参数对象里放正文的字段...]](toast('…')、toast.error('…')、notify.error({ message }) 这种),直接写在参数里的文字也算。 */
64
66
  const NOTICE_CALLS = []
65
67
  /** 确认框:[调用的对象名, [方法名...], [参数对象里放正文的字段...]]。用 hook 拿到实例、起了别的名字的,按项目里的名字加。 */
66
68
  const CONFIRM_CALLS = []
@@ -74,7 +76,7 @@ const ENTRY_CHILDREN = []
74
76
  const TEXT_PROPS = []
75
77
  /** 不管哪个组件上都是显示出来的文字的参数名(title、label、placeholder 已经算了,比如 'okText')。 */
76
78
  const TEXT_ANY = []
77
- /** 管外观的参数:[组件名, 参数名](间距、尺寸、栅格宽度、颜色这类),里面不准写具体的数字、颜色和长度,写组件给的档位(size="small")。原生元素上的 width、height 这类已经算了。 */
79
+ /** 管外观的参数:[组件名, 参数名](间距、尺寸、栅格宽度、颜色这类),里面不准写具体的数字、颜色和长度,写组件给的档位(size="small")。SVG 元素上的 fill、stroke 这类已经算了。 */
78
80
  const VALUE_PROPS = []
79
81
  /** 不管哪个组件上都只管外观的参数名(这个库里所有组件上的意思都一样才写)。 */
80
82
  const VALUE_ANY = []
@@ -86,9 +88,11 @@ const UI_CLASS_PROPS = []
86
88
  const THEME_PROVIDERS = []
87
89
  // ==== 按项目填完 ====
88
90
 
89
- /** 原生元素上显示出来的文字参数、管外观的参数(HTML、SVG 标准里的)。 */
91
+ /** 原生元素上显示出来的文字参数(HTML 标准里的)。 */
90
92
  const HTML_TEXT = ['title', 'label', 'placeholder']
91
- const HTML_VALUES = ['width', 'height', 'size', 'color', 'fill', 'stroke', 'strokeWidth', 'fontSize', 'fontWeight', 'opacity']
93
+ // 管外观的只认 SVG 元素上的外观属性。width、height、size 不算:canvas 的是分辨率,img 的是固有尺寸,input、select 的是字数、行数,SVG 的是坐标
94
+ const SVG_ELEMENTS = ['svg', 'g', 'path', 'rect', 'circle', 'ellipse', 'line', 'polyline', 'polygon', 'text', 'tspan', 'use']
95
+ const SVG_VALUES = ['fill', 'stroke', 'strokeWidth', 'opacity', 'fillOpacity', 'strokeOpacity', 'fontSize', 'fontWeight', 'color']
92
96
 
93
97
  const LANG = LANGUAGES[UI_LANGUAGE]
94
98
  if (!LANG) throw new Error(`codekeep 前端规则:UI_LANGUAGE 写 LANGUAGES 里的一套(${Object.keys(LANGUAGES).join('、')}),别的语言先在 LANGUAGES 里加一套`)
@@ -128,7 +132,7 @@ const banners = ERROR_BANNERS.map(([component, levelProp, levels, titleProp]) =>
128
132
  const ENTRY = [
129
133
  ...banners.flatMap(({ title }) => [`${title} > Literal`, ...strings(`${title} > JSXExpressionContainer`)]),
130
134
  ...NOTICE_CALLS.flatMap(([object, fields]) => {
131
- const call = `CallExpression[callee.object.name='${object}']`
135
+ const call = `CallExpression:matches([callee.name='${object}'], [callee.object.name='${object}'])`
132
136
  return [...strings(call), ...strings(`${call} > ObjectExpression > Property[key.name=/^(${names(fields)})$/]`)]
133
137
  }),
134
138
  ...CONFIRM_CALLS.flatMap(([object, methods, fields]) =>
@@ -147,16 +151,16 @@ const ENTRY = [
147
151
  const notEntry = ENTRY.length ? `:not(${ENTRY.join(', ')})` : ''
148
152
  /**
149
153
  * 文字和具体的值只查列明的位置:JSX 文字、子元素里直接写的字符串,列明会显示的参数(HTML_TEXT、TEXT_ANY、TEXT_PROPS),
150
- * 列明管外观的参数(HTML_VALUES、VALUE_ANY、VALUE_PROPS);都含二选一、带条件的写法。
154
+ * 列明管外观的参数(SVG_VALUES、VALUE_ANY、VALUE_PROPS);都含二选一、带条件的写法。
151
155
  * 别处看名字、看长相分不出用途:JSX 外面的变量、对象、函数参数,和没列明的参数(无障碍描述 alt、aria-*,
152
156
  * meta 的 content,表单的值 value,分页大小 pageSize)。哪里都查会把它们当成页面文字和样式,逼着改业务内容。
153
157
  */
154
- const listed = (native, any, props) => [
155
- ...(native.length ? [`JSXOpeningElement[name.name=/^[a-z]/] > JSXAttribute[name.name=/^(${names(native)})$/]`] : []),
158
+ const listed = (native, any, props, elements = '[a-z][\\w-]*') => [
159
+ ...(native.length ? [`JSXOpeningElement[name.name=/^(${elements})$/] > JSXAttribute[name.name=/^(${names(native)})$/]`] : []),
156
160
  ...(any.length ? [`JSXOpeningElement > JSXAttribute[name.name=/^(${names(any)})$/]`] : []),
157
161
  ...props.map(([component, prop]) => `${opening(component)} > JSXAttribute[name.name='${prop}']`),
158
162
  ]
159
- const VALUE_ATTRS = listed(HTML_VALUES, VALUE_ANY, VALUE_PROPS)
163
+ const VALUE_ATTRS = listed(SVG_VALUES, VALUE_ANY, VALUE_PROPS, names(SVG_ELEMENTS))
160
164
  /** 参数里直接写的字符串(attr="…"、attr={'…'},含二选一、带条件的)。 */
161
165
  const inAttrs = attrs => attrs.flatMap(attr => [...strings(attr), ...strings(`${attr} > JSXExpressionContainer`)])
162
166
  const IN_JSX = ['JSXText', ...strings(':matches(JSXElement, JSXFragment) > JSXExpressionContainer'), ...inAttrs(listed([], [...HTML_TEXT, ...TEXT_ANY], TEXT_PROPS))]
@@ -225,7 +229,6 @@ const channels = (allowed = []) => [
225
229
  selector: `JSXAttribute[name.name=/^(${names(['style', 'className', ...STYLE_PROPS].filter(name => !allowed.includes(name)))})$/]`,
226
230
  message: `写样式${STYLE_HINT}`,
227
231
  },
228
- { selector: "JSXOpeningElement[name.name='br']", message: `占位${STYLE_HINT}` },
229
232
  { selector: "JSXElement[children.length=0] > JSXOpeningElement[name.name=/^(div|span)$/][attributes.length=0]", message: `占位${STYLE_HINT}` },
230
233
  ]
231
234
  const fromTests = {
@@ -234,10 +237,13 @@ const fromTests = {
234
237
  }
235
238
 
236
239
  const RESTRICTED = 'no-restricted-syntax'
240
+ // 文字规则用同一个规则换个名字,才能和拦下的那些分开定级别
241
+ const TEXT = 'codekeep/text'
242
+ const textRules = { [TEXT]: ['warn', ...nameText, ...entryText, ...descPlaces] }
237
243
  // noInlineConfig 只让这类注释悄悄失效,这条让写了注释的地方直接报错,agent 才知道要改代码而不是换个写法再关。
238
- const noDisable = { '@eslint-community/eslint-comments/no-restricted-disable': ['error', RESTRICTED] }
244
+ const noDisable = { '@eslint-community/eslint-comments/no-restricted-disable': ['error', RESTRICTED, TEXT] }
239
245
  const front = {
240
- plugins: { '@eslint-community/eslint-comments': comments },
246
+ plugins: { '@eslint-community/eslint-comments': comments, codekeep: { rules: { text: builtinRules.get(RESTRICTED) } } },
241
247
  // 代码里就地关规则、改配置的注释不起作用:要放开只能改配置,codekeep 会问用户
242
248
  linterOptions: { noInlineConfig: true },
243
249
  }
@@ -246,15 +252,13 @@ const front = {
246
252
  const pageRules = {
247
253
  [RESTRICTED]: [
248
254
  'error',
249
- ...nameText,
250
- ...entryText,
251
- ...descPlaces,
252
255
  ...values,
253
256
  fromTests,
254
257
  ...channels(),
255
258
  ...THEME_PROVIDERS.map(component => ({ selector: opening(component), message: `就地改主题${STYLE_HINT}` })),
256
259
  { selector: STYLE_FILE, message: `引样式文件${STYLE_HINT}` },
257
260
  ],
261
+ ...textRules,
258
262
  ...noDisable,
259
263
  }
260
264
 
@@ -269,14 +273,12 @@ export default [
269
273
  rules: {
270
274
  [RESTRICTED]: [
271
275
  'error',
272
- ...nameText,
273
- ...entryText,
274
- ...descPlaces,
275
276
  ...values,
276
277
  fromTests,
277
278
  ...channels(['className', ...UI_CLASS_PROPS]),
278
279
  { selector: `${STYLE_FILE}:not([source.value=/^\\.\\x2F[^\\x2F]+$/])`, message: `只引同目录的样式文件${STYLE_HINT}` },
279
280
  ],
281
+ ...textRules,
280
282
  ...noDisable,
281
283
  },
282
284
  },
@@ -13,7 +13,7 @@ export const LAYERMAP_MINIMUM = '0.1.48'
13
13
 
14
14
  /**
15
15
  * 插件不把命令放进 PATH 的地方怎么有 layermap 命令:Claude Code 把 LayerMap 插件的命令放进它跑命令的 PATH,
16
- * Codex 的命令、终端、git 钩子里没有,要用 LayerMap 自己放的固定入口(LayerMap 0.1.55 起,它运行装着的最高版本)。
16
+ * Codex 的命令、终端、git 钩子里没有,要用 LayerMap 自己放的固定入口(它运行的是本机各个 LayerMap 插件跑的同一版)。
17
17
  * 入口由 LayerMap 放、归它管,这里只说怎么放;各处"找不到命令"的提示都接这一句。
18
18
  */
19
19
  export const LAYERMAP_COMMAND = 'Codex 和终端里还要跑一次 npx layermap setup command,在 ~/.local/bin 放上 layermap 命令'
@@ -27,12 +27,15 @@ export type LayermapFailure = {
27
27
 
28
28
  export type LayermapAnswer = { ok: true; value: unknown } | LayermapFailure
29
29
 
30
- /** 版本太旧的说法:模块在输出里读不到要的字段时也用它。 */
30
+ /**
31
+ * 版本太旧的说法:模块在输出里读不到要的字段时也用它。
32
+ * 新版 LayerMap 自己跟着 npm 的最新版走,只有插件和 setup 放的入口还是旧版时才会太旧,所以这里说的是升一次插件和入口。
33
+ */
31
34
  export function tooOld(): LayermapFailure {
32
35
  return {
33
36
  ok: false,
34
37
  kind: 'old',
35
- problem: `layermap 版本太旧,要 ${LAYERMAP_MINIMUM} 以上:升级 layermap 插件(Claude Code 里是 claude plugin update layermap@layermap),开新会话后再跑`,
38
+ problem: `layermap 版本太旧,要 ${LAYERMAP_MINIMUM} 以上:升级一次 LayerMap 插件(Claude Code 里是 claude plugin marketplace update layermap 再 claude plugin update layermap@layermap,Codex 里是 codex plugin marketplace upgrade layermap),~/.local/bin 的 layermap 命令再跑一次 npx layermap setup command;之后它自己跟着 npm 的最新版更新。开新会话后再跑`,
36
39
  }
37
40
  }
38
41
 
package/src/keep/check.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  // 2. 和分叉点比,规范改松了哪些(loosen.ts、eslint.ts、prettier.ts、tsconfig.ts;biome 只看配置文件改没改),主题、组件层的样式改了哪些(styles.ts)。放松的条目交给底座的用户确认(askUser),
5
5
  // 还没同意的这一段不过,照底座给的话让 agent 调确认工具。分叉点上还没有配置(首次接入)的不比、不问。
6
6
  // 分叉点那一版算不出来的(工具在那一版上跑不起来),不当成没放松,列成"程序看不出"的一项,问。
7
- // 3. 配了 eslint 的,用项目自己的 eslint 程序接口跑一遍 lint,有错误就不过(警告不拦);eslint 起不来时停(环境问题)。不跑项目写的 lint 命令:
7
+ // 3. 配了 eslint 的,用项目自己的 eslint 程序接口跑一遍 lint,有错误就不过;警告不拦,落在这次改到的行上的列成提示;eslint 起不来时停(环境问题)。不跑项目写的 lint 命令:
8
8
  // 命令行会读批量豁免文件(放在哪、叫什么、写成目录都行),从外面猜不全;程序接口不读,查出来的就是代码按规则过没过。
9
9
  // 4. 依次跑 checks 里的每条命令(从仓库根目录用 sh 跑)。
10
10
  // 5. secrets 开着时用 gitleaks 扫这次改动(secrets.ts)。
@@ -16,12 +16,12 @@ import { join } from 'node:path'
16
16
  import { askUser, type ConfirmItem } from '../base/confirm.ts'
17
17
  import { EXIT } from '../base/exit.ts'
18
18
  import { PROJECT_ENV } from '../base/execute.ts'
19
- import { filesNow, forkPoint } from '../base/git.ts'
19
+ import { changesSince, diffLines, filesNow, forkPoint } from '../base/git.ts'
20
20
  import { judgingFile } from '../base/judging.ts'
21
21
  import { hash } from '../base/records.ts'
22
22
  import type { Repo } from '../base/repo.ts'
23
23
  import { type Config, CONFIG_PATH, joined, KEEP_DIR, missingFiles, parseConfig } from './config.ts'
24
- import { eslintItems, type FileRules, fileRules, isCode, lint, type Linted, loadEslint, stable } from './eslint.ts'
24
+ import { eslintItems, type FileRules, fileRules, isCode, lint, type Linted, loadEslint, stable, type Warning } from './eslint.ts'
25
25
  import { withForkTree } from './forktree.ts'
26
26
  import { BIOME_CONFIGS, biomeItem, configItems, GITLEAKS_CONFIG, GITLEAKS_IGNORE, gitleaksItems, removedItem } from './loosen.ts'
27
27
  import { checkedFiles, loadPrettier, prettierItem } from './prettier.ts'
@@ -196,6 +196,32 @@ function askLines(items: ConfirmItem[], ask: string[], reasons: string[]): strin
196
196
  ]
197
197
  }
198
198
 
199
+ /** 提示最多列几条:接入分支上排版改了整个仓库,每一行都算改到的。 */
200
+ const HINTS_SHOWN = 40
201
+
202
+ /** 落在这次改到的行上的警告(和分叉点比,含没提交的)。旧代码上的不列:警告不拦,列出来只为写新代码时看一眼。 */
203
+ function touched(root: string, base: string, warnings: Warning[]): Warning[] {
204
+ if (!warnings.length) return []
205
+ const files = new Set(warnings.map(warning => warning.file))
206
+ const lines = new Map<string, Set<number>>()
207
+ for (const change of changesSince(root, base)) {
208
+ if (change.status === 'D' || !files.has(change.path)) continue
209
+ lines.set(change.path, new Set(diffLines(root, base, change).added.map(added => added.line)))
210
+ }
211
+ return warnings.filter(warning => lines.get(warning.file)?.has(warning.line))
212
+ }
213
+
214
+ // 警告多是前端模板的文字规则:字数、标点、放说明的位置要看用途才判断得了,程序只能猜,所以不拦,交给 agent 看页面判断。
215
+ // 不叫 agent "改到没有警告":猜错的那些改了就是改业务文字(丢掉原因、办法、数据)。
216
+ function hintLines(hints: Warning[]): string[] {
217
+ return [
218
+ '',
219
+ `提示(不拦):这次改到的行上有 ${hints.length} 条警告${hints.length > HINTS_SHOWN ? `,列前 ${HINTS_SHOWN} 条` : ''}:`,
220
+ ...hints.slice(0, HINTS_SHOWN).map(hint => ` ${hint.file}:${hint.line} ${hint.message}`),
221
+ '对着页面看一眼:是说明文字、或者确实写长了的,改;放的是数据、单位、问句、要照录的,不用改。拿不准的不改,也不要为了消掉提示删掉原因、办法和数据。',
222
+ ]
223
+ }
224
+
199
225
  /** 依次跑 checks 里的每条命令,一条没过也接着跑。返回没过的那几条和原因。 */
200
226
  function runChecks(root: string, config: Config): Array<{ name: string; cause: string }> {
201
227
  const failed: Array<{ name: string; cause: string }> = []
@@ -285,6 +311,8 @@ export async function check(repo: Repo): Promise<number> {
285
311
  console.log(linted.report)
286
312
  failures.push(`lint 有 ${linted.errors} 个错误(上面列出;批量豁免文件在这里不起作用)`)
287
313
  }
314
+ const hints = touched(root, fork.commit, linted.warnings)
315
+ if (hints.length) console.log(hintLines(hints).join('\n'))
288
316
  }
289
317
 
290
318
  // 4. 规范检查
@@ -329,7 +357,7 @@ export async function check(repo: Repo): Promise<number> {
329
357
  return blocked ? EXIT.usage : EXIT.fail
330
358
  }
331
359
 
332
- const names = [...(linted ? [`lint${linted.warnings ? `,${linted.warnings} 条警告` : ''}`] : []), ...config.checks.map(item => item.name)].join('、')
360
+ const names = [...(linted ? [`lint${linted.warnings.length ? `,${linted.warnings.length} 条警告不拦` : ''}`] : []), ...config.checks.map(item => item.name)].join('、')
333
361
  console.log(`\ncodekeep check:通过。${loosenedLine};规范检查都过了(${names})${config.secrets ? ';这次改动里没扫出密钥' : ''}。`)
334
362
  return EXIT.ok
335
363
  }
@@ -7,7 +7,7 @@
7
7
  // 只比两边都有的文件:这次新加的文件没有"原来"。
8
8
 
9
9
  import { createRequire } from 'node:module'
10
- import { dirname, join } from 'node:path'
10
+ import { dirname, join, relative } from 'node:path'
11
11
  import { pathToFileURL } from 'node:url'
12
12
  import type { ConfirmItem } from '../base/confirm.ts'
13
13
 
@@ -29,8 +29,12 @@ export const isCode = (path: string): boolean => /\.[cm]?[jt]sx?$/.test(path)
29
29
 
30
30
  interface LintMessage {
31
31
  severity: number
32
+ line?: number
33
+ message: string
34
+ ruleId: string | null
32
35
  }
33
36
  interface LintResult {
37
+ filePath: string
34
38
  errorCount: number
35
39
  warningCount: number
36
40
  messages: LintMessage[]
@@ -91,10 +95,17 @@ export async function fileRules(eslint: EslintClass, tree: string, config: strin
91
95
  return result
92
96
  }
93
97
 
94
- /** lint 的结果:错误、警告各几条,有错误时是只列错误的报告。 */
98
+ /** 一条警告:file 相对 root。 */
99
+ export interface Warning {
100
+ file: string
101
+ line: number
102
+ message: string
103
+ }
104
+
105
+ /** lint 的结果:错误几条,有错误时是只列错误的报告;警告逐条给出,由调用方挑这次改到的行。 */
95
106
  export interface Linted {
96
107
  errors: number
97
- warnings: number
108
+ warnings: Warning[]
98
109
  report: string
99
110
  }
100
111
 
@@ -106,7 +117,9 @@ export async function lint(eslint: EslintClass, root: string, config: string, fi
106
117
  const instance = new eslint({ cwd: root, overrideConfigFile: join(root, config) })
107
118
  const results = await instance.lintFiles(files.map(file => join(root, file)))
108
119
  const errors = results.reduce((sum, result) => sum + result.errorCount, 0)
109
- const warnings = results.reduce((sum, result) => sum + result.warningCount, 0)
120
+ const warnings = results.flatMap(result =>
121
+ result.messages.filter(message => message.severity === 1).map(message => ({ file: relative(root, result.filePath), line: message.line ?? 0, message: message.message })),
122
+ )
110
123
  if (errors === 0) return { errors, warnings, report: '' }
111
124
  const onlyErrors = results
112
125
  .filter(result => result.errorCount > 0)
@@ -22,7 +22,7 @@ export function guide(label = '这个仓库', styles?: StylesConfig): string[] {
22
22
  function frontend(styles: StylesConfig): string {
23
23
  const places = [...styles.theme.map(path => `主题 ${path}`), ...styles.ui.map(dir => `组件层 ${dir} 里的样式文件`)].join('、')
24
24
  return [
25
- '5. 前端:页面上不加说明文字;组件不合适时不写样式、不写具体的值去补,告诉用户。',
25
+ '5. 前端:组件不合适时不写样式、不写具体的值去补,告诉用户。页面上不加说明文字:lint 的文字警告只是提示,放的是数据、单位、问句、要照录的不用改,不为消掉警告删掉原因、办法和数据。',
26
26
  `具体的颜色、尺寸只写在${places};要改先在对话里讲清楚改什么、为什么,整组会要用户确认。`,
27
27
  '前端文件里"这里不查"的注释不起作用,lint 报了就改代码。',
28
28
  ].join('')