Oh precommit codecheck

From openharmonyinsight/openharmony-skills · View interactive version

Oh precommit codecheck is an AI agent skill from the GitHub repository openharmonyinsight/openharmony-skills. 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"

How to use this skill

Skill file

OH Precommit Codecheck

Run local code quality checks. Includes gate CI checks and additional local-only checks.

Gate CI checks (same as OpenHarmony gate):

Additional local checks (NOT part of gate CI, for extra quality):

Notes

Current limitations

This skill covers a subset of the full OpenHarmony gate CI checks:

Quick Reference

| 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 |

Determine trigger mode

Check whether $ARGUMENTS is set.

Mode 1: User-invoked (`$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:

Steps:

  1. Resolve the file list using the rules above. Filter to only existing files.
  2. Run checks by calling the check script:

```bash

bash ~/.claude/skills/oh-precommit-codecheck/scripts/check.sh <file1> <file2> ...

```

  1. Present results to the user as a concise summary table.
  2. If defects were found and --fix was NOT specified:
  1. If --fix WAS specified and defects were found:

Mode 2: AI auto-trigger (no `$ARGUMENTS`, after completing code changes)

When you have just finished writing or modifying code files, automatically check them.

Steps:

  1. Collect the list of files you just modified in this conversation (from your tool call history — look at Edit/Write calls).
  2. Run checks:

```bash

bash ~/.claude/skills/oh-precommit-codecheck/scripts/check.sh <modified_files...>

```

  1. If 0 defects: silently pass — do not mention the check to the user unless they ask.
  2. If defects found:

a. Auto-fix each defect:

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.

Fix guidelines

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.

Copyright

C/C++ (CodeArts)

Python

Shell

GN

Common Mistakes — NEVER Do

Error Recovery

Example Output

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 个可自动修复。是否修复?
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.