Home/Automation & Workflow/embedded-coding-style
E

embedded-coding-style

by @Z1R343L-D77v
4.0(26)

This Skill is designed for embedded C projects, offering MISRA-like coding style governance. It emphasizes strict GB2312 encoding safety, supports selectable scope execution, and provides verifiable rule checks for code style, ensuring project code quality and consistency.

embeddedc-stylecode-qualityautomationmisraGitHub
Installation
npx skills add Z1R343L-D77/embedded-coding-style-codex-skills --skill embedded-coding-style
compare_arrows

Before / After Comparison

1
Before

Without automated tools, embedded C project teams spend significant time on manual code style reviews, checking encoding, brace placement, comment formats, and more. This process is time-consuming, prone to errors, leads to inconsistent codebases, and increases maintenance costs.

After

With SkillForge's embedded coding style Skill, teams can automate MISRA-like style checks and corrections, ensuring all code strictly adheres to GB2312 encoding and unified standards. This significantly reduces manual review time, enhancing code quality and development efficiency.

SKILL.md

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:

  1. Driver layer only: <project_root>/<driver_dir>
  2. BSP layer only: <project_root>/<bsp_dir>
  3. App layer only: <project_root>/<app_dir>
  4. Combined subset: any two scopes
  5. 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

  1. Encoding: GB2312 (code page 936), mandatory.
  2. Line ending: CRLF.
  3. File end: one blank line (CRLF+CRLF).
  4. Every .c/.h begins with:
/**
 * @file ...
 * @author  ...
 * @brief ...
 * @version ...
 * @date ...
 *
 * @copyright Copyright (c) 2026
 */
  1. Function doc comment uses /** ... */ and includes @brief @param @retval.
  2. Inline/block explanation comments use /* ... */.
  3. Comment language: Chinese; avoid AI-template phrasing.
  4. Standard headers use <> (e.g. <stdint.h>, <stdio.h>, <string.h>, <math.h>, <stddef.h>).
  5. Project headers use "...".
  6. Header files keep include guard and must contain C++ compatibility block:
#ifdef __cplusplus
extern "C" {
#endif

...

#ifdef __cplusplus
}
#endif
  1. Left brace must be on a new line.
  2. Brace indentation must align with control statement indentation.
  3. Always use braces for single-line bodies:
  • if
  • while
  • else if
  • else
  • (also keep for/switch/do as full blocks)
  1. switch requires default.
  2. Each case must end with explicit break/return (or controlled jump).
  3. Prefer explicit comparisons; avoid implicit truthiness when unclear.
  4. Integer literals should use explicit suffixes where applicable (U, UL).
  5. Macro parameters/expressions require parentheses.
  6. Multi-statement macros require do { ... } while (0).
  7. Minimize global visibility: file-private symbols should be static.
  8. Pointer params should be null-checked before dereference for externally reachable paths.
  9. Avoid magic numbers; extract to macro/constant (prefer existing project style).
  10. Do not alter timing/ISR/state-machine behavior for formatting-only tasks.
  11. Text read/write encoding is mandatory GB2312 (code page 936), no auto-detect, no fallback encoding.
  12. Read path must use strict GB2312 decoding (decoder exception fallback enabled); if decode fails, stop immediately.
  13. Write path must use strict GB2312 encoding (encoder exception fallback enabled); if encode fails, stop immediately and rollback.
  14. 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.
  15. Struct-pointer function parameters must use unified name handle (for example: static void gpio_control_work(GPIO_Control_t *handle)), avoid mixed aliases such as p_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 handle consistently and update in-function references in the same scope.
  • Run strict encoding preflight before first write:
    • Force GB2312 decode 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.
  • Required operation: explicit GB2312 read + explicit GB2312 write for every touched .c/.h file.

Step 4: Brace Normalization

  • Convert control statements to newline brace style.
  • Add missing braces to all single-line if/while/else if/else bodies.
  • 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 #endif of 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):

  1. if/while/else if/else without brace:
rg -n "^\s*(if|while|else\s+if|else)\b" <selected_scope_paths>
  1. C++ guards exist in headers:
rg -n "#ifdef __cplusplus|extern \"C\"|#endif" <selected_scope_paths>
  1. File header presence:
rg -n "^/\*\*|@file|@author|@brief|@version|@date" <selected_scope_paths>
  1. Tail bytes check (13,10,13,10 expected):
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 ',')
}
  1. Spot-check random files for Chinese comment readability.
  2. 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 GB2312 decode/encode throws:
    • Stop immediately.
    • Restore from known-good backup.
    • Re-apply rules with explicit strict GB2312 read/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.

User Reviews (0)

Write a Review

Effect
Usability
Docs
Compatibility

No reviews yet

Statistics

Installs120
Rating4.0 / 5.0
Version
Updated2026年5月6日
Comparisons1

User Rating

4.0(26)
5
77%
4
15%
3
4%
2
4%
1
0%

Rate this Skill

0.0

Compatible Platforms

🤖claude-code

Timeline

Created2026年5月6日
Last Updated2026年5月6日