-
Notifications
You must be signed in to change notification settings - Fork 105
Add support for https://prettier.io #108
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
Conversation
cee3b76
to
d4be93d
Compare
This change adds the Prettier (https://prettier.io) JavaScript formatter. Fixes: google#89
This tripped me up bad time and wouldn't like anybody else to suffer the same way.
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! Looks good, few minor suggestions.
\ string(l:Prettier_options)) | ||
endif | ||
let l:cmd = [s:plugin.Flag('prettier_executable'), '--stdin', '--no-color'] | ||
if @% == "" |
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.
Could you add a comment about what this part is doing?
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.
Done
instant/flags.vim
Outdated
"" | ||
" Command line arguments to to feed prettier. Either a list or callable that | ||
" takes no args and returns a list with command line arguments. | ||
call s:plugin.Flag('prettier_options', ['--single-quote', '--trailing-comma=all', '--arrow-parens=always', '--print-width=80']) |
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.
Nit: Wrap this long line.
If it helps, https://google.github.io/styleguide/vimscriptfull.xml?showone=Whitespace#Whitespace has an example of proper line continuations.
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.
Done
vroom/prettier.vroom
Outdated
|
||
:FormatCode prettier | ||
! prettier .*2> (.*) | ||
$ echo '[error] stdin: SyntaxError: Unexpected token (2:1)' >\1 (command) |
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.
Consider improving readability and avoiding overhead of extra shell calls by taking advantage of line continuations:
$ 2 (status)
$ echo -e >\1 ' (command)
|[error] stdin: SyntaxError: Unexpected token (2:1)\n
|[error] 1 | function foo() {\n
|[error] > 2 |\n
|[error] | ^'
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.
Done. Note that I had to drop the -e
because that would show up in the output and mess up the matching regex that's in prettier.vim
. is this running in a non-bash shell?
@@ -104,3 +104,12 @@ call s:plugin.Flag('shfmt_options', ['-i', '2', '-sr', '-ci']) | |||
"" | |||
" The path to the shfmt executable. | |||
call s:plugin.Flag('shfmt_executable', 'shfmt') | |||
|
|||
"" | |||
" Command line arguments to to feed prettier. Either a list or callable that |
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.
Need to run vimdoc over the directory (see https://github.com/google/vimdoc) so the doc file picks up this edit.
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.
Done
This change adds the Prettier (https://prettier.io) JavaScript
formatter.
Fixes: #89