skills/check-test-code-quality/rules/R020/SKILL.md
# R020: .id重复 ## 规则信息 | 属性 | 值 | |------|-----| | 规则编号 | R020 | | 问题类型 | .id重复 | | 严重级别 | Critical | | 规则复杂度 | complex | | 扫描范围 | 同一独立XTS工程内的所有源代码文件(`.ets`, `.ts`, `.js`) | | testcase字段 | `-`(.id()不在it()块内) | ## 问题描述 一个独立XTS工程下的页面设计中,`.id()` 的字符串参数值不允许重复。即同一个独立XTS工程中,所有源代码文件里 `.id('xxx')` 的字符串参数值不能重复。 ## 与R019的关系 R020与R019的扫描逻辑完全一致,唯一差异是检测目标属性。两者共享相同的工程级检测基类(见 [references/project_level_scan.md](../../references/project_level_scan.md)),包括: - `find_independent_projects()` — 工程边界识别 - `get_pr
npx skillsauth add openharmonyinsight/openharmony-skills skills/check-test-code-quality/rules/R020Install this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
| 属性 | 值 |
|------|-----|
| 规则编号 | R020 |
| 问题类型 | .id重复 |
| 严重级别 | Critical |
| 规则复杂度 | complex |
| 扫描范围 | 同一独立XTS工程内的所有源代码文件(.ets, .ts, .js) |
| testcase字段 | -(.id()不在it()块内) |
一个独立XTS工程下的页面设计中,.id() 的字符串参数值不允许重复。即同一个独立XTS工程中,所有源代码文件里 .id('xxx') 的字符串参数值不能重复。
R020与R019的扫描逻辑完全一致,唯一差异是检测目标属性。两者共享相同的工程级检测基类(见 references/project_level_scan.md),包括:
find_independent_projects() — 工程边界识别get_project_source_files() — 递归源文件收集collect_attr_values() — 属性值提取find_duplicate_groups() — 重复检测| 属性 | R019 | R020 |
|------|------|------|
| 检测目标 | .key('xxx') | .id('xxx') |
| 正则 | \.key\s*\(\s*(["\'])([^"\']+)\1\s*\) | \.id\s*\(\s*(["\'])([^"\']+)\1\s*\) |
| 问题描述 | .key重复 | .id重复 |
import re
ID_PATTERN = re.compile(
r'\.id\s*\(\s*(["\'])([^"\']+)\1\s*\)',
re.MULTILINE
)
find_independent_projects(),见 references/project_level_scan.mdos.walk),见 get_project_source_files()collect_attr_values(project_dir, source_files, base_dir, ID_PATTERN)find_duplicate_groups(items)def scan_r020(scan_root, base_dir):
issues = []
projects = find_independent_projects(scan_root)
for project_dir in projects:
source_files = get_project_source_files(project_dir)
if not source_files:
continue
ids = collect_attr_values(project_dir, source_files, base_dir, ID_PATTERN)
duplicates = find_duplicate_groups(ids)
for dup in duplicates:
rel_project = os.path.relpath(project_dir, base_dir)
other_info = '; '.join(dup['other_locations'])
issues.append({
'rule': 'R020',
'type': '.id重复',
'severity': 'Critical',
'file': dup['first_file'],
'line': dup['first_line'],
'testcase': '-',
'snippet': f".id('{dup['value']}')",
'suggestion': (
f"路径: {dup['first_file']}, 行号: {dup['first_line']}, "
f"问题描述: 在独立XTS工程 '{rel_project}' 中,.id值 "
f"'{dup['value']}' 重复 {dup['count']} 次。"
f"重复位置: {other_info}。"
),
})
return issues
确保.id()的值在工程内唯一。修改重复的id值为有意义的唯一标识。
路径: {文件路径}, 行号: {行号}, 问题描述: 在独立XTS工程 '{工程名称}' 中,.id值 '{id值}' 重复 {重复次数} 次。重复位置: {位置1}, {位置2}, ...
// File1: TestAddCustomProperty.ets(同一独立工程内)
Button('Add')
.id('buttonCustomProperty') // 第一次出现
Text('Custom')
.id('customPropertyValue') // 第一次出现
// File2: TestRemoveCustomProperty.ets(同一独立工程内)
Button('Remove')
.id('buttonCustomProperty') // 错误:与File1重复
Text('RemoveCustom')
.id('customPropertyValue') // 错误:与File1重复
// File1: TestAddCustomProperty.ets(同一独立工程内)
Button('Add')
.id('addButtonCustomProperty') // id值唯一
Text('Custom')
.id('addCustomPropertyValue') // id值唯一
// File2: TestRemoveCustomProperty.ets(同一独立工程内)
Button('Remove')
.id('removeButtonCustomProperty') // id值唯一
Text('RemoveCustom')
.id('removeCustomPropertyValue') // id值唯一
与R019完全一致,详见 rules/R019/SKILL.md 的陷阱章节。
| 字段 | 值 |
|------|-----|
| rule | R020 |
| type | .id重复 |
| severity | Critical |
| file | 相对路径 |
| line | .id()所在行号 |
| testcase | - |
| snippet | .id('customPropertyValue') |
| suggestion | 路径: {文件路径}, 行号: {行号}, 问题描述: 在独立XTS工程 '{工程名}' 中,.id值 '{id值}' 重复 {次数} 次。重复位置: {文件:行号}; ... |
development
Run local code quality checks covering a subset of OpenHarmony gate CI (copyright, CodeArts C/C++) plus additional local checks (pylint/flake8, shellcheck/bashate, gn format). Use before committing to reduce gate failures. Triggers on: /oh-precommit-codecheck, "门禁检查", "门禁预检", "检查代码", "run codecheck", "check code quality", "lint my code", "代码检查", or after completing code implementation. WHEN to use: before git commit, before creating PR, after modifying C/C++/Python/Shell/GN files, when gate CI fails with codecheck defects, or when you want to preview what gate will flag.
development
OpenHarmony PR full lifecycle workflow. Five modes: - Commit: standardized commit with DCO sign-off and Issue linking - Create PR: commit + push to fork + create Issue + create PR on upstream - Fix Codecheck: fetch gate CI codecheck defects from a PR and auto-fix them - Review PR: fetch a PR's changes to local for code review - Fix Review: fetch unresolved review comments from a PR and auto-fix them Triggers on: /oh-pr-workflow, "提交代码", "创建PR", "提个PR", "commit", "修复告警", "修复门禁", "修复codecheck", "fix codecheck", "review pr", "review这个pr", "看下这个pr", "检视pr", "修复review", "修复检视意见", "fix review", or a GitCode PR URL with fix/review intent.
testing
分析 HM Desktop PRD 文档,提取需求信息、验证完整性、检查章节顺序(需求来源→需求背景→需求价值分析→竞品分析→需求描述)、检查 KEP 定义、检测需求冲突并生成结构化分析报告。适用于用户请求:(1) 分析或审查 PRD 文档, (2) 从需求中提取 KEP 列表, (3) 检查 PRD 完整性或一致性, (4) 将需求映射到模块架构, (5) 验证 PRD 格式合规性, (6) 验证竞品分析章节完整性。关键词:PRD分析, requirement extraction, KEP验证, completeness check, chapter order validation, 竞品分析检查, analyze PRD, 需求提取, 完整性检查, 章节顺序验证
development
基于 PRD 文档自动生成鸿蒙系统设计文档,包括架构设计文档和功能设计文档。生成前会分析 OpenHarmony 存量代码结构,确保与现有架构兼容。架构设计文档第2章必须为竞品方案分析,位于需求背景之后。适用于用户请求:(1) 生成架构设计文档, (2) 生成功能设计文档, (3) 从 PRD 生成设计文档, (4) 创建系统架构设计, (5) 编写功能规格说明, (6) 分析 OH 代码结构。关键词:architecture design, functional design, design doc, 竞品方案分析, OpenHarmony code analysis, 架构设计, 功能设计, 设计文档生成, OH代码分析, analyze codebase, competitor analysis