Skip to content

Conversation

@neuronull
Copy link
Contributor

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-29177

📔 Objective

As we recently added the udeps and cargo sort checks to CI and already had clippy and fmt checks, the need for pre commit checks is increasing.

This PR adds pre-commit checks the same ones we have in CI for the Rust bits in desktop native.

The changes to the version of cargo-sort in CI was done to get to a version that supports the workspace.dependencies and more sections of the toml file in general.

The changes to the individual Cargo.toml files were to update them with cargo-sort

📸 Screenshots

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

@neuronull neuronull self-assigned this Dec 4, 2025
@neuronull neuronull added the desktop Desktop Application label Dec 4, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 4, 2025

Logo
Checkmarx One – Scan Summary & Details6406b029-9843-40da-8313-9ac891cafe73

Great job! No new security vulnerabilities introduced in this pull request

This reverts commit 6b76467.
@codecov
Copy link

codecov bot commented Dec 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 41.82%. Comparing base (852248d) to head (5362ec2).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17823      +/-   ##
==========================================
- Coverage   41.83%   41.82%   -0.01%     
==========================================
  Files        3588     3588              
  Lines      104118   104118              
  Branches    15698    15698              
==========================================
- Hits        43557    43550       -7     
- Misses      58717    58724       +7     
  Partials     1844     1844              

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment on lines +3 to +8
"cargo +nightly -Z unstable-options -C ./desktop_native fmt",
"cargo +nightly -Z unstable-options -C ./desktop_native clippy --all-features --all-targets --tests -- -D warnings",
],
"*Cargo.toml": (stagedFiles) => [
"cargo +nightly -Z unstable-options -C ./desktop_native udeps --workspace --all-features --all-targets",
"cargo +nightly -Z unstable-options -C ./desktop_native sort --workspace --check",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

unstable-options required for -C

@neuronull neuronull requested a review from coltonhurst December 5, 2025 16:00
@neuronull neuronull marked this pull request as ready for review December 5, 2025 16:00
@neuronull neuronull requested review from a team as code owners December 5, 2025 16:00
@neuronull neuronull requested a review from djsmith85 December 5, 2025 16:01
@claude
Copy link

claude bot commented Dec 5, 2025

Claude finished @neuronull's task —— View job


Code Review Complete

Tasks

  • Analyze PR changes and context
  • Review Rust code changes and configuration
  • Review CI workflow updates
  • Review pre-commit hook setup
  • Provide comprehensive feedback

Overall Assessment: REQUEST CHANGES

This PR adds valuable pre-commit hooks for Rust code, but the implementation has several critical issues that need to be addressed before merge.

Critical Issues

1. Pre-commit hooks ignore staged files parameter ❌

Location: apps/desktop/lint-staged.config.js:2-9

The stagedFiles parameter is accepted but never used. All cargo commands run workspace-wide operations that process ALL files, not just staged ones.

"*.rs": (stagedFiles) => [  // stagedFiles is never used!
  "cargo +nightly -Z unstable-options -C ./desktop_native fmt",
  "cargo +nightly -Z unstable-options -C ./desktop_native clippy --all-features --all-targets --tests -- -D warnings",
],

Impact:

  • Unnecessarily slow hooks (processes entire workspace for every commit)
  • Confusing failures from unmodified files
  • Defeats the purpose of lint-staged

Recommendation: Remove the unused parameter and add a comment explaining the workspace-wide behavior:

export default {
  // Note: These run on the entire desktop_native workspace regardless of which files are staged.
  // This matches CI behavior and ensures workspace consistency.
  "*.rs": () => [
    "cargo +nightly -Z unstable-options -C ./desktop_native fmt --check",
    "cargo +nightly -Z unstable-options -C ./desktop_native clippy --all-features --all-targets --tests -- -D warnings",
  ],
  "*Cargo.toml": () => [
    "cargo +nightly -Z unstable-options -C ./desktop_native sort --workspace --check",
  ],
};

2. Missing --check flag on cargo fmt ⚠️

Location: apps/desktop/lint-staged.config.js:3

"cargo +nightly -Z unstable-options -C ./desktop_native fmt",  // No --check!

Without --check, cargo fmt will modify files but those changes won't be staged, resulting in:

  • Confusing uncommitted changes after commit
  • Commits containing unformatted code
  • CI failures

Recommendation: Add --check to match CI behavior:

"cargo +nightly -Z unstable-options -C ./desktop_native fmt --check",

3. Clippy command differs from CI ⚠️

Pre-commit: Uses +nightly toolchain and --all-targets
CI (.github/workflows/lint.yml:124-128): Uses stable toolchain without --all-targets

Impact: Commits could pass nightly clippy locally but fail stable clippy in CI.

Recommendation: Match CI exactly to prevent surprises:

"*.rs": () => [
  "cargo -C ./desktop_native fmt --check",
  "RUSTFLAGS='-D warnings' cargo -C ./desktop_native clippy --all-features --tests",
],

Important Issues

4. cargo-udeps will be very slow ⚠️

Location: apps/desktop/lint-staged.config.js:7

cargo-udeps requires compiling the entire workspace and can take 30-60 seconds. This will significantly slow down every commit touching Cargo.toml files.

Recommendation: Remove cargo-udeps from pre-commit and rely on CI:

"*Cargo.toml": () => [
  "cargo +nightly -Z unstable-options -C ./desktop_native sort --workspace --check",
],

Fast feedback is critical for pre-commit hooks. Developers will skip hooks (--no-verify) if they're too slow.

5. Cargo.lock dependency updates ❓

The Cargo.lock file shows several dependency version updates (bitflags 2.9.0 → 2.10.0, log 0.4.25 → 0.4.29, etc.). Were these intentional? The PR description doesn't mention updating dependencies.

Positive Observations

cargo-sort version update (Finding 5): Correctly updated to v2.0.2 with good documentation
Cargo.toml reformatting: All formatting changes are correct and consistent
CI workflow changes: Appropriate and well-executed

Nice-to-Have Improvements

Documentation: Consider adding Rust nightly toolchain requirements to development docs:

### Rust Development Setup

The desktop native code requires Rust nightly toolchain:
```bash
rustup install nightly

### Summary

The core value of this PR is solid - pre-commit hooks will catch issues earlier. However, the implementation needs refinement to:
1. Avoid developer friction (slow hooks, confusing behavior)
2. Ensure consistency with CI (prevent "passed locally but failed in CI" scenarios)
3. Work correctly with lint-staged (use or remove `stagedFiles` parameter)

**Must fix**: Findings 1, 2, 3  
**Should fix**: Findings 4, 5  
**Nice-to-have**: Finding 7

---

@neuronull
Copy link
Contributor Author

resolved a merge conflict

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

Labels

desktop Desktop Application

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants