R002: 错误码断言必须是number类型
OfficialPrevent type-mismatch assertions on error codes.
Software Engineering#unit tests#type checking#error codes#OpenHarmony#test code quality#grep/regex rules#assertEqual
Authoropenharmonyinsight
Version1.0.0
Installs0
System Documentation
What problem does it solve?
It prevents test failures and fragile logic caused by asserting OpenHarmony error.code with string literals instead of numbers.
Core Features & Use Cases
- Detect common assertion patterns: flags string-literal usage in expect/assertEqual/assertTrue and if-condition comparisons involving xxx.code.
- Validate numeric-only error codes: only reports cases where the asserted string is a pure numeric literal (e.g., "401", "14000011").
- Supports basic variable tracking: identifies string-typed variables/constants/parameters that are later used to compare against error.code, including catch-block alias cases (e.g., err as error alias).
Quick Start
Use this rule to scan your OpenHarmony test files and automatically list every place where error.code is compared or asserted using numeric strings, then convert those assertions to number literals.
Dependency Matrix
Required Modules
None requiredComponents
Standard package💻 Claude Code Installation
Recommended: Let Claude install automatically. Simply copy and paste the text below to Claude Code.
Please help me install this Skill: Name: R002: 错误码断言必须是number类型 Download link: https://github.com/openharmonyinsight/openharmony-skills/archive/main.zip#r002-number Please download this .zip file, extract it, and install it in the .claude/skills/ directory.
Agent Skills Search Helper
Install a tiny helper to your Agent, search and equip skill from 471,000+ vetted skills library on demand.