Skip to content

fix: resolve a relative --database against the working directory - #537

Merged
2bndy5 merged 3 commits into
mainfrom
claude/project-thread-a3krfd-database
Oct 31, 2026
Merged

2bndy5 merged 3 commits into
mainfrom
claude/project-thread-a3krfd-database

Conversation

@shenxianpeng

@shenxianpeng shenxianpeng commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

As suggested in #535 (comment): a relative --database path is now resolved against the current working directory, like cpp-linter v1 (1.15+), instead of against --repo-root. Results only differ when --repo-root is not ..

  • ClangParams::from(&Cli) uses std::path::absolute() (no filesystem access, so a missing path still reaches the existing "Failed to read compilation database" handling).
  • New test cli::structs::test::relative_db_path (--repo-root sub --database build gives <cwd>/build).
  • tests/comments.rs and tests/reviews.rs passed -p=build together with --repo-root=<tmp dir>. With this change that path pointed at cpp-linter/build, so the tests still passed but without the meson database (each run logged "Failed to read compilation database file"). They now pass the absolute <tmp dir>/build.

Checked locally (clang 21): cargo test --all-features --lib db_path, --test comments (17 passed, single-threaded) and --test reviews (16 passed), no "Failed to read compilation database" warning; cargo clippy --all-features --all-targets clean, cargo fmt.

Summary by CodeRabbit

  • Bug Fixes
    • Relative compilation database paths are now resolved from the current working directory, rather than the repository root. This makes path handling consistent when the configured repository root differs from the directory where the command is run.
    • If the path cannot be resolved, the supplied path is preserved.

@coderabbitai

coderabbitai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b266df78-f4dd-44bf-92b6-a4135baf075c
Commits

Reviewing files that changed from the base of the PR and between 940d4b6 and 37b346f.

Files selected for processing: 3
  • cpp-linter/src/cli/structs.rs
  • cpp-linter/tests/comments.rs
  • cpp-linter/tests/reviews.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

Relative compilation database paths now resolve against the current working directory instead of the repository root. If resolution fails, the supplied path is retained. Tests use absolute database paths.

Changes: Compilation Database Path Resolution

Layer / File(s) Summary
Resolve relative database paths
cpp-linter/src/cli/structs.rs, cpp-linter/tests/comments.rs, cpp-linter/tests/reviews.rs
ClangParams::from resolves relative database paths against the current working directory and retains the supplied path if resolution fails. The repository root is cloned from CLI options. Tests check the resolution behavior and pass absolute database paths.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related issues

  • Issue 514 tracks differences from cpp-linter v1 before GA. This change addresses the relative --database resolution difference.
Merge Risk: Minimal · up to 37b34

The database path behavior and updated tests are consistent with the intended change.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed 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 states the main change: a relative --database path is now resolved against the working directory. The raw summary confirms that ClangParams::from resolves a relative compilation-database…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title states the main change: a relative --database path is now resolved against the working directory. The raw summary confirms that ClangParams::from resolves a relative compilation-database path against the current working directory instead of the repository root. The title uses the "fix:" prefix, which fits the behavior change. The title is specific, short, and matches the changeset and the PR objectives.

Full details: Docstring Coverage

Explanation

Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 3 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@codecov

codecov Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.82%. Comparing base (940d4b6) to head (37b346f).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #537   +/-   ##
=======================================
  Coverage   99.82%   99.82%           
=======================================
  Files          29       29           
  Lines        7432     7460   +28     
=======================================
+ Hits         7419     7447   +28     
  Misses         13       13           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

2bndy5 pushed a commit that referenced this pull request Oct 31, 2026
<!-- claude-projects-attribution: {"github_login":"shenxianpeng"} -->

As suggested in
#535 (comment):
a new `--gen-patch-path <PATH>` option (also read from the
`GEN_PATCH_PATH` env var) sets where the combined fix patch is written,
so users can run `git apply "$GEN_PATCH_PATH"` without copying the path
from the logs.

- Setting it implies `--gen-patch`.
- A relative path is relative to the current working directory (same as
`--database` in #537, and what `git apply` expects). Note that
`--summary-output-file` and `--sarif-file` still resolve against
`--repo-root`; happy to switch this one to match those if you prefer.
- Without it, the patch stays at
`<repo-root>/.cpp-linter-cache/auto-fix.patch`, and `fix-patch-path`
reports whichever path was used.
- A stale patch at the chosen path is removed at the start of a run,
like the default one.

Implementation:

- `FeedbackInput::patch_path` holds the resolved path;
`ClangParams::default_patch_path()` builds the default.
- `FileObj::maybe_append_patch()` and `make_suggestions_from_patch()`
take the patch path instead of building it from `repo_root` (both are
`pub`, so this changes their signatures).
- Workspace `clap` enables the `env` feature (no new crates in
`Cargo.lock`).
- Tests: `cli::structs::test::{default_patch_path,
gen_patch_path_implies_gen_patch, gen_patch_path_from_env}` and
`run::test::custom_patch_path` (stale file replaced, nothing written to
the default path).

Checked locally with clang 21: all `cpp-linter` lib tests (120), `--test
comments` (17) and `--test reviews` (16) pass single-threaded (plain
`cargo test` races on env vars, nextest doesn't); `cargo clippy
--all-features --all-targets` clean; the generated CLI doc renders the
option and its example block.

---------

Co-authored-by: Xianpeng Shen <3353385+shenxianpeng@users.noreply.github.com>

@2bndy5 2bndy5 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Need to rebase branch to fix CI checks

@2bndy5
2bndy5 merged commit d4247a4 into main Oct 31, 2026
77 checks passed
@2bndy5
2bndy5 deleted the claude/project-thread-a3krfd-database branch October 31, 2026 16:21
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