Fix: #2604, Fix: #2240, Fix: #2341, Fix #1355 - Better error handling and and spaces handling in autofmt (#2736)

* add new autofmt sample
* Feat: implement rustfmt::skip support for rsx
* generally improve error handling with better expect messages
* wip: nested rsx formatting and expression formatting
* nested rsx formatting works
* collapse autofmt crate
* cast indent through macros
* use proper whitespace
* no more eating comments!
* Use proper error handling
This commit is contained in:
Jonathan Kelley authored and GitHub committed 2024-07-30 18:36:13 -07:00
1 parent ef0202f999
commit 828cc502f1
47 files changed
+1621 -1055

No files matched your search

+11 -28
View File
@@ -115,7 +115,13 @@ fn refactor_file(
s = format_rust(&s)?;
}
let edits = dioxus_autofmt::fmt_file(&s, indent);
let Ok(Ok(edits)) =
syn::parse_file(&s).map(|file| dioxus_autofmt::try_fmt_file(&s, &file, indent))
else {
eprintln!("failed to format file: {}", s);
exit(1);
};
let out = dioxus_autofmt::apply_formats(&s, edits);
if file == "-" {
@@ -159,7 +165,10 @@ fn format_file(
}
}
let edits = dioxus_autofmt::fmt_file(&contents, indent);
let parsed = syn::parse_file(&contents)
.map_err(|err| Error::ParseError(format!("Failed to parse file: {}", err)))?;
let edits = dioxus_autofmt::try_fmt_file(&contents, &parsed, indent)
.map_err(|err| Error::ParseError(format!("Failed to format file: {}", err)))?;
let len = edits.len();
if !edits.is_empty() {
@@ -313,29 +322,3 @@ async fn test_auto_fmt() {
fmt.autoformat().unwrap();
}
/*#[test]
fn spawn_properly() {
let out = Command::new("dioxus")
.args([
"fmt",
"-f",
r#"
//
rsx! {
div {}
}
//
//
//
"#,
])
.output()
.expect("failed to execute process");
dbg!(out);
}*/