Add C linter/formatter (clang-format + clang-tidy) to CI - #27
Merged
Conversation
- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
lint-cGitHub Actions job to lint and format the C sources of the PHP extension, alongside the existing PHP test matrix..clang-formatconfig 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/.hfiles soclang-format --dry-run --Werrorpasses immediately. The CI step runs the dry-run check..clang-tidyconfig with a conservative, Zend-macro-aware check set (bug-finding + performance + readability). Runs against the extension sources listed inconfig.m4using acompile_commands.jsongenerated viabear -- make. Set to report-only (WarningsAsErrorsempty) so the existing, never-tidied code is not blocked — findings surface in CI logs to be addressed over time.lint/test:lintconvention:lint:c:format(writes),test:c:format(check),test:c:tidy(analysis).test:c:formatis wired into thetestaggregator.compile_commands.json(Bear build artifact).Notes on choices (decided with the user)
--Werrorcheck is green from the start rather than failing on pre-existing inconsistencies.bear -- makeis used (one extra apt package in CI) for accurate Zend/PHP include resolution under clang-tidy.Verification
clang-format --dry-run --Werrorover all.c/.hfiles → exit 0 (clean)..clang-tidyparses cleanly under clang-tidy 19; no unknown check names.test:c:formatTaskfile command (find/xargs/clang-format dry-run) → exit 0.bear -- make+clang-tidyend-to-end run requires PHP headers (not present in the sandbox) and is exercised by CI onubuntu-latest.Files
.clang-format,.clang-tidy(new).github/workflows/test.yml(newlint-cjob)Taskfile.yml(new C lint/format tasks).gitignore(ignorecompile_commands.json).c/.hsources reformatted (no logic changes)