FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

build: add clang tidy to enforce modern c++ usage by Miou-zora · Pull Request #591 · EngineSquared/EngineSquared · GitHub

build: add clang tidy to enforce modern c++ usage - #591

Merged
Miou-zora merged 22 commits into
mainfrom
553-build-add-clang-tidy-to-enforce-modern-c-usage
May 2, 2026
Merged

build: add clang tidy to enforce modern c++ usage#591
Miou-zora merged 22 commits into
mainfrom
553-build-add-clang-tidy-to-enforce-modern-c-usage

Conversation

Miou-zora commented May 1, 2026
edited by coderabbitai Bot
Loading

Copy link
Copy Markdown
Contributor

Pull Request

Description

To ensure that the codebase follows good principles like modern usage of cpp, I added clang tidy configuration file with an automatic check inside CI.

Related Issues (Put "None" if there are no related issues)

close #553

Type of Change

Please delete options that are not relevant.

  • Build/CI configuration change

Changes Made

List the main changes in this PR:

  • Added clang tidy config file
  • Add a gate in CI to check the code conformity to clang tidy

Testing

Describe the tests you ran to verify your changes. Please delete options that are not relevant.

  • Unit tests pass (xmake test)

Test Environment

  • OS: macOS
  • Compiler: Clang

Screenshots/Videos (Put "None" if there are no related issues)

None

Documentation

Please delete options that are not relevant.

  • No documentation changes are required

Checklist (Don't delete any options)

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Breaking Changes (Put "None" if there are no related issues)

None

Additional Notes (Put "None" if there are no related issues)

None

Summary by CodeRabbit

  • Chores

    • Enforced stricter static-analysis rules (treat warnings as errors) and scoped checks to source files with repository formatting.
    • Added CI automation to run these static-analysis checks.
    • Aligned internal log level definitions with the logging backend for more consistent log behavior.
  • Bug Fixes

    • Improved cleanup behavior during constraint finalization to reduce errors and improve runtime stability when exceptions occur.

Miou-zora self-assigned this May 1, 2026
Miou-zora linked an issue May 1, 2026 that may be closed by this pull request

coderabbitai Bot commented May 1, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a repository .clang-tidy config and a CI tidy job that installs LLVM/clang-tidy-22 and runs xmake check -y clang.tidy; modifies exception cleanup in ConstraintHelpers.cpp; and makes Log::Level explicitly map to spdlog levels with a simplified conversion.

Changes

Clang-tidy integration & CI

Layer / File(s) Summary
Config (data shape)
.clang-tidy
New root clang-tidy config enabling selected bugprone checks, WarningsAsErrors: "*", HeaderFilterRegex: "^src/", header/implementation extensions (including empty header ext), FormatStyle: file, SystemHeaders: false, empty CheckOptions, User: miouzora.
CI workflow layout / env
.github/workflows/ci.yml
Reformats expressions, rewrites env.UNWANTED_REGEX to a double-quoted, escaped, wrapped form, and adjusts needs arrays formatting.
CI job wiring / execution
.github/workflows/ci.yml
Adds tidy job that installs llvm-22/clang-tidy-22, sets up xmake, and runs xmake check -y clang.tidy using ./.clang-tidy.

Code edits (independent maintenance changes)

Layer / File(s) Summary
Exception cleanup behavior
src/plugin/physics/src/system/ConstraintHelpers.cpp
In FinalizeConstraint, the catch (const std::exception &e) path now directly calls ctx.physicsSystem.RemoveConstraint(joltConstraint); (removed the inner try { ... } catch (...) {} suppression wrapper) before logging and releasing joltConstraint.
Log level enum / mapping
src/utils/log/src/Logger.hpp
Log::Level enumerators assigned explicitly to spdlog::level::level_enum constants; Log::ToSpdlogLevel simplified to static_cast conversion.

Sequence Diagram(s)

sequenceDiagram
    participant Contributor as "Contributor / PR"
    participant GitHub as "GitHub Actions"
    participant Runner as "CI Runner"
    participant Apt as "apt (package manager)"
    participant Xmake as "xmake"
    participant ClangTidy as "clang-tidy-22"

    Contributor->>GitHub: push PR
    GitHub->>Runner: start workflow (ci.yml)
    Runner->>Apt: install llvm-22 and clang-tidy-22
    Apt-->>Runner: packages installed
    Runner->>Xmake: run `xmake check -y clang.tidy`
    Xmake->>ClangTidy: invoke checks using `./.clang-tidy`
    ClangTidy-->>Xmake: diagnostics (warnings → errors)
    Xmake-->>Runner: exit code (pass/fail)
    Runner-->>GitHub: workflow result
    GitHub-->>Contributor: status (success/failure)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐇 I hopped through configs, tidy and bright,
Nibbling warnings into strict delight,
CI hums, packages fall in line,
Constraints cleaned up — release the shine,
Thump for tidy trees and clearer night.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding clang-tidy configuration to enforce modern C++ usage, which aligns with the primary objective.
Linked Issues check ✅ Passed The PR successfully implements all core requirements from issue #553: .clang-tidy configuration file added, CI gate configured, and clang-tidy integrated into the workflow.
Out of Scope Changes check ✅ Passed All changes are within scope: .clang-tidy configuration, CI workflow updates, and necessary code adjustments to comply with clang-tidy checks.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches 🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 553-build-add-clang-tidy-to-enforce-modern-c-usage

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.clang-tidy:
- Around line 2-5: Update the .clang-tidy configuration so that Checks expands
beyond only bugprone-string-constructor to include the targeted groups (e.g.,
modernize-*, cppcoreguidelines-*, readability-*, performance-*) and avoid making
every warning an error immediately; modify the Checks field to include those
groups and change WarningsAsErrors from "*" to either an explicit list of rule
names or remove the wildcard (leave empty) while you run clang-tidy to generate
a baseline/fix list, then reintroduce WarningsAsErrors once the baseline
violations are fixed; refer to the existing Keys "Checks" and "WarningsAsErrors"
in the file to implement these changes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info ⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9a73baac-3251-4324-a91a-ead949838aec

📥 Commits

Reviewing files that changed from the base of the PR and between e480ac2 and 9bff6f1.

📒 Files selected for processing (2)
  • .clang-tidy
  • .github/workflows/ci.yml

Comment thread .clang-tidy Outdated
Miou-zora changed the title build: add clang tidy to enforce modern c usage build: add clang tidy to enforce modern c++ usage May 1, 2026
Miou-zora requested a review from Copilot May 1, 2026 18:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Pull request overview

Adds a repository-wide clang-tidy configuration and introduces a CI job to run clang-tidy as a quality gate, aligning with issue #553’s goal of enforcing more modern C++ usage and reducing technical debt.

Changes:

  • Added a root .clang-tidy configuration file.
  • Added a new tidy job in GitHub Actions CI to run xmake check clang.tidy using that config.
  • Minor CI YAML formatting changes (line wrapping / spacing).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
.github/workflows/ci.yml Adds a dedicated clang-tidy CI job using xmake’s check integration.
.clang-tidy Introduces clang-tidy rules/config intended to be enforced by CI.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/ci.yml Outdated
Comment thread .clang-tidy Outdated
Comment thread .clang-tidy Outdated

coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/plugin/physics/src/system/ConstraintHelpers.cpp`:
- Around line 94-99: The exception handler for storing a ConstraintInternal must
not let cleanup throw: ensure ctx.physicsSystem.RemoveConstraint(joltConstraint)
is called inside a protective no-throw block (e.g., wrap it in a try-catch) or
use a non-throwing cleanup helper so that joltConstraint->Release() always runs
even if RemoveConstraint throws; reference the same pattern used in
DestroyConstraint() and apply it to the catch handling around RemoveConstraint
and joltConstraint->Release().
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info ⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 88c50c10-8de2-4166-b7ce-b8747b3a4076

📥 Commits

Reviewing files that changed from the base of the PR and between 672628c and 1d6040f.

📒 Files selected for processing (1)
  • src/plugin/physics/src/system/ConstraintHelpers.cpp

coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
🧹 Nitpick comments (2)
src/utils/log/src/Logger.hpp (2)

40-58: ⚡ Quick win

Optional: collapse the if/else if dispatch in Log::Log using spdlog::log.

Now that ToSpdlogLevel maps reliably via static_cast, the entire manual dispatch chain can be replaced with a single spdlog::log call. This removes ~12 lines of boilerplate and eliminates the latent risk of silently missing a newly added Log::Level value (e.g., the current chain falls through to Trace as the default rather than forwarding trace explicitly).

♻️ Proposed simplification
 template <typename T> inline void Log(Level level, const T &msg) noexcept
 {
-    using enum Log::Level;
-
-    if (level == info)
-        Log::Info(msg);
-    else if (level == warning)
-        Log::Warning(msg);
-    else if (level == error)
-        Log::Error(msg);
-    else if (level == critical)
-        Log::Critical(msg);
-    else if (level == debug)
-        Log::Debug(msg);
-    else if (level == off)
-        return;
-    else
-        Log::Trace(msg);
+    spdlog::log(ToSpdlogLevel(level), msg);
 };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/utils/log/src/Logger.hpp` around lines 40 - 58, Replace the manual
if/else dispatch in the template function Log (the Log::Log overload) with a
single spdlog::log call using the existing ToSpdlogLevel conversion: first
early-return on Level::off if you want to suppress logging, then call
spdlog::log(ToSpdlogLevel(level), msg). Remove the long if/else chain and the
"using enum Log::Level;" line; keep the template signature and rely on
ToSpdlogLevel(Level) to map levels so new enum values won't silently fall
through.

13-13: Pin Log::Level's underlying type to int to match spdlog::level::level_enum explicitly.

The static_cast on line 25 is valid because both Log::Level and spdlog::level::level_enum use int as their underlying type. However, spdlog::level::level_enum declares this explicitly (: int), while Log::Level relies on implicit default. Adding : int to Log::Level makes the coupling explicit and consistent, preventing any accidental incompatibility if the enum representation ever changes.

♻️ Proposed change
-enum class Level {
+enum class Level : int {
     trace    = spdlog::level::level_enum::trace,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/utils/log/src/Logger.hpp` at line 13, The enum Log::Level should
explicitly pin its underlying type to int to match spdlog::level::level_enum;
update the declaration of enum class Level to use ": int" (e.g., enum class
Level : int) so the static_cast to spdlog::level::level_enum (used elsewhere in
Logger.hpp) is guaranteed safe and stable if defaults change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/utils/log/src/Logger.hpp`:
- Around line 40-58: Replace the manual if/else dispatch in the template
function Log (the Log::Log overload) with a single spdlog::log call using the
existing ToSpdlogLevel conversion: first early-return on Level::off if you want
to suppress logging, then call spdlog::log(ToSpdlogLevel(level), msg). Remove
the long if/else chain and the "using enum Log::Level;" line; keep the template
signature and rely on ToSpdlogLevel(Level) to map levels so new enum values
won't silently fall through.
- Line 13: The enum Log::Level should explicitly pin its underlying type to int
to match spdlog::level::level_enum; update the declaration of enum class Level
to use ": int" (e.g., enum class Level : int) so the static_cast to
spdlog::level::level_enum (used elsewhere in Logger.hpp) is guaranteed safe and
stable if defaults change.

ℹ️ Review info ⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f854ab1b-93a1-4ab7-9f5b-36b895eb7d53

📥 Commits

Reviewing files that changed from the base of the PR and between 1d6040f and 95f7bc1.

📒 Files selected for processing (2)
  • .clang-tidy
  • src/utils/log/src/Logger.hpp
✅ Files skipped from review due to trivial changes (1)
  • .clang-tidy

sonarqubecloud Bot commented May 2, 2026

Copy link
Copy Markdown

Miou-zora merged commit fed68f7 into main May 2, 2026
30 checks passed
Miou-zora deleted the 553-build-add-clang-tidy-to-enforce-modern-c-usage branch May 2, 2026 18:55
Miou-zora added a commit that referenced this pull request May 24, 2026
# Pull Request

## Description

To ensure that the codebase follows good principles like modern usage of
cpp, I added clang tidy configuration file with an automatic check
inside CI.

## Related Issues (Put "None" if there are no related issues)

close #553 

## Type of Change
Please delete options that are not relevant.

- Build/CI configuration change

## Changes Made
List the main changes in this PR:
- Added clang tidy config file
- Add a gate in CI to check the code conformity to clang tidy

## Testing
Describe the tests you ran to verify your changes. Please delete options
that are not relevant.
- Unit tests pass (`xmake test`)

### Test Environment
- OS: macOS
- Compiler: Clang

## Screenshots/Videos (Put "None" if there are no related issues)

None

## Documentation
Please delete options that are not relevant.

- No documentation changes are required

## Checklist (Don't delete any options)
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [x] Any dependent changes have been merged and published

## Breaking Changes (Put "None" if there are no related issues)

None

## Additional Notes (Put "None" if there are no related issues)

None

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Chores**
* Enforced stricter static-analysis rules (treat warnings as errors) and
scoped checks to source files with repository formatting.
  * Added CI automation to run these static-analysis checks.
* Aligned internal log level definitions with the logging backend for
more consistent log behavior.

* **Bug Fixes**
* Improved cleanup behavior during constraint finalization to reduce
errors and improve runtime stability when exceptions occur.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <copilot@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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUILD] Add clang-tidy to enforce modern C++ usage

2 participants


Back | FazBrowse Home | New Git URL