skills/check-test-code-quality/rules/R021/SKILL.md
# R021: hypium版本号>=1.0.26 ## 规则信息 | 属性 | 值 | |------|-----| | 规则编号 | R021 | | 问题类型 | hypium版本号不满足要求 | | 严重级别 | Critical | | 规则复杂度 | simple | | 扫描范围 | 独立XTS工程根目录下的 `oh-package.json5` | | testcase字段 | `-`(配置文件,不在it()块内) | ## 问题描述 一个独立XTS工程的 `oh-package.json5` 文件中,`devDependencies` 下的 `"@ohos/hypium"` 字段值必须 >= `1.0.26`。 ## 修复建议 将 `"@ohos/hypium"` 的版本号升级到 `1.0.26` 或以上。 ## 修复建议格式 ``` 路径: {文件路径}, 行号: {行号}, 问题描述: 在独立XTS工程 '{工程名称}' 中,oh-package.json5的devDependencies.@ohos/hypium版本号为 '{当前版本}',低于最
npx skillsauth add openharmonyinsight/openharmony-skills skills/check-test-code-quality/rules/R021Install 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.
| 属性 | 值 |
|------|-----|
| 规则编号 | R021 |
| 问题类型 | hypium版本号不满足要求 |
| 严重级别 | Critical |
| 规则复杂度 | simple |
| 扫描范围 | 独立XTS工程根目录下的 oh-package.json5 |
| testcase字段 | -(配置文件,不在it()块内) |
一个独立XTS工程的 oh-package.json5 文件中,devDependencies 下的 "@ohos/hypium" 字段值必须 >= 1.0.26。
将 "@ohos/hypium" 的版本号升级到 1.0.26 或以上。
路径: {文件路径}, 行号: {行号}, 问题描述: 在独立XTS工程 '{工程名称}' 中,oh-package.json5的devDependencies.@ohos/hypium版本号为 '{当前版本}',低于最低要求版本 1.0.26。
复用R011的独立XTS工程识别逻辑(必须使用修正后的版本,正确处理group类型父BUILD.gn,见R019陷阱6)。
在每个独立XTS工程的根目录下查找 oh-package.json5 文件。注意:
oh-package.json5,不检查 entry/oh-package.json5 或 cpp/*/oh-package.json5 等子目录文件oh-package.json5,跳过该工程在 oh-package.json5 文件中,提取 devDependencies 下 "@ohos/hypium" 的版本号字符串。
关键: 必须跳过注释行。oh-package.json5 支持 // 单行注释,注释掉的依赖不参与检查。
import re
import os
HYPIMUM_PATTERN = re.compile(
r'"@ohos/hypium"\s*:\s*"([^"]+)"'
)
def parse_version(version_str):
parts = version_str.strip().split('.')
result = []
for p in parts:
m = re.match(r'(\d+)', p)
result.append(int(m.group(1)) if m else 0)
while len(result) < 3:
result.append(0)
return tuple(result)
def scan_r021(scan_root, base_dir):
MIN_VERSION = (1, 0, 26)
issues = []
projects = find_independent_projects(scan_root)
for project_dir in projects:
pkg_path = os.path.join(project_dir, 'oh-package.json5')
if not os.path.isfile(pkg_path):
continue
with open(pkg_path, 'r', encoding='utf-8') as f:
lines = f.readlines()
for line_idx, line in enumerate(lines):
stripped = line.strip()
# 跳过注释行(// 开头或全行被注释)
if stripped.startswith('//'):
continue
# 跳过 @ohos/hypium 被注释的情况
# 例如: // "@ohos/hypium": "1.0.21",
code_part = stripped
if '//' in stripped:
# 取 // 之前的部分
code_part = stripped[:stripped.index('//')].strip()
match = HYPIMUM_PATTERN.search(code_part)
if not match:
continue
version_str = match.group(1)
version = parse_version(version_str)
if version < MIN_VERSION:
rel_path = os.path.relpath(pkg_path, base_dir)
rel_project = os.path.relpath(project_dir, base_dir)
line_num = line_idx + 1
issues.append({
'rule': 'R021',
'type': 'hypium版本号不满足要求',
'severity': 'Critical',
'file': rel_path,
'line': line_num,
'testcase': '-',
'snippet': f'"@ohos/hypium": "{version_str}"',
'suggestion': (
f"路径: {rel_path}, 行号: {line_num}, "
f"问题描述: 在独立XTS工程 '{rel_project}' 中,"
f"oh-package.json5的devDependencies.@ohos/hypium版本号为 "
f"'{version_str}',低于最低要求版本 1.0.26。"
),
})
return issues
{
"modelVersion": "6.0.0",
"description": "Please describe the basic information.",
"dependencies": {
},
"devDependencies": {
"@ohos/hypium": "1.0.25" // ✗ 错误:版本低于 1.0.26
}
}
{
"devDependencies": {
"@ohos/hypium": "1.0.6" // ✗ 错误:版本低于 1.0.26
}
}
{
"modelVersion": "6.0.0",
"description": "Please describe the basic information.",
"dependencies": {
},
"devDependencies": {
"@ohos/hypium": "1.0.26" // ✓ 版本号满足最低要求
}
}
{
"devDependencies": {
"@ohos/hypium": "1.0.27" // ✓ 版本号满足最低要求
}
}
oh-package.json5 支持 // 单行注释。被注释掉的 @ohos/hypium 条目不参与检查。
"devDependencies": {
// "@ohos/hypium": "1.0.21", // ← 被注释掉,不检查
}
如果不过滤注释行,会将注释中的旧版本号误报为问题。
判断方法: 行去除首尾空白后以 // 开头,或行内 // 之前的部分不含 @ohos/hypium。
独立XTS工程下可能存在多个 oh-package.json5 文件:
{工程根目录}/oh-package.json5 ← 只检查这个{工程根目录}/entry/oh-package.json5 ← 不检查{工程根目录}/entry/src/main/cpp/types/libxxx/oh-package.json5 ← 不检查大部分工程的版本号为标准semver格式(如 1.0.26),但可能存在非标准格式。解析时只取数字部分进行比较:
def parse_version(version_str):
parts = version_str.strip().split('.')
result = []
for p in parts:
m = re.match(r'(\d+)', p)
result.append(int(m.group(1)) if m else 0)
while len(result) < 3:
result.append(0)
return tuple(result)
部分工程的 oh-package.json5 中可能没有 devDependencies 字段,或者 devDependencies 下没有 "@ohos/hypium" 条目。这种情况下不报错(规则只检查存在的hypium版本号是否满足要求)。
每条issue的字段:
| 字段 | 值 |
|------|-----|
| rule | R021 |
| type | hypium版本号不满足要求 |
| severity | Critical |
| file | 相对路径(如arkui/xxx/oh-package.json5) |
| line | "@ohos/hypium" 所在行号 |
| testcase | - |
| snippet | "@ohos/hypium": "1.0.25" |
| suggestion | 路径: {文件路径}, 行号: {行号}, 问题描述: 在独立XTS工程 '{工程名}' 中,oh-package.json5的devDependencies.@ohos/hypium版本号为 '{版本}',低于最低要求版本 1.0.26。 |
@ohos/hypium 条目不检查entry/oh-package.json5 等子目录文件不检查oh-package.json5 的不检查devDependencies 中无 @ohos/hypium 条目的不检查检查:
oh-package.json5 中,devDependencies.@ohos/hypium 的版本号1.0.26 时报告问题不检查:
oh-package.json5@ohos/hypium 条目的文件全仓扫描结果(版本分布):
- 1.0.26: 2954个工程(合规)
- 1.0.21: 33个工程(不合规,大部分已注释)
- 1.0.6: 18个工程(不合规,部分为活跃依赖如officeservice、web子系统)
- 1.0.24: 4个工程(不合规,如multimedia/av_codec)
- 1.0.25: 3个工程(不合规,如web子系统)
R021与其他配置文件检查规则(R007/Test.json、R010/BUILD.gn、R012/p7b、R017/syscap.json)类似,都是检查工程配置文件中的特定字段值。区别在于:
oh-package.json5(非标准JSON,支持注释和尾逗号)json.loads() 解析,以兼容JSON5格式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