-
Notifications
You must be signed in to change notification settings - Fork 8
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
feat: add option for quote and indentation styles #19
feat: add option for quote and indentation styles #19
Conversation
Absolutely yes! 🧡 In fact, this was on my mind (included in the roadmap), that from I could definitely reuse the options interface (and maybe some internal functions) passed down to |
That would definitely be feasible inside Am I understanding you correctly, that you are suggesting that we are publicly exposing those methods, so that they can be reused externally? |
🦋 Changeset detectedLatest commit: d97e56f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
thanks! |
Relevant for sveltejs/cli#380
Potentially also relevant for
svelte-ast-print
(cc @xeho91)?Currently,
esrap
is hardcoded to always use\t
for indentation and'
single quotes.This PR gives outside consumers the flexibility to specify what they want to use, by providing optional options:
Couple of notes:
svelte
itself, as it's only used as a code generation tool there. But this allows codemods to keep the users formatting in place in many more places than it's possible now.quotes
andindentation
into single files and did not use the previous testing setup here. This is because it requires passing custom options to theprint
function. I deemed this way the testing setup would stay more understandable than adding anoptions.json
file to each testing directory.Now, onto the more controversial part, that I'm not sure if this should be implemented here. I considered adding an
auto
option for both properties.indent: 'auto'
. This could be implemented like thisguessIndentString
that's already used in multiple placessv
/golden-fleece
. "Problem" with this is that it requires a string input, but we only have the ast. We could consider exposing this method fromesrap
for public use though or let the user optionally provide the original source code as part of the optionsquotes: 'auto'
This could be fairly simple to implement inside esrap as onlyLiteral
should be affected by this (rough sample implementation below)As explained above, I'm uncertain if and how the
auto
options should be part ofesrap
, thus I have not implemented them at this point, but i would love your input on this.