You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make this a required status check in GitHub branch protection rules. This alone eliminates the "AI tools reformat each iteration" problem — any PR that introduces formatting changes will fail CI.
2. Align rustfmt.toml with Upstream (spiral/ldk-node)
Currently our rustfmt.toml has 14 settings. Upstream may have different settings, causing spurious diffs when merging upstream changes.
Action: Compare rustfmt.toml against upstream's at https://github.com/lightningdevkit/ldk-node/blob/main/rustfmt.toml. If they differ, decide:
Option A: Adopt upstream's exact config — minimizes merge friction, but may change our current formatting
Option B: Keep our config but document the divergence explicitly — requires manual reformatting when pulling upstream changes
For upstream merge hygiene, Option A is strongly recommended.
Contributors run pre-commit install once after cloning. This catches formatting issues before they ever reach CI or review. Works well alongside AI tools since it runs as part of the git commit flow.
4. Editor-Level Enforcement via .editorconfig and VS Code Settings
Add .editorconfig for consistent baseline across all editors:
This ensures cargo fmt produces identical output on all machines and in CI, eliminating "it formats differently on my machine" issues.
Recommended Implementation Order
Priority
Solution
Effort
Impact
1
Dedicated fmt-check.yml + required status check
Low
High — blocks unformatted PRs
2
Align rustfmt.toml with upstream
Low-Medium
High — eliminates upstream merge noise
3
rust-toolchain.toml for version pinning
Low
Medium — consistency across environments
4
.editorconfig + VS Code settings
Low
Medium — prevents drift during editing
5
pre-commit hook
Low
Medium — catches issues before CI
Note on AI Tools
The pre-commit hook and required CI check are the most effective tools against AI-introduced formatting changes. If cargo fmt --check fails in CI, any PR with formatting changes — regardless of source — will be blocked until fixed.
changed the title [-]dev: Setup coding style enforcement to match upstream formatting[/-][+]dev: setup formatting enforcement matching upstream [/+]on Mar 2, 2026
Activity
ovitrif commentedon Mar 2, 2026
@claude What solutions could we adopt for addressing this issue?!
claude commentedon Mar 2, 2026
Claude finished @ovitrif's task in 1m 25s —— View job
Solutions for Coding Style Enforcement
Here's a breakdown of the current state and concrete solutions, ordered from highest to lowest impact.
Current State
rustfmt.tomlexists with specific settings (hard tabs,max_width = 100, compressed fn params, etc.).github/workflows/rust.yml(cargo fmt --all -- --check)rust.ymlis triggered only onworkflow_dispatch(manual), not on every PR or push — so format checks are not automatically enforcedrustfmtbot workflow exists but is also manual-only nowRecommended Solutions
1. Add a Dedicated
fmt-check.ymlCI Workflow (Highest Priority)The most impactful fix. Add a lightweight workflow that runs on every PR and push:
Make this a required status check in GitHub branch protection rules. This alone eliminates the "AI tools reformat each iteration" problem — any PR that introduces formatting changes will fail CI.
2. Align
rustfmt.tomlwith Upstream (spiral/ldk-node)Currently our
rustfmt.tomlhas 14 settings. Upstream may have different settings, causing spurious diffs when merging upstream changes.Action: Compare
rustfmt.tomlagainst upstream's athttps://github.com/lightningdevkit/ldk-node/blob/main/rustfmt.toml. If they differ, decide:For upstream merge hygiene, Option A is strongly recommended.
3. Pre-commit Hook via
pre-commitFrameworkAdd
.pre-commit-config.yamlto the repo:Contributors run
pre-commit installonce after cloning. This catches formatting issues before they ever reach CI or review. Works well alongside AI tools since it runs as part of the git commit flow.4. Editor-Level Enforcement via
.editorconfigand VS Code SettingsAdd
.editorconfigfor consistent baseline across all editors:And optionally add
.vscode/settings.json:{ "editor.formatOnSave": true, "rust-analyzer.rustfmt.extraArgs": [], "[rust]": { "editor.defaultFormatter": "rust-lang.rust-analyzer" } }This makes VS Code (and JetBrains with the EditorConfig plugin) auto-format on save, preventing formatting drift during editing.
5. Document the Formatting Policy in CLAUDE.md / CONTRIBUTING
CLAUDE.md already states
ALWAYS run cargo fmt before committing. Strengthening this with:rustfmtversion (viarust-toolchain.toml) to ensure everyone uses the same formatter version6. Pinned Rust Toolchain via
rust-toolchain.tomlAdd a
rust-toolchain.tomlto pin the formatter version:This ensures
cargo fmtproduces identical output on all machines and in CI, eliminating "it formats differently on my machine" issues.Recommended Implementation Order
fmt-check.yml+ required status checkrustfmt.tomlwith upstreamrust-toolchain.tomlfor version pinning.editorconfig+ VS Code settingspre-commithookNote on AI Tools
The pre-commit hook and required CI check are the most effective tools against AI-introduced formatting changes. If
cargo fmt --checkfails in CI, any PR with formatting changes — regardless of source — will be blocked until fixed.[-]dev: Setup coding style enforcement to match upstream formatting[/-][+]dev: setup formatting enforcement matching upstream [/+][-]dev: setup formatting enforcement matching upstream [/-][+]dev: enforce formatting matching upstream [/+][-]dev: enforce formatting matching upstream [/-][+]dev: enforce formatting matching upstream style[/+]