Logo van Oh Precommit Codecheck

Oh Precommit Codecheck

Organisatie
openharmonyinsight
oh-precommit-codecheck

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.

Overzicht

Uitgeveropenharmonyinsight
Repositoryopenharmony-skills
Skillnaamoh-precommit-codecheck
Sterren
36
Forks
7
Meegeleverde bestanden
6
Links
  • Instructies in Markdown

    Een SKILL.md-bestand dat het model laadt wanneer nodig, zodat het alleen tokens kost als een verzoek er daadwerkelijk bij past.

  • Werkt met elk LLM

    AI-skills zijn gewone Markdown, geen aanbiederspecifieke code. Daardoor werken ze met GPT, Claude, Gemini, Grok of een lokaal model.

  • 6 meegeleverde bestanden

    Scripts, sjablonen en referentiemateriaal die het model tijdens het werken kan lezen. Bestanden zijn alleen-lezen en worden nooit uitgevoerd.

  • Open source

    Gepubliceerd door openharmonyinsight op GitHub. Lees de broninhoud voordat je de skill installeert.

Installatie

Installeer de AI-skill Oh Precommit Codecheck in TypingMind om deze met elke LLM te gebruiken, of voeg de skill toe aan een andere agent die SKILL.md kan lezen.

1

Installeren in TypingMind

TypingMind installeert een skill rechtstreeks vanuit de GitHub-map — het leest SKILL.md, bundelt de bijbehorende bestanden en slaat het resultaat lokaal op.

  1. Open de app en ga naar Plug-ins → Skills.
  2. Kies "Installeren via GitHub".
  3. Plak de onderstaande URL van de skillmap en bevestig.
    https://github.com/openharmonyinsight/openharmony-skills/tree/main/skills/oh-precommit-codecheck
  4. Schakel de skill in elke chat in waarin je deze beschikbaar wilt hebben.
Plug-ins → Skills → Nieuwe skill → Via GitHub-URL. Plak vervolgens de map-URL en druk op Doorgaan.
2

Installeren in een andere agent

Elke agent die het Agent Skills-formaat kan lezen, kan deze skill gebruiken — kopieer de map naar de skillmap van die agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/openharmonyinsight/openharmony-skills.git /tmp/openharmony-skills
mkdir -p .claude/skills
cp -r /tmp/openharmony-skills/skills/oh-precommit-codecheck .claude/skills/oh-precommit-codecheck
Start Claude Code na het kopiëren opnieuw op, zodat de nieuwe skill wordt herkend.

Gebruik deze skill in TypingMind

Schakel Oh Precommit Codecheck in een willekeurige chat in TypingMind in en het model doet de rest. De naam en beschrijving staan in de systeemprompt. Zodra een verzoek erbij past, laadt het model zelf de volledige instructies — je hoeft de skill nooit handmatig aan te roepen en deze kost pas tokens wanneer je de skill daadwerkelijk gebruikt.

Het model laadt Oh Precommit Codecheck automatisch zodra een verzoek erbij past.

Werkt met elk AI-model

AI-skills zijn gewone Markdown-instructies in plaats van aanbiederspecifieke code. Daardoor is Oh Precommit Codecheck niet gebonden aan het model waarvoor de skill is geschreven. Installeer de skill één keer in TypingMind en gebruik deze met GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama of een lokaal model dat je zelf draait — allemaal met je eigen API-sleutels.

  • Alleen geladen wanneer nodig

    De systeemprompt bevat alleen de naam en beschrijving. De instructies worden bij het eerste bijpassende verzoek opgehaald, dus een ongebruikte skill kost niets.

  • Wissel van model tijdens een chat

    Omdat de skill uit instructies bestaat en niet uit code, blijft deze werken als je van model wisselt — het volgende model leest hetzelfde SKILL.md-bestand.

Skillinstructies

Dit is de inhoud van SKILL.md die het model laadt. Lees deze vóór de installatie — een skill bestaat uit instructies die je model zal volgen.

OH Precommit Codecheck

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

Gate CI checks (same as OpenHarmony gate):

  • Copyright: Header presence, year correctness, comment style (/** for C/C++)
  • C/C++ format: clang-format (clang-format-14 preferred, fallback to clang-format)
  • C/C++ quality: CodeArts Check (codecheck-ide-engine + Huawei clang-tidy: clangtidy + secfinder + fixbot)

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

  • Python: pylint + flake8
  • Shell: shellcheck + bashate-mod-ds
  • GN: gn format --dry-run

Notes

  • First run downloads ~600MB of CodeArts tools to ~/.codecheck-tools/
  • Python/Shell linters must be pre-installed (pylint, flake8, shellcheck, bashate-mod-ds)
  • C/C++ checks without compile_commands.json may miss some context-dependent issues
  • GN format check requires gn in PATH

Current limitations

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

  • Languages: Only C/C++, Python, Shell, GN are checked. Java, JavaScript, TypeScript, ArkTS are NOT yet wired up (the CodeArts engine has rules for them locally).
  • C++ rules: ~114 of ~163 gate G.* rules are covered (~70%). Missing rules are mainly C-language variants without -CPP suffix.
  • Not covered at all: WordsTool sensitive-word checks (~200+ rules), OAT open-source compliance (~10 rules), security-specific checks (weak crypto, unsafe IPSI), code metrics (oversized functions/files/complexity, redundant/duplicate code).
  • Local pass does NOT guarantee gate pass — this is a best-effort pre-filter.

Quick Reference

InvocationModeBehavior
/oh-precommit-codecheck (standalone)Mode 1Check specified files, report results, ask before fixing
/oh-precommit-codecheck --fixMode 1Check and auto-fix up to 3 rounds
Auto-triggered by oh-pr-workflowMode 2Silent check + auto-fix, report only if defects remain
Pre-commit hookMode 2Same 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:

  • --fix flag can appear anywhere in arguments
  • If an argument looks like a git commit (matches git rev-parse --verify <arg>), treat it as a commit
  • Otherwise treat arguments as file paths

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> ...
  3. Present results to the user as a concise summary table.
  4. If defects were found and --fix was NOT specified:
    • Suggest: "Run /oh-precommit-codecheck --fix to auto-fix these issues."
  5. If --fix WAS specified and defects were found:
    • For copyright defects: Fix the copyright header directly (add missing header, update year, change comment style).
    • For C/C++ defects: Read each defective file, understand the rule violation, and fix it directly using the Edit tool.
    • For Python defects: Read each defective file, understand the rule violation, and fix it directly using the Edit tool.
    • For Shell defects: Read each defective file, understand the rule violation, and fix it directly using the Edit tool.
    • For GN format defects: Run gn format <file> to auto-format.
    • After fixing, re-run the check script to verify. Repeat up to 3 rounds.
    • Report any remaining unfixable defects.

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...>
  3. If 0 defects: silently pass — do not mention the check to the user unless they ask.
  4. If defects found: a. Auto-fix each defect:
    • For copyright: Add/update copyright header.
    • For C/C++ mechanical fixes (G.FMT.11-CPP braces, G.EXP.35-CPP nullptr, G.FMT.05-CPP line width): Fix directly.
    • For C/C++ judgment-required (G.NAM.03-CPP naming, G.FUN.01-CPP size): Do NOT auto-fix — report to user.
    • For Python / Shell: Fix standard rules directly, report ambiguous ones.
    • For GN format: Run 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.

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

  • no-copyright: Add the full Apache 2.0 copyright header (see CLAUDE.md for template)
  • wrong-year: Update the year range to include current year (e.g., 2025 → 2025-2026)
  • wrong-comment-style: For .cpp/.c/.h/.hpp files, change first line to /** (block comment style)

C/C++ (CodeArts)

  • G.FMT.11-CPP (braces): Add {} around single-line if/for/while/else bodies
  • G.NAM.03-CPP (naming): Fix variable/function names to match convention
  • G.EXP.35-CPP (nullptr): Replace NULL / 0 (pointer context) with nullptr
  • G.FUN.01-CPP (params): Cannot auto-fix — report to user
  • G.CNS.02-CPP (magic numbers): Extract to named constexpr constant

Python

  • C0304 (final newline): Add trailing newline
  • C0305 (trailing newline): Remove extra trailing blank lines
  • C0321 (multiple statements): Split into separate lines
  • C0410 (multiple imports): One import per line
  • C0411 (import order): Reorder to stdlib → third-party → local
  • Other pylint/flake8 rules: Read the message and fix accordingly

Shell

  • SC2086 (double-quote): Add double quotes around variable expansions
  • SC2164 (cd failure): Add || exit after cd commands
  • SC2148 (shebang): Add #!/usr/bin/env bash at top
  • Other shellcheck rules: Read the message and fix accordingly

GN

  • Run gn format <file> — fully automatic, no manual intervention needed

Common Mistakes — NEVER Do

  • NEVER run gn format on files that fail gn parse — it corrupts the file. Run gn parse first; if it fails, fix syntax manually before formatting.
  • NEVER auto-fix G.FUN.01-CPP (function too long) — requires architectural judgment. Always report to user.
  • NEVER auto-fix G.NAM.03-CPP naming without reading surrounding code — naming conventions depend on context (member variables, global variables, function params have different rules).
  • NEVER trust 0 defects from CodeArts if the engine log shows startup errors — check defects.json is non-empty AND engine exited normally.
  • NEVER assume local tool versions match gate CI — version mismatch causes false negatives. If results differ from gate, check: java -version, clang-tidy --version, pylint --version.
  • NEVER re-run the full check suite if only one checker failed — re-run only the failed checker to save time.

Error Recovery

  • CodeArts engine fails to start: Check java -version (requires 11+). Check download integrity: md5sum codecheck-ide-engine.jar. Re-run setup: bash scripts/setup_codecheck.sh --force.
  • compile_commands.json missing: C++ checks will have ~30% false negative rate. Generate with: gn gen out/default --export-compile-commands or proceed with reduced accuracy.
  • pylint/flake8 version mismatch: Gate uses specific versions. Check with pylint --version and compare with gate CI logs.

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 个可自动修复。是否修复?

Meegeleverde bestanden

Het model leest deze bestanden wanneer nodig terwijl de skill geladen is. Ze worden beschikbaar gesteld als leesbare bestanden en worden nooit uitgevoerd.

Veelgestelde vragen

Wat doet de AI-skill Oh Precommit Codecheck?

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.

Waarom Oh Precommit Codecheck gebruiken in TypingMind?

Omdat je deze skill één keer installeert en met elk model kunt gebruiken. Oh Precommit Codecheck bestaat uit gewone Markdown in plaats van aanbiederspecifieke code. Dezelfde skill werkt dus met GPT-5, Claude, Gemini, Grok of een lokaal model, en je kunt midden in een chat van model wisselen zonder dat de skill niet meer werkt. TypingMind werkt met je eigen API-sleutels, dus je betaalt aanbieders rechtstreeks in plaats van een abonnement per gebruikersplek. Je skills en chats blijven in je eigen opslag.

Hoe installeer ik Oh Precommit Codecheck in TypingMind?

Open Plug-ins → Skills → Installeren vanaf GitHub in TypingMind en plak https://github.com/openharmonyinsight/openharmony-skills/tree/main/skills/oh-precommit-codecheck. TypingMind leest het bestand SKILL.md, bundelt de bijbehorende bestanden en installeert het geheel als een skill die je per chat kunt inschakelen.

Welke AI-modellen kunnen Oh Precommit Codecheck gebruiken?

Elk model dat je in TypingMind koppelt. AI-skills bestaan uit gewone Markdown-instructies in plaats van aanbiederspecifieke code. GPT, Claude, Gemini, Grok en lokale modellen kunnen deze skill dus allemaal laden wanneer een verzoek erbij past.

Hoeveel AI-modellen kan ik met Oh Precommit Codecheck gebruiken?

Zoveel als je wilt. Zolang een model skills ondersteunt, kun je Oh Precommit Codecheck ermee gebruiken: GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama en meer. Allemaal in TypingMind met je eigen API-sleutels.

Is de AI-skill Oh Precommit Codecheck gratis?

Deze skill is door openharmonyinsight op GitHub gepubliceerd. Bekijk de repository voor de licentievoorwaarden. Je betaalt alleen je eigen AI-aanbieder voor de tokens die je gebruikt.

Wat zijn AI-skills?

Een AI-skill is een herbruikbare bundel instructies die een AI-model leert hoe het één specifieke taak moet uitvoeren. Deze volgt het open Agent Skills-formaat: een bestand met de naam SKILL.md met een naam en beschrijving, plus eventuele scripts, sjablonen of referentiebestanden die het model nodig heeft. Het model leest de instructies alleen als je verzoek bij de skill past. Een geïnstalleerde skill kost dus niets zolang deze niet wordt gebruikt.

Waarin verschillen AI-skills van plug-ins of MCP-servers?

Een plug-in of MCP-server geeft een model nieuwe tools om aan te roepen: code die ergens wordt uitgevoerd en een resultaat teruggeeft. Een AI-skill geeft het model juist kennis en een werkwijze: hoe het een taak moet aanpakken, welke stappen het moet volgen en hoe goede uitvoer eruitziet. Skills bestaan uit gewone Markdown en hebben dus geen server, API-sleutel of runtime nodig. Ze werken met elk model.

Toon alles

Maak nu je eigen AI-werkruimte

Schrijf je in voor onze nieuwsbrief en blijf op de hoogte van nieuwe functies en toekomstige weggeefacties 👇