-
-
Notifications
You must be signed in to change notification settings - Fork 101
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
Find a different syntax for inline snapshot so that cargo fmt can work #499
Comments
Check out #456, both this:
...and the broader discussion. I agree that it would be great to allow rustfmt to work, though lots of other tradeoffs... |
Sharing my workaround:
# Replace `@` with `-` in macros
id: pre-format
language: Rust
rule:
pattern: '@'
precedes:
kind: raw_string_literal
inside:
kind: macro_invocation
stopBy: end
fix: '-'
# Replace `-` with `@` in macros
id: post-format
language: Rust
rule:
pattern: '-'
precedes:
kind: raw_string_literal
inside:
kind: macro_invocation
stopBy: end
fix: '@' |
from #605 (comment)
OK, that's quite interesting. |
@andylokandy, on further reflection, I'm not sure there's a syntax which would actually work here? We need to identify the type of macro in the
Am I right in thinking this is the full set of options? Or is there some other way around it? Here's a WIP branch with me trying things (originally tried |
Could you provide a example of the ambiguities? I may not fully understand it. (and what if |
Try my branch — the rust compiler will complain about ambiguities in the macro... |
Got it. It's a limitation of the compiler (lack of backtrack when parsing macro), but there is a nasty way to get through: instead of directly defining the pattern arms, consume the tokens one by one. In detail:
Here is a demo of this technique. |
Ah OK cool! If you want to make a branch / draft PR with this on, I think that would be quite helpful. Assuming the interface for users is still nice and internal stuff is well-documented, I would be +1 on this. (...though I'm not the sole decider, to set expectations) |
Currently,
@r###"..."###
the inline snapshot syntax is invalid duringcargo fmt
analyze and cannot be formatted.Perhaps a different syntax (e.g.
i=r""
) can be used for helping in this case.The text was updated successfully, but these errors were encountered: