feat: Add HarmonyOS support for .ets files and review configurations (#48)

* feat: add .ets file extension support for HarmonyOS development

* feat: add complete HarmonyOS review support with ArkTS rules, .json5 config, and oh_modules exclusion

- Add arkts.md rule doc with ArkTS-specific and TypeScript general checks
- Add .json5 to supported file types for HarmonyOS config files
- Map .json5 to json.md rules in system_rules.json
- Exclude oh_modules/** (HarmonyOS dependency dir) from review
- Exclude *.test.ets (HarmonyOS test files) from review
- Add unit tests for all new extensions and patterns

* refactor: merge json and json5 glob patterns into single brace expansion
This commit is contained in:
Lei Zhang 2026-06-05 12:22:11 +08:00 committed by GitHub
parent 0ac1193040
commit 95c5d5930e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 76 additions and 2 deletions

View file

@ -16,6 +16,10 @@ func TestIsAllowedExt(t *testing.T) {
{".tsx", true},
{".py", true},
{".rs", true},
{".ets", true},
{".ETS", true},
{".json5", true},
{".JSON5", true},
{".txt", false},
{".md", false},
{".png", false},
@ -84,6 +88,12 @@ func TestIsExcludedPath(t *testing.T) {
{"rust test file", "src/parser_test.rs", true},
{"rust non-test", "src/parser.rs", false},
// HarmonyOS oh_modules and test files
{"oh_modules root", "oh_modules/some_lib/index.ets", true},
{"oh_modules nested", "entry/oh_modules/lib/index.ets", true},
{"ets test file", "entry/src/test/Component.test.ets", true},
{"ets non-test", "entry/src/main/Component.ets", false},
// Case insensitive
{"case insensitive go", "Foo/Bar_Test.go", true},
{"case insensitive java", "com/FooTEST.java", true}, // lowercase → "com/footest.java" matches "**/*test.java"

View file

@ -12,5 +12,7 @@
"**/spec/**/*_spec.rb",
"**/*Test.java",
"**/*Tests.java",
"**/*_test.rs"
"**/*_test.rs",
"**/oh_modules/**",
"**/*.test.ets"
]

View file

@ -62,6 +62,8 @@
".exs",
".erl",
".hrl",
".ets",
".json5",
".dart",
".tf"
]

View file

@ -0,0 +1,55 @@
#### 明确的错别字或拼写错误
- 组件名、变量名、函数名中的拼写错误
- 日志或错误信息中影响阅读理解的拼写错误
#### 死代码
- 永远不会被执行到的代码块(如条件恒为 false 的分支、return 语句后的代码)
- 声明后从未被读取或引用的变量
- 已注释掉的大段代码块(无明显保留意图的注释代码)
#### 状态装饰器使用
- `@State` 修饰的数组/对象通过 push/属性修改不会触发 UI 刷新,必须替换引用
- `@Prop`(单向)与 `@Link`(双向)使用场景是否正确
- 嵌套对象状态更新必须配合 `@Observed` + `@ObjectLink`
- 超过 3 层 props 传递应使用 `@Provide/@Consume` 替代
- `@StorageLink/@StorageProp` 仅用于真正的全局状态,避免滥用
#### 组件生命周期
- `aboutToAppear` 中创建的定时器、监听器必须在 `aboutToDisappear` 中释放
- 页面级逻辑应放在 `onPageShow/onPageHide` 而非组件生命周期中
- 避免在生命周期中执行耗时同步操作阻塞 UI 线程
#### ArkUI 声明式语法
- 禁止在 `build` 方法中执行副作用(网络请求、定时器、日志打印)
- `ForEach` / `LazyForEach` 必须提供唯一且稳定的 key 生成函数
- 条件渲染使用 `if/else`,不使用 `switch`
- 禁止在 `build` 方法外直接操作组件实例
#### 性能优化
- 大列表(>20项必须使用 `LazyForEach` 替代 `ForEach`
- 禁止在 `build` 方法中创建新对象、闭包或调用函数返回样式,会导致子组件不必要重建
- 复杂计算结果应通过 `@Watch` 缓存,避免每次渲染重复计算
- 图片资源应设置合理缓存策略,避免重复加载
#### 资源访问规范
- 字符串禁止硬编码,必须使用 `$r('app.string.key')` 支持国际化
- 图片使用 `$r('app.media.icon')``$rawfile('path')`,禁止硬编码路径
- 颜色/尺寸使用资源引用 `$r('app.color.primary')` 支持主题切换
#### 组件通信
- 父→子用 `@Prop`/`@Link`,子→父用回调函数 `onEvent` 模式
- 跨组件通信用 `@Provide/@Consume`,全局状态用 `AppStorage`
- 避免通过 `AppStorage` 传递组件间局部状态
#### TypeScript 通用规范
- 禁止使用 `any` 类型,如必须使用需注释说明原因
- 禁止使用 `var`,必须使用 `let``const`
- 禁止使用 `==``!=`,必须使用 `===``!==`
- 异步函数必须包含 try-catch 错误处理,提供用户友好的错误提示
- 优先使用 async/await禁止回调地狱独立异步操作用 `Promise.all` 并行
- 空值判断:取值或解构赋值时进行空值判断,避免空指针异常
#### 代码安全性检查
- 用户输入必须校验(长度、格式、范围),禁止直接拼接到 SQL 或命令字符串
- 敏感信息密钥、密码、token禁止打印到日志或上传
- 网络请求必须使用 HTTPS 并验证证书

View file

@ -6,9 +6,10 @@
"**/pom.xml": "pom_xml.md",
"**/build.gradle": "build_gradle.md",
"**/package.json": "package_json.md",
"**/*.json": "json.md",
"**/*.{json,json5}": "json.md",
"**/*.{yaml,yml}": "yaml.md",
"**/*.java": "java.md",
"**/*.ets": "arkts.md",
"**/*.{ts,js,tsx,jsx}": "ts_js_tsx_jsx.md",
"**/*.{kt}": "kotlin.md",
"**/*.{cpp,cc,hpp}": "cpp.md",

View file

@ -72,6 +72,10 @@ func TestResolve_DefaultRules(t *testing.T) {
{"app.kt", "空安全"},
{"src/main/handler.cpp", "智能指针"},
{"driver.c", "malloc"},
{"pages/Index.ets", "状态装饰器"},
{"components/Button.ets", "状态装饰器"},
{"entry/src/main/module.json5", "json-key"},
{"entry/oh-package.json5", "json-key"},
}
for _, tt := range tests {