Skip to content

fix quote within quotes formatted incorrectly by fmt #7045

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

keystroke3
Copy link
Contributor

@keystroke3 keystroke3 commented Jun 2, 2025

Fixes #6998 by looking for `" and "` patterns. If the first quote character is encountered before the second one, then the second character is treated as quoted and the outer quote block ends there. If the second character is encountered before the first, then the inner quote is considered closed, but the other one is not closed. So after the second " in `"" we are still in backtick block. For `"` we are not within any quote block after the last `

@keystroke3 keystroke3 changed the title fix quote within quotes formatted correctly fix quote within quotes formatted incorrectly by fmt Jun 2, 2025
@francislavoie
Copy link
Member

francislavoie commented Jun 2, 2025

I think it could be easier to change quoted to not be a boolean but instead a rune and then check if it's 0 to mean not quoted. Then you just need two conditions very early in the loop if quoted == '"' && ch == '`' and vice versa to just eat the character as-is until the matching quote is found

@mholt
Copy link
Member

mholt commented Jun 6, 2025

That's actually a great idea @francislavoie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The formatter should allow for backticks within quotes and vice versa
3 participants