skills/oh-precommit-codecheck/SKILL.md
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.
npx skillsauth add openharmonyinsight/openharmony-skills oh-precommit-codecheckInstall 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.
Run local code quality checks. Includes gate CI checks and additional local-only checks.
Gate CI checks (same as OpenHarmony gate):
/** for C/C++)Additional local checks (NOT part of gate CI, for extra quality):
gn format --dry-run~/.codecheck-tools/pylint, flake8, shellcheck, bashate-mod-ds)compile_commands.json may miss some context-dependent issuesgn in PATHThis skill covers a subset of the full OpenHarmony gate CI checks:
-CPP suffix.| Invocation | Mode | Behavior |
|-----------|------|----------|
| /oh-precommit-codecheck (standalone) | Mode 1 | Check specified files, report results, ask before fixing |
| /oh-precommit-codecheck --fix | Mode 1 | Check and auto-fix up to 3 rounds |
| Auto-triggered by oh-pr-workflow | Mode 2 | Silent check + auto-fix, report only if defects remain |
| Pre-commit hook | Mode 2 | Same as auto-trigger |
Check whether $ARGUMENTS is set.
$ARGUMENTS present or /oh-precommit-codecheck called)Parse $ARGUMENTS to determine file scope and fix mode:
/oh-precommit-codecheck → files from: git diff --cached --name-only
/oh-precommit-codecheck <commit> → files from: git diff-tree --no-commit-id -r <commit> --name-only
/oh-precommit-codecheck <file ...> → the listed files directly
/oh-precommit-codecheck --fix → same file resolution + auto-fix mode
Argument parsing rules:
--fix flag can appear anywhere in argumentsgit rev-parse --verify <arg>), treat it as a commitSteps:
bash ~/.claude/skills/oh-precommit-codecheck/scripts/check.sh <file1> <file2> ...
--fix was NOT specified:
/oh-precommit-codecheck --fix to auto-fix these issues."--fix WAS specified and defects were found:
gn format <file> to auto-format.$ARGUMENTS, after completing code changes)When you have just finished writing or modifying code files, automatically check them.
Steps:
bash ~/.claude/skills/oh-precommit-codecheck/scripts/check.sh <modified_files...>
gn format <file>.
b. Re-run checks to verify fixes.
c. Repeat up to 3 rounds total.
d. If defects remain after 3 rounds, report the unfixable ones to the user.Mode 2 and CLAUDE.md interaction: When triggered as pre-commit hook or by
oh-pr-workflow, Mode 2 auto-fixes to streamline the commit flow. This overrides
the CLAUDE.md "show report first" convention because the user has already expressed
intent to commit. If invoked standalone (/oh-precommit-codecheck without commit
context), default to report-only and ask before fixing.
Below: Reference sections — consult when fixing specific defect types. Skip to "Common Mistakes" if you just need guardrails.
When auto-fixing defects, match the rule to the fix below. If the rule is not listed, read the defect message and apply best judgment.
2025 → 2025-2026).cpp/.c/.h/.hpp files, change first line to /** (block comment style){} around single-line if/for/while/else bodiesNULL / 0 (pointer context) with nullptrconstexpr constant|| exit after cd commands#!/usr/bin/env bash at topgn format <file> — fully automatic, no manual intervention neededgn format on files that fail gn parse — it corrupts the file. Run gn parse first; if it fails, fix syntax manually before formatting.defects.json is non-empty AND engine exited normally.java -version, clang-tidy --version, pylint --version.java -version (requires 11+). Check download integrity: md5sum codecheck-ide-engine.jar. Re-run setup: bash scripts/setup_codecheck.sh --force.gn gen out/default --export-compile-commands or proceed with reduced accuracy.pylint --version and compare with gate CI logs.Typical Mode 1 result:
Codecheck Results (12 defects):
| Rule | Count | File | Auto-fixable |
|------|-------|------|-------------|
| G.FMT.11-CPP | 5 | token_test.cpp | Yes |
| G.NAM.03-CPP | 3 | token_test.cpp | Yes (with context) |
| G.EXP.35-CPP | 2 | token_test.cpp | Yes |
| G.FUN.01-CPP | 1 | token_test.cpp | No — report to user |
| G.FMT.05-CPP | 1 | token_test.cpp | Yes |
发现 12 个告警,其中 11 个可自动修复。是否修复?
testing
--- name: ohos-req-value-decision description: Use after review meeting to record decision and route to next step. Triggers: 评审决策纪要, 评审结论回流, value decision, 评审接纳, 评审不接纳, 评审退回, 下次重新上会. Do NOT use for feature baseline (ohos-req-feature-baseline), review gate checks (ohos-req-review-gate), or IR generation (ohos-req-feature-to-ir). metadata: author: openharmony scope: common stage: requirements capability: value-decision version: 0.3.0 status: draft tags: - sdd - requirements
development
Use when converting an OpenHarmony requirement document, spec, or design proposal into an OpenHarmony review slide deck (需求评审 / 需求变更评审 / 设计评审 PPTX) — produces the fixed OpenHarmony-branded review-deck structure (OH logo on every page) with architecture/flow diagrams and field tables. Triggers on "需求评审PPT", "需求变更评审", "把需求文档转成评审PPT", "spec转评审PPT", "requirement/spec to review deck". NOT for arbitrary or generic slide decks unrelated to OpenHarmony requirement/design review.
testing
Use when performing the Phase 0 Step 0.5 Review Ready Gate on a 04-feature.md, especially when the user says "evaluate gate", "review readiness", "feature ready?", "should we generate IR", or when the ohos-req-intake-orchestration main session needs a structured Ready / Conditional Ready / Not Ready judgment instead of doing the check inline. Reads 01-04, runs seven fixed checks plus a conditional-items check, and returns a machine-readable JSON summary plus a human-readable table that the main session can route on. Do NOT use for feature baseline generation (ohos-req-feature-baseline), value decision recording (ohos-req-value-decision), or IR generation (ohos-req-feature-to-ir).
testing
--- name: ohos-req-requirement-intake description: Use when importing an OHOS requirement into Phase 0.1, especially for 01-requirement.md, requirement intake, background, user value, scenarios, scope, FR/NFR, affected modules, or priority. Triggers: 需求导入, 01-requirement, 需求基线, RR单号. Do NOT use for feasibility analysis (ohos-req-feasibility-analysis), architecture decision (ohos-req-arch-decision), or feature baseline (ohos-req-feature-baseline). metadata: author: openharmony scope: common