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

Don't format code inside macros that look like functions #77

Closed
mondeja opened this issue Sep 1, 2023 · 2 comments
Closed

Don't format code inside macros that look like functions #77

mondeja opened this issue Sep 1, 2023 · 2 comments
Labels
wontfix This will not be worked on

Comments

@mondeja
Copy link

mondeja commented Sep 1, 2023

Currently, leptosfmt makes really strange changes to the "arguments" passed to macros that look like functions:

- <Link rel="canonical" href=format!("https://{}/", &domain)/>
+ <Link rel="canonical" href=format!("https://{}/", & domain)/>

The problem becomes much worse when these macros that look like functions have complex code, for example:

-                    title=move_tr!("download-filetype", &{
-                        let mut map = HashMap::new();
-                        map.insert("filetype".to_string(), tr!("svg").into());
-                        map
-                    })
+                    title=move_tr!(
+                        "download-filetype", & { let mut map = HashMap::new(); map.insert("filetype"
+                        .to_string(), tr!("svg") .into()); map }
+                    )
+

I think it would make sense to ignore anything inside a macro that looks like a function.

@bram209
Copy link
Owner

bram209 commented Oct 9, 2023

Hi, can you try again with the latest version0.1.15? It includes some enhancements on std macro formatting.

@bram209 bram209 added the wontfix This will not be worked on label Oct 9, 2023
@bram209
Copy link
Owner

bram209 commented Oct 9, 2023

The format! macro is now properly formatted in the latest version.
Considering a macro in rust effectively maps a stream of tokens to a new stream of tokens, there is no straightforward way to support formatting arbitrary macros (as they can take a self-made syntax as input).

This library depends on prettyplease for formatting rust source code. Feel free to make an issue there.

@bram209 bram209 closed this as completed Oct 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants