Skip to content

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

Merged
merged 3 commits into from
Dec 15, 2018
Merged

Conversation

lhchavez
Copy link
Contributor

This change adds the Prettier (https://prettier.io) JavaScript
formatter.

Fixes: #89

@lhchavez lhchavez force-pushed the prettier branch 2 times, most recently from cee3b76 to d4be93d Compare December 12, 2018 06:21
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.
Copy link
Contributor

@dbarnett dbarnett left a 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 @% == ""
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

""
" 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'])
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


:FormatCode prettier
! prettier .*2> (.*)
$ echo '[error] stdin: SyntaxError: Unexpected token (2:1)' >\1 (command)
Copy link
Contributor

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]     | ^'

Copy link
Contributor Author

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
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@dbarnett dbarnett merged commit 2147649 into google:master Dec 15, 2018
@lhchavez lhchavez deleted the prettier branch January 14, 2019 01:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants