embedded-coding-style
このスキルは組み込みCプロジェクト向けに設計されており、MISRAライクなコーディングスタイル管理を提供します。厳格なGB2312エンコーディングの安全性を重視し、選択可能なスコープでの実行をサポートし、検証可能なコードスタイルルールチェックを通じて、プロジェクトのコード品質と一貫性を保証します。
npx skills add Z1R343L-D77/embedded-coding-style-codex-skills --skill embedded-coding-styleBefore / After 効果比較
1 组自動化ツールがない場合、組み込みCプロジェクトチームは、エンコーディング、ブレースの配置、コメント形式などを手動でコードスタイルレビューに多くの時間を費やします。このプロセスは時間がかかり、エラーが発生しやすく、コードベースの一貫性が失われ、メンテナンスコストが増加します。
SkillForgeの組み込みコーディングスタイルスキルを使用すると、チームはMISRAライクなスタイルチェックと修正を自動化できます。これにより、すべてのコードがGB2312エンコーディングと統一された標準に厳密に準拠し、手動レビュー時間を大幅に削減し、コード品質と開発効率を向上させます。
name: embedded-coding-style description: "Initialize embedded project context, then apply and verify MISRA-like C coding style rules with selectable scope, ANSI encoding policy, brace policy, header/doc comment policy, and verification checklist."
Embedded Coding Style Skill
Initialize project context first, then apply a strict, repeatable embedded C style policy to selected scope.
Initialization + Scope Selection
Step 0: Initialize Project Context (Mandatory)
Before any edit, initialize the project and gather context:
Get-Location
Get-ChildItem -Path <project_root>
If backup is provided, verify backup path exists before edits.
Step 1: Select Scope (Mandatory)
Choose one scope per run:
- Driver layer only:
<project_root>/<driver_dir> - BSP layer only:
<project_root>/<bsp_dir> - App layer only:
<project_root>/<app_dir> - Combined subset: any two scopes
- Full target: all selected core scopes
Default behavior: if user does not specify scope, use full target scope.
Do not edit outside selected scope.
Hard Rules
- Encoding:
GB2312(code page 936), mandatory. - Line ending:
CRLF. - File end: one blank line (
CRLF+CRLF). - Every
.c/.hbegins with:
/**
* @file ...
* @author ...
* @brief ...
* @version ...
* @date ...
*
* @copyright Copyright (c) 2026
*/
- Function doc comment uses
/** ... */and includes@brief @param @retval. - Inline/block explanation comments use
/* ... */. - Comment language: Chinese; avoid AI-template phrasing.
- Standard headers use
<>(e.g.<stdint.h>,<stdio.h>,<string.h>,<math.h>,<stddef.h>). - Project headers use
"...". - Header files keep include guard and must contain C++ compatibility block:
#ifdef __cplusplus
extern "C" {
#endif
...
#ifdef __cplusplus
}
#endif
- Left brace must be on a new line.
- Brace indentation must align with control statement indentation.
- Always use braces for single-line bodies:
ifwhileelse ifelse- (also keep
for/switch/doas full blocks)
switchrequiresdefault.- Each
casemust end with explicitbreak/return(or controlled jump). - Prefer explicit comparisons; avoid implicit truthiness when unclear.
- Integer literals should use explicit suffixes where applicable (
U,UL). - Macro parameters/expressions require parentheses.
- Multi-statement macros require
do { ... } while (0). - Minimize global visibility: file-private symbols should be
static. - Pointer params should be null-checked before dereference for externally reachable paths.
- Avoid magic numbers; extract to macro/constant (prefer existing project style).
- Do not alter timing/ISR/state-machine behavior for formatting-only tasks.
- Text read/write encoding is mandatory
GB2312(code page 936), no auto-detect, no fallback encoding. - Read path must use strict
GB2312decoding (decoder exception fallback enabled); if decode fails, stop immediately. - Write path must use strict
GB2312encoding (encoder exception fallback enabled); if encode fails, stop immediately and rollback. - Remove obvious AI-style comments (for example:
/* global variable with static scope */); rewrite as natural engineering comments that describe current module intent/context, not generic coding slogans. - Struct-pointer function parameters must use unified name
handle(for example:static void gpio_control_work(GPIO_Control_t *handle)), avoid mixed aliases such asp_ctrl/p_xxx.
Execution Procedure
Step 2: Pre-check Files in Selected Scope
Enumerate selected files only:
Get-ChildItem -Path <selected_scope_paths> -Recurse -File
Step 3: Safe Edit Strategy
- Edit in small passes (headers first, then braces, then comments).
- Avoid broad regex that can touch function comments repeatedly.
- For file header replacement, replace only the first top-of-file block comment.
- During comment cleanup, rewrite AI-template comments into natural project comments; preserve technical meaning and avoid repetitive rule-recitation wording.
- During signature cleanup, rename struct-pointer parameters to
handleconsistently and update in-function references in the same scope. - Run strict encoding preflight before first write:
- Force
GB2312decode for source text (code page 936). - Decoder fallback must be exception-based; any decode error means immediate stop.
- Do not switch to UTF-8/UTF-16/other encodings as fallback.
- Force
- Required operation: explicit
GB2312read + explicitGB2312write for every touched.c/.hfile.
Step 4: Brace Normalization
- Convert control statements to newline brace style.
- Add missing braces to all single-line
if/while/else if/elsebodies. - Ensure opening brace indent equals control-statement indent.
Step 5: Header/C++ Guard Normalization
- Keep include guard.
- Ensure exactly one open C++ block and one close C++ block.
- Place close C++ block immediately before final
#endifof include guard.
Step 6: Include Normalization
- Convert standard C headers from
"x.h"to<x.h>. - Keep project headers in
"x.h".
Step 7: Final Newline + Encoding Pass
- Normalize newline to CRLF.
- Trim trailing blank noise.
- Force final
CRLF+CRLF. - Write using
GB2312(code page 936) with strict encoder fallback (exception on unmappable chars).
Verification Checklist
Run and confirm all are clean (within selected scope only):
if/while/else if/elsewithout brace:
rg -n "^\s*(if|while|else\s+if|else)\b" <selected_scope_paths>
- C++ guards exist in headers:
rg -n "#ifdef __cplusplus|extern \"C\"|#endif" <selected_scope_paths>
- File header presence:
rg -n "^/\*\*|@file|@author|@brief|@version|@date" <selected_scope_paths>
- Tail bytes check (
13,10,13,10expected):
Get-ChildItem <selected_scope_paths> -Recurse -File | ForEach-Object {
$b=[IO.File]::ReadAllBytes($_.FullName)
$tail=if($b.Length -ge 4){$b[($b.Length-4)..($b.Length-1)]}else{$b}
"{0}:{1}" -f $_.FullName,($tail -join ',')
}
- Spot-check random files for Chinese comment readability.
- Encoding safety check:
rg -n "\?\?\?|\uFFFD" <selected_scope_paths>
Result must be empty for newly changed content.
Recovery / Rollback
- If text becomes mojibake or strict
GB2312decode/encode throws:- Stop immediately.
- Restore from known-good backup.
- Re-apply rules with explicit strict
GB2312read/write configuration.
- Never perform non-GB2312 encode/decode cycles.
- Do not continue batch edits after detecting corruption or codec exception.
- If strict GB2312 preflight fails, only allow byte-level operations (copy/backup/line-ending check), no semantic rewrite.
Success Criteria
- All files in selected scope comply with Hard Rules.
- No mojibake/no
?replacement damage in Chinese comments. - No unintended behavior changes.
- Diff is style-focused and reviewable.
ユーザーレビュー (0)
レビューを書く
レビューなし
統計データ
ユーザー評価
この Skill を評価