Skip to content

Add C linter/formatter (clang-format + clang-tidy) to CI - #27

Merged
matapatos merged 2 commits into
mainfrom
vibe/c-linter-formatter-619b0a
Sep 10, 2026
Merged

Add C linter/formatter (clang-format + clang-tidy) to CI#27
matapatos merged 2 commits into
mainfrom
vibe/c-linter-formatter-619b0a

Conversation

@matapatos

Copy link
Copy Markdown
Contributor

Summary

  • Adds a new lint-c GitHub Actions job to lint and format the C sources of the PHP extension, alongside the existing PHP test matrix.
  • clang-format (formatter, failing): adds a .clang-format config derived from the repo's existing C style (4-space indent; custom brace wrapping — function braces on a new line, control/struct/enum braces attached) and reformats all .c/.h files so clang-format --dry-run --Werror passes immediately. The CI step runs the dry-run check.
  • clang-tidy (static analyzer, report-only): adds a .clang-tidy config with a conservative, Zend-macro-aware check set (bug-finding + performance + readability). Runs against the extension sources listed in config.m4 using a compile_commands.json generated via bear -- make. Set to report-only (WarningsAsErrors empty) so the existing, never-tidied code is not blocked — findings surface in CI logs to be addressed over time.
  • Adds Taskfile tasks mirroring the existing lint/test:lint convention: lint:c:format (writes), test:c:format (check), test:c:tidy (analysis). test:c:format is wired into the test aggregator.
  • Ignores compile_commands.json (Bear build artifact).

Notes on choices (decided with the user)

  • Tools: clang-format (formatting) + clang-tidy (static analysis), per the chosen options.
  • Reformat strategy: all C/H sources were reformatted (~920 lines across 31 files) so the new --Werror check is green from the start rather than failing on pre-existing inconsistencies.
  • Compile DB: bear -- make is used (one extra apt package in CI) for accurate Zend/PHP include resolution under clang-tidy.

Verification

  • clang-format --dry-run --Werror over all .c/.h files → exit 0 (clean).
  • .clang-tidy parses cleanly under clang-tidy 19; no unknown check names.
  • test:c:format Taskfile command (find/xargs/clang-format dry-run) → exit 0.
  • Workflow YAML and Taskfile YAML validated as well-formed.
  • Note: full bear -- make + clang-tidy end-to-end run requires PHP headers (not present in the sandbox) and is exercised by CI on ubuntu-latest.

Files

  • .clang-format, .clang-tidy (new)
  • .github/workflows/test.yml (new lint-c job)
  • Taskfile.yml (new C lint/format tasks)
  • .gitignore (ignore compile_commands.json)
  • All .c/.h sources reformatted (no logic changes)

mistral-vibe and others added 2 commits September 10, 2026 15:51
- Add .clang-format config derived from the repo's existing C style
  (4-space indent, custom brace wrapping: function braces on a new line,
  control/struct braces attached) and reformat all .c/.h sources so the
  check passes.
- Add .clang-tidy config with a conservative, Zend-macro-aware check set
  (bug-finding + performance + readability). Runs report-only
  (WarningsAsErrors empty) so the un-tidied codebase is not blocked.
- Add a 'lint-c' CI job that checks formatting with clang-format and runs
  clang-tidy against the extension sources using a compile_commands.json
  generated via 'bear -- make'.
- Add Taskfile tasks: lint:c:format, test:c:format, test:c:tidy; wire
  test:c:format into the 'test' aggregator.
- Ignore compile_commands.json.

Co-authored-by: matapatos <matapatos@users.noreply.github.com>
The previous edit placed the 'test' job at top-level indentation instead of
under 'jobs:', so GitHub Actions could not parse the workflow and the run
failed with a workflow-file error. Re-indent 'test:' to nest under 'jobs:'.

Co-authored-by: matapatos <matapatos@users.noreply.github.com>
@matapatos
matapatos marked this pull request as ready for review September 10, 2026 15:59
@matapatos
matapatos merged commit e349f49 into main Sep 10, 2026
1 of 5 checks passed
@matapatos
matapatos deleted the vibe/c-linter-formatter-619b0a branch September 10, 2026 15:59
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.

2 participants