# How to Check Code Formatting in OpenLogi: A Complete Verification Guide

> Easily check code formatting in OpenLogi with our complete guide. Learn the simple command to verify all workspace crates without modifying files. Keep your code clean.

- Repository: [Xuan Zhang/OpenLogi](https://github.com/AprilNEA/OpenLogi)
- Tags: how-to-guide
- Published: 2026-08-22

---

**To check code formatting in OpenLogi, run `cargo fmt --all -- --check` from the repository root to validate all workspace crates without modifying files.**

OpenLogi is a Rust-based logistics platform where maintaining consistent code style is essential when contributing to its approximately 30 workspace crates. This guide explains how to check code formatting in OpenLogi using the standardized `cargo fmt` toolchain across three enforcement layers: local development, pre-commit hooks, and continuous integration.

## Understanding OpenLogi's Formatting Architecture

The repository follows standard Rust formatting workflows powered by **Rustfmt**, ensuring consistent style across the entire codebase.

### Workspace-Wide Configuration

OpenLogi organizes roughly 30 crates under a single workspace defined in [`Cargo.toml`](https://github.com/AprilNEA/OpenLogi/blob/main/Cargo.toml) at the repository root. The formatting configuration respects workspace-wide [`rustfmt.toml`](https://github.com/AprilNEA/OpenLogi/blob/main/rustfmt.toml) settings (if present) and the edition defined in each crate's [`Cargo.toml`](https://github.com/AprilNEA/OpenLogi/blob/main/Cargo.toml). The [`rust-toolchain.toml`](https://github.com/AprilNEA/OpenLogi/blob/main/rust-toolchain.toml) file pins the Minimum Supported Rust Version (MSRV), guaranteeing that formatting behavior remains consistent across all development environments and CI runners.

### Key Configuration Files

Several source files document and enforce the formatting pipeline:

- [`docs/DEVELOPMENT.md`](https://github.com/AprilNEA/OpenLogi/blob/main/docs/DEVELOPMENT.md) (line 195) documents the local formatting command for developers
- [`AGENTS.md`](https://github.com/AprilNEA/OpenLogi/blob/main/AGENTS.md) (line 102) defines the pre-commit hook configuration
- [`.claude/rules/ci.md`](https://github.com/AprilNEA/OpenLogi/blob/main/.claude/rules/ci.md) (line 47) specifies the CI `rustfmt` job
- [`rust-toolchain.toml`](https://github.com/AprilNEA/OpenLogi/blob/main/rust-toolchain.toml) pins the Rust version for reproducible formatting
- [`Cargo.toml`](https://github.com/AprilNEA/OpenLogi/blob/main/Cargo.toml) lists all workspace members that `cargo fmt --all` traverses

## How to Check Code Formatting Locally

Developers can verify formatting compliance before submitting changes using the standard Rust toolchain.

### Prerequisites

Ensure the Rust toolchain is installed. The repository's [`rust-toolchain.toml`](https://github.com/AprilNEA/OpenLogi/blob/main/rust-toolchain.toml) pins the MSRV, ensuring your local `cargo fmt` version matches the project's requirements.

### The Verification Command

From the repository root, execute:

```bash
cargo fmt --all -- --check

```

This command invokes `rustfmt` on every crate in the workspace. The `--all` flag ensures all workspace members are processed, while `--check` operates in read-only mode—it reports deviations without modifying files and exits with a non-zero status if any file requires formatting.

### Fixing Formatting Issues

If the check reports violations, apply the formatter without the `--check` flag:

```bash
cargo fmt --all

```

After formatting, re-run the check command to confirm compliance:

```bash
cargo fmt --all -- --check

```

## Automated Formatting Enforcement in OpenLogi

OpenLogi enforces formatting automatically at two critical checkpoints to prevent style violations from entering the codebase.

### Pre-Commit Hooks

According to [`AGENTS.md`](https://github.com/AprilNEA/OpenLogi/blob/main/AGENTS.md) (line 102), the repository utilizes a pre-commit hook described in the hook configuration. Every commit is automatically processed through `cargo fmt`, catching formatting issues before they enter the git history.

### Continuous Integration Gate

The CI pipeline defined in [`.claude/rules/ci.md`](https://github.com/AprilNEA/OpenLogi/blob/main/.claude/rules/ci.md) (line 47) includes a `rustfmt` job that executes:

```bash
cargo fmt --all -- --check

```

This job guarantees that all pushed code complies with the style guidelines before the merge gate is passed. Any formatting violations will fail the build, requiring the developer to fix the issues locally and push again.

## Essential Formatting Commands for Developers

Use these commands during development to maintain code quality across the OpenLogi workspace:

```bash

# CI-style verification (read-only)

cargo fmt --all -- --check

# Auto-format entire workspace

cargo fmt --all

# Combine with linting for a single crate example

cargo clippy -p openlogi-core -- -D warnings

```

## Summary

- **Primary command**: Use `cargo fmt --all -- --check` to verify formatting across all 30+ crates without modifying files
- **Configuration**: Formatting respects [`rustfmt.toml`](https://github.com/AprilNEA/OpenLogi/blob/main/rustfmt.toml) and the MSRV pinned in [`rust-toolchain.toml`](https://github.com/AprilNEA/OpenLogi/blob/main/rust-toolchain.toml)
- **Automation**: Pre-commit hooks (defined in [`AGENTS.md`](https://github.com/AprilNEA/OpenLogi/blob/main/AGENTS.md)) and CI gates ([`.claude/rules/ci.md`](https://github.com/AprilNEA/OpenLogi/blob/main/.claude/rules/ci.md)) enforce style automatically
- **Fixing issues**: Run `cargo fmt --all` to auto-correct violations, then re-verify with the check command
- **Documentation**: Development workflows are documented in [`docs/DEVELOPMENT.md`](https://github.com/AprilNEA/OpenLogi/blob/main/docs/DEVELOPMENT.md) (line 195)

## Frequently Asked Questions

### How do I check if my OpenLogi code follows the formatting standards?

Run `cargo fmt --all -- --check` from the repository root. This validates all workspace crates and exits with a non-zero status if any file violates the style guidelines, printing the paths of offending files without modifying them.

### What should I do if the formatting check fails in CI?

Run `cargo fmt --all` locally to auto-format all files in the workspace, then commit and push the changes. The CI job defined in [`.claude/rules/ci.md`](https://github.com/AprilNEA/OpenLogi/blob/main/.claude/rules/ci.md) executes the same check command, so local verification prevents pipeline failures.

### Does OpenLogi use custom formatting rules?

OpenLogi follows standard Rustfmt conventions. While the repository may include a [`rustfmt.toml`](https://github.com/AprilNEA/OpenLogi/blob/main/rustfmt.toml) for workspace-wide preferences, the primary enforcement relies on the Rust toolchain version pinned in [`rust-toolchain.toml`](https://github.com/AprilNEA/OpenLogi/blob/main/rust-toolchain.toml) to ensure consistent behavior across environments.

### Can I format just one crate instead of the entire workspace?

While `cargo fmt --all` processes the entire workspace, you can target specific packages using `cargo fmt -p <package-name>`. However, CI and pre-commit hooks require full workspace compliance, so verifying the entire workspace with `--all` is recommended before submitting changes.