From ff172ed2c1b15a36ebd5266c647ceddedd0e8be5 Mon Sep 17 00:00:00 2001 From: JianFeeeee Date: Sat, 19 Sep 2026 15:22:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A4=E6=8D=AE:=20=E4=BF=AE=20`AmIcon`=20?= =?UTF-8?q?=E5=B0=BA=E5=AF=B8=E6=A3=80=E6=9F=A5=E7=9A=84=E5=81=87=E7=BA=A2?= =?UTF-8?q?=20=E2=80=94=E2=80=94=20=E5=AE=83=E8=B7=A8=E8=BF=87=20`}`=20?= =?UTF-8?q?=E5=90=83=E5=88=B0=E4=BA=86=E4=B8=8B=E4=B8=80=E4=B8=AA=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E4=BF=AE=E9=A5=B0=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 这条判据抓的是真形状(`AmIcon({…}).width(48)` 会让图标贴左上角), 但正则写宽了:`[\s\S]{0,200}?` 允许**跨过 `}`**,于是这种**正确**写法被判红: Row({ space: 4 }) { AmIcon({ … }) Text('新建') } .height(26) ← 这是 Row 的,不是 AmIcon 的 实测(日历工具栏新加的「+ 新建」按钮):报 `CalendarPage.ets:1223 → .height(`, 而那一行链在 `Row` 上。**是判据误报,不是代码错。** 修法:扫描区间**不允许出现 `{`/`}`**。`AmIcon({…}).width(48)` 里参数花括号已被 `)` 收尾,而跨到下一个组件的路径会被排除。 ★ 修完**立刻做了变异验证**(这类放宽最容易顺手把判据改废): 把真实的 `AmIcon({…})` 改成 `AmIcon({…}).width(48)` ⇒ **判红**; 还原 ⇒ 绿。既要"不误报",也要"仍能抓真错",两半都得验。 --- client/electron/test/harmony-arkts.test.mjs | 23 +++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/client/electron/test/harmony-arkts.test.mjs b/client/electron/test/harmony-arkts.test.mjs index 68a3cb3..8fe0874 100644 --- a/client/electron/test/harmony-arkts.test.mjs +++ b/client/electron/test/harmony-arkts.test.mjs @@ -245,8 +245,27 @@ test('★ 尺寸/底色不许直接链在 `AmIcon` 上(内层容器固定 icon if (e.isDirectory()) { walkDir(full); continue; } if (!/\.ets$/.test(e.name)) continue; const src = code(full); - /* `AmIcon({ ... })` 后面直接跟 `.width(` 或 `.height(` */ - for (const m of src.matchAll(/AmIcon\(\{[\s\S]{0,200}?\}\)\s*\.\s*(width|height)\s*\(/g)) { + /* + * `AmIcon({ ... })` 后面直接跟 `.width(` 或 `.height(`。 + * + * ★★ 2026-09-19 修(判据自己撞出来的假红):原先写的是 + * `AmIcon\(\{[\s\S]{0,200}?\}\)\s*\.\s*(width|height)\s*\(` + * —— `[\s\S]{0,200}?` 可以**跨过 `}`**。于是这种**正确**写法被判红: + * + * Row({ space: 4 }) { + * AmIcon({ ... }) + * Text('新建') + * } + * .height(26) ← 这是 Row 的,不是 AmIcon 的 + * + * 实测(日历工具栏的「+ 新建」按钮):报 `CalendarPage.ets:1223 → .height(`, + * 而那一行链在 `Row` 上。 + * + * 修法:扫描区间里**不允许出现 `}` 或 `{`** —— 只有同一表达式内的 + * 换行/空白/参数才算。`AmIcon({…}).width(48)` 里 `{…}` 已被 `\)` 收尾, + * 而跨过 `}` 到下一个组件的路径会被这条排除。 + */ + for (const m of src.matchAll(/AmIcon\(\{[^{}]{0,200}?\}\)\s*\.\s*(width|height)\s*\(/g)) { const line = src.slice(0, m.index).split('\n').length; hits.push(`${e.name}:${line} → .${m[1]}(`); }