-
-
Notifications
You must be signed in to change notification settings - Fork 726
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
dx fmt deletes comments #2341
Comments
I am unable to reproduce this using the git version of the CLI. Can you test the git version of the CLI on your end? You can install the git version with:
|
I did run the command to install git version and checked again: - // TODO: Implement event handling here -> listen to eve
nts in child
let accept_keys = [Key::Enter, Key::Character(" ".to_string())];
- if accept_keys.contains(&evt.key()){
+ if accept_keys.contains(&evt.key()) {
log::info!("{} pressed in {}", evt.key(), "{props.labelText}");
log::info!("{} pressed in {}", evt.key(), "{props.labelText}");
}
},
class: "flex flex-1 h-full w-3/4 items-center justify-center btn btn-outline my-1 py-1",
- div { class: "flex-none py-1", // TODO: Refactor into separate component
+ div { class: "flex-none py-1",
Icon { width: 24, height: 24, icon: props.icon, title: "{props.iconTitle}" }
- },
+ }
"{props.labelText}"
- input { // TODO: Refactor into separate component
+ input {
dx -V says:
|
I can reproduce it now. The formatter doesn't like inline comments and removes them completely: rsx! {
div { // this comment will be removed
"hi",
}
} |
this also seems to affect the VSCode Dioxus extension. Block-level comments ( |
Adding to the list. All comments are removed in event handlers (except doc comments): rsx! {
div {
// also occurs in move || async move
onclick: move |_| {
// is removed
/* is removed */
}
}
} |
I think it comes from here: dioxus/packages/cli/src/cli/autoformat.rs Lines 249 to 253 in 472031d
syn does not keep comments. https://crates.io/crates/rustfmt-wrapper (or spawning I don't know if Dioxus developers would agree with this solution, but if they do, I would be happy to do it. |
We try our best to preserve comments by writing out whitepace on rsx indents, but there's no way to preserve whitespace with prettyplease. I'd be interested in supporting the rustfmt wrapper approach, but it is convenient for autoformatting to not rely on rustfmt so we can use it in things like wasm. |
What if it was behind a target cfg? Wasi support spawning new tasks, so rustfmt would work. |
Problem
Using
dx fmt
on source files is deleting comments, both in rsx macros and standard rust when using--all-code
.This is especially egregious because standard
rustfmt
formatter is really messing up any files with rsx in them, sodx fmt
is the only viable alternative.Steps To Reproduce
Steps to reproduce the behavior:
dx fmt -f yourfile.rs
Expected behavior
Comments should be left alone.
I'm not entirely sure how
rustfmt
does it, but with my limited experience with it, it seems to keep comments intact and relatively in the relevelant place after formatting.Screenshots
n/a
Environment:
Questionnaire
The text was updated successfully, but these errors were encountered: