Skip to content

ci: add cargo fmt check to CI#81

Merged
escapedcat merged 6 commits intomasterfrom
chore/cargo-fmt
Apr 9, 2026
Merged

ci: add cargo fmt check to CI#81
escapedcat merged 6 commits intomasterfrom
chore/cargo-fmt

Conversation

@escapedcat
Copy link
Copy Markdown
Collaborator

@escapedcat escapedcat commented Apr 8, 2026

Add formatting and linting to CI

  • Add cargo fmt -- --check to enforce consistent formatting
  • Add cargo clippy -- -D warnings to catch common issues
  • Include rustfmt and clippy components in rust-toolchain.toml
  • Fix one pre-existing clippy warning (regex compiled inside loop)
  • extend AGENTS.md

Summary by CodeRabbit

  • Chores
    • Added pre-test validation steps to the CI pipeline: automated formatting check and strict linting before running tests.
    • Ensured development toolchain includes formatting and linting components required by CI.
    • Optimized server-side text extraction for minor performance and allocation improvements (no behavioral changes).

Enforce consistent formatting by running cargo fmt --check before
tests. The codebase is already formatted, so this just prevents
future regressions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 8, 2026

📝 Walkthrough

Walkthrough

Added CI pre-test validation steps (cargo fmt -- --check and cargo clippy -- -D warnings) to .github/workflows/preview.yml, declared rustfmt and clippy in rust-toolchain.toml, and introduced a module-level static TIP_RE Regex in src/rest/v4/activity.rs.

Changes

Cohort / File(s) Summary
CI Workflow
.github/workflows/preview.yml
Added two pre-test steps: cargo fmt -- --check and cargo clippy -- -D warnings to fail the job on formatting or lint warnings before running tests.
Toolchain Components
rust-toolchain.toml
Added components entry including rustfmt and clippy to ensure those tools are available in the pinned toolchain.
Regex Optimization
src/rest/v4/activity.rs
Replaced per-request Regex::new(...).unwrap() with a module-level static TIP_RE (LazyLock) and used it to extract lightning:* substrings from user descriptions.

Sequence Diagram(s)

sequenceDiagram
    participant GH as GitHub Actions
    participant Repo as Repository
    participant Toolchain as Rust Toolchain (rustfmt/clippy)
    participant Test as cargo test

    GH->>Repo: checkout
    GH->>Toolchain: ensure toolchain (rust-toolchain.toml)
    GH->>Toolchain: run `cargo fmt -- --check`
    alt fmt passes
        GH->>Toolchain: run `cargo clippy -- -D warnings`
        alt clippy passes
            GH->>Test: run `cargo test`
        else clippy fails
            GH-->>Repo: fail CI (clippy warnings treated as errors)
        end
    else fmt fails
        GH-->>Repo: fail CI (formatting mismatch)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • bubelov

Poem

🐰 Hopping through commits with a cheer,

fmt and clippy now appear,
Toolchain set, regex tucked tight,
CI bounces errors into light,
I nibble bugs and dance all night. 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title mentions only 'cargo fmt check' but the PR adds both formatting and linting checks, also fixes a regex compilation issue, and updates toolchain configuration. Update the title to reflect all main changes, such as: 'ci: add formatting and linting checks' or 'ci: add cargo fmt and clippy checks with toolchain components'
✅ Passed checks (2 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/cargo-fmt

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.

escapedcat and others added 2 commits April 8, 2026 11:18
rustfmt is not installed by default for pinned toolchains. Adding it
to rust-toolchain.toml ensures it's available in CI and for local devs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add cargo clippy -- -D warnings to CI pipeline. Include clippy
component in rust-toolchain.toml. Fix the only clippy warning: move
Regex::new() outside the loop in activity handler.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

This comment was marked as resolved.

…gets

Use std::sync::LazyLock to compile the lightning tip regex once per
process instead of once per request.

Keep clippy without --all-targets for now — test code has 45 pre-existing
warnings that would need a separate cleanup PR. Noted as follow-up.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/rest/v4/activity.rs (1)

1-16: ⚠️ Potential issue | 🟡 Minor

Reorder and group imports to match repo rules.

Line 13 introduces std imports before all external imports are complete, and the groups are not separated by blank lines.

Suggested fix
 use crate::db;
 use crate::db::main::invoice::schema::{InvoiceStatus, InvoicedService};
 use crate::db::main::MainPool;
 use crate::rest::error::RestApiError;
 use crate::rest::error::RestResult;
+
 use actix_web::get;
 use actix_web::web::Data;
 use actix_web::web::Json;
 use actix_web::web::Query;
 use regex::Regex;
 use serde::Deserialize;
 use serde::Serialize;
-use std::sync::LazyLock;
 use time::Duration;
 use time::OffsetDateTime;
+
+use std::sync::LazyLock;

As per coding guidelines "Organize imports in order: internal crate modules (use crate::), external crate imports, then use std:: imports, with blank lines between groups".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/rest/v4/activity.rs` around lines 1 - 16, Reorder and group the imports
so crate-local imports come first, external crates next, and std imports last,
with a blank line between each group; specifically move all use crate::... lines
(use crate::db; use crate::db::main::invoice::schema::{InvoiceStatus,
InvoicedService}; use crate::db::main::MainPool; use
crate::rest::error::{RestApiError, RestResult};) to the top, then the external
imports (actix_web items like get and web::{Data, Json, Query}, regex::Regex,
serde::{Deserialize, Serialize}, time::{Duration, OffsetDateTime}), and finally
the std import(s) such as std::sync::LazyLock, ensuring blank lines separate the
three groups and preserving the existing symbols and names.
🤖 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/rest/v4/activity.rs`:
- Around line 17-18: The static declaration for TIP_RE (the LazyLock<Regex>
initialization) is failing rustfmt; run `cargo fmt` and update the formatting of
the static TIP_RE = LazyLock::new(...) initializer to match rustfmt's expected
layout (reflow the closure/Regex::new call so the declaration is formatted per
rustfmt) and commit the resulting changes so `cargo fmt -- --check` passes CI.

---

Outside diff comments:
In `@src/rest/v4/activity.rs`:
- Around line 1-16: Reorder and group the imports so crate-local imports come
first, external crates next, and std imports last, with a blank line between
each group; specifically move all use crate::... lines (use crate::db; use
crate::db::main::invoice::schema::{InvoiceStatus, InvoicedService}; use
crate::db::main::MainPool; use crate::rest::error::{RestApiError, RestResult};)
to the top, then the external imports (actix_web items like get and web::{Data,
Json, Query}, regex::Regex, serde::{Deserialize, Serialize}, time::{Duration,
OffsetDateTime}), and finally the std import(s) such as std::sync::LazyLock,
ensuring blank lines separate the three groups and preserving the existing
symbols and names.
🪄 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: 9b1a9bef-57f0-41bf-b1ec-cb67d1e843d9

📥 Commits

Reviewing files that changed from the base of the PR and between 9e5fbc7 and 0cffba1.

📒 Files selected for processing (3)
  • .github/workflows/preview.yml
  • rust-toolchain.toml
  • src/rest/v4/activity.rs
✅ Files skipped from review due to trivial changes (1)
  • rust-toolchain.toml
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/preview.yml

escapedcat and others added 2 commits April 8, 2026 11:45
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace the single "run cargo fmt" note with a full pre-commit
checklist (fmt, clippy, test) and document the rust-toolchain.toml pin.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@escapedcat escapedcat requested a review from bubelov April 8, 2026 04:05
@escapedcat escapedcat merged commit a6ad0e1 into master Apr 9, 2026
2 checks passed
@escapedcat escapedcat deleted the chore/cargo-fmt branch April 9, 2026 02:42
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