Skip to content

Make formatter KiCad-style compliant and simplify stackup patching#542

Merged
akhilles merged 2 commits intomainfrom
sexpr-fmt
Feb 17, 2026
Merged

Make formatter KiCad-style compliant and simplify stackup patching#542
akhilles merged 2 commits intomainfrom
sexpr-fmt

Conversation

@akhilles
Copy link
Contributor

@akhilles akhilles commented Feb 16, 2026

Previously, layout sync wasn't quite idempotent. It was only idempotent after KiCad loads + saves the layout file and fixes the formatting. Now, it's really idempotent. This also eliminates the need for complex change detection + conditional patching. The logic is now much simpler: always patch board config and then format.


Note

Medium Risk
Changes how .kicad_* files are rewritten during layout sync and introduces new formatting logic, so small formatting/ordering differences could create large diffs or expose parser/formatter edge cases despite added tests.

Overview
Makes KiCad S-expression output deterministic and KiCad-style compliant by introducing a new pcb_sexpr::formatter (prettify/format_tree) and switching schematic/symbol generation to use it.

Simplifies pcb layout stackup/layer patching by removing approximate-diff/conditional updates and instead structurally mutating the parsed PCB S-expression, then always rewriting the board with canonical formatting (atomic buffered write).

Extends pcb fmt to optionally format a single explicit KiCad S-expression file path (with --check/--diff support via unified diffs), while keeping default/discovery behavior limited to .zen files; updates snapshots accordingly and adds similar as a dependency.

Written by Cursor Bugbot for commit 6eeaaca. This will update automatically on new commits. Configure here.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

writer.write_all(text.as_bytes())?;
writer.flush()?;
fs::rename(&tmp_path, path)?;
Ok(())
Copy link

Choose a reason for hiding this comment

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

Atomic rewrite fails on existing Windows files

Medium Severity

write_text_atomic_buffered uses fs::rename(&tmp_path, path) to replace an existing PCB file. On Windows, rename does not overwrite existing destinations, so stackup patching can fail even after successful write of the temp file.

Fix in Cursor Fix in Web

@akhilles akhilles merged commit 44b9052 into main Feb 17, 2026
12 checks passed
@akhilles akhilles deleted the sexpr-fmt branch February 17, 2026 00:49
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