Summary of the new feature / enhancement
As a contributor to the DSC repository,
I want to have a clear and consistent Rust code style across the project,
So that:
- Pull request focuses on behavior changes rather than style arguments.
- All code "looks like it came from the same author."
- CI can automatically detect style violations and reject PRs that don't conform
- New contributors have less friction
Currently, formatting style is ad hoc. This causes friction in reviews, occasional style comment debates, and some churn when refactoring.
I propose we adopt rustfmt with a small, curated rustfmt.toml config file and enforce it in the CI (separate or Pester tests) with cargo fmt --check.
Proposed formatting policy
-
Use rustfmt as the canonical formatter:
- Developers should run cargo fmt locally (or via IDE) before committing.
- The project includes a
rustfmt.toml file with agreed-upon overrides of defaults.
-
Minimal deviations from default style:
- Keep most defaults. Only override settings that are meaningful
- Example options to override:
max_width, imports_granularity, reorder_imports, wrap_comments.
-
Check in CI and locally
- Either a CI pipeline or Pester test should run:
cargo fmt --all -- --check -- --files-with-diff
- If formatting is incorrect, the build should fail and show the diff.
-
One-time bulk reformat
- Upon acceptance, run
cargo fmt over the existing codebase.
- After that, all future PRs must remain formatted.
-
Developer tooling / integration
- Configure popular tooling (VS Code) to auto-run formatting on save using rustfmt
-
Versioning and toolchain alignment
- We pin the
rustfmt version implicitly by pinning the Rust toolchain version.
Example rustfmt.toml
Below is a suggestion for a minimal config that tweaks a few settings to get started (whilst retaining most of the default style):
# rustfmt.toml for DSC
# Basic layout
max_width = 100
hard_tabs = false
tab_spaces = 4
# Imports
reorder_imports = true
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
# Comments & docs
wrap_comments = true
format_code_in_doc_comments = true
normalize_doc_attributes = true
# Macro bodies, etc.
format_macro_bodies = true
# Edition (for parsing behavior)
edition = "2021"
Rationale for some choices:
imports_granularity = "Crate" means use std::{fs, io} rather than separate lines.
group_imports = "StdExternalCrate" groups standard library imports, external crates, and local modules separately (not sure about compliance here)
- Enabling comment wrapping and doc formatting keeps comments from drifting into odd indent or width shapes.
format_macro_bodies = true ensures macro invocation bodies are formatted consistently with the rest of the code.
Summary of the new feature / enhancement
Currently, formatting style is ad hoc. This causes friction in reviews, occasional style comment debates, and some churn when refactoring.
I propose we adopt
rustfmtwith a small, curatedrustfmt.tomlconfig file and enforce it in the CI (separate or Pester tests) withcargo fmt --check.Proposed formatting policy
Use
rustfmtas the canonical formatter:rustfmt.tomlfile with agreed-upon overrides of defaults.Minimal deviations from default style:
max_width,imports_granularity,reorder_imports,wrap_comments.Check in CI and locally
One-time bulk reformat
cargo fmtover the existing codebase.Developer tooling / integration
Versioning and toolchain alignment
rustfmtversion implicitly by pinning the Rust toolchain version.Example
rustfmt.tomlBelow is a suggestion for a minimal config that tweaks a few settings to get started (whilst retaining most of the default style):
Rationale for some choices:
imports_granularity = "Crate"meansuse std::{fs, io}rather than separate lines.group_imports = "StdExternalCrate"groups standard library imports, external crates, and local modules separately (not sure about compliance here)format_macro_bodies = trueensures macro invocation bodies are formatted consistently with the rest of the code.