Skip to content

ci: add .clang-format and PR format-check step#139

Open
SoundMatt wants to merge 1 commit into
COVESA:mainfrom
SoundMatt:feat/clang-format-30
Open

ci: add .clang-format and PR format-check step#139
SoundMatt wants to merge 1 commit into
COVESA:mainfrom
SoundMatt:feat/clang-format-30

Conversation

@SoundMatt

Copy link
Copy Markdown
Contributor

Closes #30

Summary

  • .clang-format — captures the style already used in the codebase:

    • 4-space indent, no tabs, 80-column limit
    • BreakBeforeBraces: Linux (function braces on a new line, control-structure braces on the same line)
    • IndentCaseLabels: false (case labels aligned with enclosing switch)
    • SortIncludes: Never (existing include ordering is intentional and must not be disrupted)
  • CI format job — runs only on pull requests; installs clang-format, collects C/H files changed relative to the PR base (git diff --name-only ... | grep -E '\.(c|h)$'), and runs clang-format --dry-run --Werror on them.

    Existing files that a PR does not touch are not checked, so the CI passes immediately without requiring a large reformatting sweep. New or modified files must conform to the style going forward.

Why a PR-scoped check?

A whole-tree format check would fail instantly because the existing code has minor style drift (e.g. mixed spacing around * in pointer declarations). A PR-scoped check enforces style on new contributions without blocking existing work.

Add a .clang-format configuration that captures the existing Open1722
code style:
  - 4-space indent, no tabs
  - Linux brace style (function braces on a new line, control-structure
    braces on the same line as the keyword)
  - case labels at switch indent level (IndentCaseLabels: false)
  - includes are not reordered (SortIncludes: Never)

Add a 'format' job to the GitHub Actions workflow that runs only on
pull requests.  It installs clang-format, collects the C/H files
changed in the PR (via git diff against the PR base), and calls
clang-format --dry-run --Werror on them.  Existing files not touched
by a PR are left unaffected so the CI passes immediately without
requiring a big reformatting sweep.

Signed-off-by: Matt Jones <47545907+SoundMatt@users.noreply.github.com>
@SoundMatt

Copy link
Copy Markdown
Contributor Author

Friendly ping — this PR has been open for 3+ weeks with no review activity. The change is self-contained (adds a .clang-format file and a CI format-check step that enforces the existing code style). Happy to adjust if the approach doesn't fit the project's CI philosophy. Is there a maintainer who could take a look?

@adriaan-niess

Copy link
Copy Markdown
Member

Hi Matt,

Sorry for keeping you waiting. Thanks for having a look at this issues. I'll try to review your PR within this week.

Regards
Adriaan

@adriaan-niess adriaan-niess self-assigned this Jun 15, 2026
@adriaan-niess

adriaan-niess commented Jun 19, 2026

Copy link
Copy Markdown
Member

Hi Matt,

I like the PR and would like to integrate it. The only issue I have is, that the formatting check is assigned to the Build Open1722 workflow (see image below) even though it has nothing to do with the build itself.

My suggestion would be to combine the formatting related checks, that is:

  1. Check SPDX Headers
  2. Check Formatting

under one common workflow. What do you think?

Regards
Adriaan

2026-06-19_11h34_38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Configure a linter for consistent formatting

2 participants