Skip to content

Conversation

@hideselfview
Copy link
Contributor

@hideselfview hideselfview commented Jan 15, 2026

Note from human: this is Claude output, I have limited Dioxus experience:


Summary

This fixes a conflict between dx fmt and cargo fmt (rustfmt). Previously, dx fmt would add indentation whitespace to blank lines inside RSX blocks, but cargo fmt removes trailing whitespace from all lines. This made it impossible for code to satisfy both formatters.

The Problem

Many projects run both formatters as checks in CI or pre-commit hooks:

cargo fmt --check   # Fails if there's trailing whitespace
dx fmt --check      # Fails if blank lines lack indentation whitespace

This creates an impossible cycle:

  1. Code formatted by cargo fmt has clean blank lines (no trailing whitespace)
  2. dx fmt --check fails because it wants indentation on those blank lines
  3. Running dx fmt adds trailing whitespace to blank lines
  4. Now cargo fmt --check fails because it wants to remove that whitespace

There's no state where both checks pass, so projects either have to:

  • Disable one of the formatters
  • Skip the checks entirely
  • Post-process with sed to strip trailing whitespace (hacky)

The Fix

Skip adding indentation to empty lines in two places in prettier_please.rs:

  1. When indenting formatted RSX blocks inside expressions (line ~58)
  2. When reassembling the final formatted output (line ~113)

Now dx fmt produces output that cargo fmt also accepts - blank lines stay blank.

Testing

Added two new test cases:

  • blank_lines - tests RSX inside match arms
  • blank_lines_preserved - tests that blank lines between elements are preserved without trailing whitespace

All existing tests continue to pass.

Fixes #5223

This fixes a conflict between dx fmt and cargo fmt (rustfmt). Previously,
dx fmt would add indentation whitespace to blank lines inside RSX blocks,
but cargo fmt removes trailing whitespace from all lines. This made it
impossible for code to satisfy both formatters.

The fix skips adding indentation to empty lines in two places:
1. When indenting formatted RSX blocks inside expressions
2. When reassembling the final formatted output

Fixes DioxusLabs#5223
@hideselfview hideselfview requested a review from a team as a code owner January 15, 2026 15:20
@jkelleyrtp jkelleyrtp merged commit 3a60140 into DioxusLabs:main Jan 16, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants