Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dioxius macros confuse rustfmt #6230

Open
uzytkownik opened this issue Jul 6, 2024 · 8 comments
Open

Dioxius macros confuse rustfmt #6230

uzytkownik opened this issue Jul 6, 2024 · 8 comments
Labels
needs-mcve needs a Minimal Complete and Verifiable Example

Comments

@uzytkownik
Copy link

Rustfmt formats:

fn Layout() -> Element {
    fn Links() -> Element {
        rsx! {
            nav {
                ul {
                    id: "main-nav",
                    class: "nav nav-pills",
                    for item in RouteDiscriminants::iter() {
                        MenuItem { item }
                    }
                }
            }
        }
    }
    rsx! {
        header {
            class: "text-bg-dark d-flex justify-content-center py-3",
            Links {}
        }
        main {
            class: "col-lg-8 mx-auto p-4 py-md-5",
            Outlet::<Route> { }
        }
    }
}

into:

fn Layout() -> Element {
    fn Links() -> Element {
        rsx! {
            nav {
            ul {
                id: "main-nav",
                class: "nav nav-pills",
                for item in RouteDiscriminants::iter() {
                MenuItem { item }
                }
            }
            }
        }
    }
    rsx! {
    header {
        class: "text-bg-dark d-flex justify-content-center py-3",
        Links {}
    }
    main {
        class: "col-lg-8 mx-auto p-4 py-md-5",
        Outlet::<Route> { }
    }
    }
}
@ytmimi
Copy link
Contributor

ytmimi commented Jul 6, 2024

@uzytkownik what version of rustfmt are you using? I'm unable to reproduce the issue locally building rustfmt from source.

@ytmimi ytmimi added the needs-mcve needs a Minimal Complete and Verifiable Example label Jul 6, 2024
@uzytkownik
Copy link
Author

@ytmimi Hmm. It looks something very strange goes on with tabs. It looks like rustfmt does not convert them into spaces which seems to be strange. I would expect based on documentation to have them converted into spaces by default- hard_tabs.

Outside of that it seems to be mismatch of tab_spaces between rustfmt and editor. I disabled tabs in editor fixing the problem but it seems to me that behaviour should be clarified in documentation or (even better) hard_tabs would convert them into spaces.

@ytmimi
Copy link
Contributor

ytmimi commented Jul 6, 2024

Also, which configuration options are you using?

@uzytkownik
Copy link
Author

@ytmimi None. I just run cargo fmt. No configuration.

@ytmimi
Copy link
Contributor

ytmimi commented Jul 6, 2024

Got it, so this was just a mismatch between rustfmt and your editors settings?

@uzytkownik
Copy link
Author

@ytmimi Sorry. As proximate cause (which was confusing for me) yes. Though I assumed by default cargo fmt converts to spaces based on hard_tabs documentation.

@ytmimi
Copy link
Contributor

ytmimi commented Jul 6, 2024

I'm not sure if the issue is with rustfmt. I ran a little test, and it seems that when hard_tabs=false is set leading tab characters are replaced with spaces based on the value of tab_spaces.

Given the following input that uses tabs:

fn Layout() -> Element {
	fn Links() -> Element {
		rsx! {
			nav {
				ul {
					id: "main-nav",
					class: "nav nav-pills",
					for item in RouteDiscriminants::iter() {
						MenuItem { item }
					}
				}
			}
		}
	}
	rsx! {
		header {
			class: "text-bg-dark d-flex justify-content-center py-3",
			Links {}
		}
		main {
			class: "col-lg-8 mx-auto p-4 py-md-5",
			Outlet::<Route> { }
		}
	}
}

Running rustfmt with hard_tabs=false (the default, but I explicitly configured it) outputs:

fn Layout() -> Element {
    fn Links() -> Element {
        rsx! {
            nav {
                ul {
                    id: "main-nav",
                    class: "nav nav-pills",
                    for item in RouteDiscriminants::iter() {
                        MenuItem { item }
                    }
                }
            }
        }
    }
    rsx! {
        header {
            class: "text-bg-dark d-flex justify-content-center py-3",
            Links {}
        }
        main {
            class: "col-lg-8 mx-auto p-4 py-md-5",
            Outlet::<Route> { }
        }
    }
}

@ytmimi
Copy link
Contributor

ytmimi commented Jul 6, 2024

Let me know if you're able to recreate the scenario (and provide sample input) that lead to the odd indentation you noted in your original comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-mcve needs a Minimal Complete and Verifiable Example
Projects
None yet
Development

No branches or pull requests

2 participants