sql-pretty: add indent & config in wasm#36857
Open
justjake wants to merge 2 commits into
Open
Conversation
Add an indent field to PrettyConfig and use it when nesting pretty-printer documents. Provide Default for PrettyConfig so existing callers only specify the fields they override.
Add prettyStrConfig and prettyStrsConfig exports that accept width, indent, and formatMode. Validate JS config values explicitly before constructing mz_sql_pretty::PrettyConfig. Add a small Node test for the generated wasm package, and have bin/wasm-build run crate-local test.mjs scripts so CI exercises the generated JS wrapper.
Contributor
|
Thank you for your submission! We really appreciate it. Like many source-available projects, we require that you sign our Contributor License Agreement (CLA) before we can accept your contribution. I have read the Contributor License Agreement (CLA) and I hereby sign the CLA. You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
justjake
commented
Jun 2, 2026
Comment on lines
+30
to
+34
| export interface PrettyConfig { | ||
| width?: number; | ||
| indent?: number; | ||
| formatMode?: PrettyFormatMode; | ||
| } |
Author
There was a problem hiding this comment.
Is this legit? The types aren't auto-generated?
Author
|
I have read the Contributor License Agreement (CLA) and I hereby sign the CLA. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
I want to shape Materialize SQL for rendering in the terminal as part of my migration tooling.
For this use-case, 4-space indent is quite greedy for horizontal screen space, so I would prefer a 2-space indent. However everyone's opinion is different, so it should be an option.
Description
Note: I am not a Rust programmer, so this diff is mostly Codex. I reviewed the code and it looks good to me, but I am not attuned to the aesthetics of Rust. Thank you for your patience.
Add an
indentfield to PrettyConfig and use it when nesting pretty-printer documents. Provide Default for PrettyConfig so existing callers only specify the fields they override.I converted several stand-alone functions into methods to make indent available to them.
Then in wasm, add
prettyStrConfigandprettyStrsConfigexports that accept width,indent, and formatMode and turns it into
mz_sql_pretty::PrettyConfig.I considered tacking the indent on as a third arg, but I think
f(string, number, number)is a bad signature - too easy to confuse the number args. I considered overloading the current signature but overloads are a bit weird and I didn't want to suggest weird code. Happy to do if y'all like them (and bindgen supports...).I added a little JavaScript test to verify the whole package works.
Verification