-
Notifications
You must be signed in to change notification settings - Fork 24
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
service: fix handling of --option <value> #725
base: main
Are you sure you want to change the base?
Conversation
src/service.ts
Outdated
if (nextArg.done) { | ||
throw new Error(`--${arg} expects a value`); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the problem is that there are cases where this isn't true (some examples include --bracket-same-line
and --single-quote
), so it's hard to solve. We may need to actually use something that has the specific options and try to keep them in sync with prettier, which is a pain :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was playing around in the repl and got this out:
(await require("prettier").getSupportInfo()).options.filter(o => o.type === "boolean").map(o => o.name)
[
'singleQuote',
'bracketSpacing',
'bracketSameLine',
'singleAttributePerLine',
'vueIndentScriptAndStyle',
'semi',
'experimentalTernaries',
'jsxSingleQuote',
'insertPragma',
'requirePragma',
'useTabs'
]
These are all the prettier options1 that don't take an argument (some have o.default: true
, meaning the argument would have a no- prefix, like --no-semi
).
This seems like something that can be worked with, but the arguments could be different depending on the resolved prettier version, which wouldn't be a problem, except that we don't know the version until we've parsed the arguments :^).
Given how prettierd doesn't support prettierd file.ts
, I'm more inclined to suggest that --stdin-filepath <filename>
should be required, which would be a breaking change, but far simpler.
Footnotes
-
the prettier CLI has other arguments that don't take a value, but here we're calling the module ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm yeah I think that's an OK breaking change to make, as it simplifies things and makes prettierd command line interface compatible with prettier.
Do you want to give it a shot?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, will do!
It's a shame iterators don't provide a |
src/service.ts
Outdated
if (nextArg === undefined) { | ||
throw new Error(`--${arg} expects a value`); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we still want this check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing that out. Made me realise I missed some edge cases.
bdacb55
to
48b6dd5
Compare
Running
prettier --help
shows options with their values separated with spaces.Running
prettierd
with the options formatted as such doesn't work, but prettier doesn't differentiate between--opt=val
and--opt val
. Unfortunately my editor setup uses the space variety and isn't easy to change as it affects other formatting tools as well.A better solution would be to somehow import prettier's option handling code, but I thought that might be a bit too much for this.
before:
after: