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

Possible to provide an escape hatch for expressions? #15

Closed
max-sixty opened this issue Sep 13, 2022 · 3 comments · Fixed by #51
Closed

Possible to provide an escape hatch for expressions? #15

max-sixty opened this issue Sep 13, 2022 · 3 comments · Fixed by #51

Comments

@max-sixty
Copy link

Firstly thanks for the awesome library. We use it in https://github.com/prql/prql to format SQL once our compiler has produced it, from sqlparser-rs.

A couple of times we've wanted to not format an expression, maybe because it's not standard SQL. Here's an example that just came up: PRQL/prql#965

Do you have any thoughts for how best to manage that? We could use a sentinel and then replace it afterwards? Or would this library be open to something like a <ignore> tag / -- format-ignore comment?

@wugeer
Copy link
Contributor

wugeer commented Sep 6, 2024

@max-sixty That's a good question. I'm wondering how to handle SQL statements that don't need formatting. Should we add line breaks before and after such SQL statements, or should we also consider the preceding and following context?
Or do you have some expected output that we can refer to? :)

@max-sixty
Copy link
Author

The immediate thing that would be really useful is to be able to say "between these comments, don't format the expression".

Other code formatters do this, such as black's # fmt: off feature.

Then questions such as

Should we add line breaks before and after such SQL statements, or should we also consider the preceding and following context?

...are quite minor for the user, I think (if I'm understanding your questions correctly)


Should we add line breaks before and after such SQL statements, or should we also consider the preceding and following context?
Or do you have some expected output that we can refer to? :)

I just added a comment to PRQL/prql#965 (comment). The motivating case would be to format:

SELECT
  *
FROM
  sometable
WHERE
-- fmt: off
  json:first_key.second_key = 1
-- fmt: on
  AND 
-- fmt: off
  json:first_key.second_key = 1
-- fmt:on

...without adding a space in json:first_key. Does that make sense?

Thanks for responding!

@wugeer
Copy link
Contributor

wugeer commented Sep 7, 2024

Good idea! I will try to solve this problem.

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 a pull request may close this issue.

2 participants