DioxusLabs / DioxusLabs/dioxus

Fmt removes newlines on top scopes

Open
#3,007 0 comments 1 reaction 0 assignees View on GitHub
autoformatting bug
Dominant language
Rust
Stars
39.1k
Forks
1.9k
Avg merge
4d 10h
Merged PRs (30d)
4

Description

**Problem**

Running `dx fmt --all-code` the new lines that separate the top level blocks get deleted. It's not a critical issue but can be annoying.

```rust
use dioxus_logger::tracing;
fn main() {
dioxus_logger::init(tracing::Level::INFO).expect("failed to init logger");
tracing::info!("starting app");
launch(App);
}
fn App() -> Element {
//...
}
#[server(PostServerData)]
async fn post_server_data(data: String) -> Result {
//...
}
```

**Steps To Reproduce**

Steps to reproduce the behavior:

- Generate a new fullstack app
- Insure between the `main`, `App` and ` post_server_data` functions and the last `use` there is a new line
- Run `dx fmt --all-code`

**Expected behavior**

The new line should stay between the functions like this

```rust
use dioxus_logger::tracing;

fn main() {
dioxus_logger::init(tracing::Level::INFO).expect("failed to init logger");
tracing::info!("starting app");
launch(App);
}

fn App() -> Element {
//...
}

#[server(PostServerData)]
async fn post_server_data(data: String) -> Result {
//...
}
```

**Environment:**
- Dioxus version: 0.5.7
- Rust version: 1.81
- OS info: MacOS Intel
- App platform: Fullstack

**Questionnaire**
- [x] I'm interested in fixing this myself but don't know where to start
- [ ] I would like to fix and I have a solution
- [x] I don't have time to fix this right now, but maybe later

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by generating a fullstack app and running `dx fmt --all-code` on Rust code with blank lines between the `use`, `main`, `App`, and `post_server_data` items. Trace the formatter entry point used by this command and verify that the blank lines remain after formatting.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.