Merge commit '2eb29a8c2b4d8af9c88c35d7925e254a19b06a79' as 'vim/bundle/prettier'

main
Buddy Sandidge 6 years ago
commit fd5cfe72eb

@ -0,0 +1,12 @@
**Do you want to request a *feature* or report a *bug*?**
**What is the current/expected behavior?**
**What version of `vim-prettier` are you using - (output of `:PrettierVersion`) ?**
**What version of `prettier` are you using - (output of `:PrettierCliVersion`) ?**
**What is your `prettier` executable path - (output of `:PrettierCliPath`) ?**
**Did this work in previous versions of vim-prettier and/or prettier ?**

@ -0,0 +1,19 @@
*Before* submitting a pull request, please make sure the following is done...
1. Fork the repo and create your branch from `master`.
2. If you've added code that should be tested, do a sanity check on `vim8` and `neovim`
3. If you've changed APIs, update the README and documentation `./doc/prettier.txt`
Please use the simple form below as a guideline for describing your pull request.
Thanks for contributing to vim-prettier
* * *
**Summary**
[...]
**Test Plan**
[...]

@ -0,0 +1,4 @@
TODO
node_modules
.yarn_lock
yarn.lock

@ -0,0 +1,7 @@
---
language: python
dist: precise
install:
- pip install vim-vint
script:
- vint .

@ -0,0 +1,296 @@
# Change Log
## [0.2.6](https://github.com/prettier/vim-prettier/tree/0.2.6) (2017-12-08)
[Full Changelog](https://github.com/prettier/vim-prettier/compare/0.2.5...0.2.6)
**Closed issues:**
- Single quote option not working [\#84](https://github.com/prettier/vim-prettier/issues/84)
- no semicolon not working [\#83](https://github.com/prettier/vim-prettier/issues/83)
- Slow [\#82](https://github.com/prettier/vim-prettier/issues/82)
**Merged pull requests:**
- Bumping prettier dep to 1.9.1 [\#86](https://github.com/prettier/vim-prettier/pull/86) ([mitermayer](https://github.com/mitermayer))
- issues-83-and-84 - Fixing prettier 1.9 regression [\#85](https://github.com/prettier/vim-prettier/pull/85) ([mitermayer](https://github.com/mitermayer))
## [0.2.5](https://github.com/prettier/vim-prettier/tree/0.2.5) (2017-11-08)
[Full Changelog](https://github.com/prettier/vim-prettier/compare/0.2.4...0.2.5)
**Implemented enhancements:**
- Add support for prettier 1.8 [\#77](https://github.com/prettier/vim-prettier/issues/77)
**Fixed bugs:**
- Prettier: failed to parse buffer. Prettier fails on css files. [\#76](https://github.com/prettier/vim-prettier/issues/76)
**Closed issues:**
- prepends `Ignored unknown option: --config-precedence` in buffer [\#73](https://github.com/prettier/vim-prettier/issues/73)
**Merged pull requests:**
- Issue 77/adding support for prettier 1.8 [\#80](https://github.com/prettier/vim-prettier/pull/80) ([mitermayer](https://github.com/mitermayer))
- issues/76 - the shellescapping util function was breaking async [\#79](https://github.com/prettier/vim-prettier/pull/79) ([mitermayer](https://github.com/mitermayer))
- Add shellescape for file path [\#74](https://github.com/prettier/vim-prettier/pull/74) ([chemzqm](https://github.com/chemzqm))
## [0.2.4](https://github.com/prettier/vim-prettier/tree/0.2.4) (2017-10-20)
[Full Changelog](https://github.com/prettier/vim-prettier/compare/0.2.3...0.2.4)
**Implemented enhancements:**
- No references to getting help or support [\#67](https://github.com/prettier/vim-prettier/issues/67)
**Fixed bugs:**
- Incorrect resolving of prettier config [\#71](https://github.com/prettier/vim-prettier/issues/71)
**Closed issues:**
- SyntaxError: Unexpected token [\#69](https://github.com/prettier/vim-prettier/issues/69)
**Merged pull requests:**
- Fixing bug where config was not being correctly loaded based on file [\#72](https://github.com/prettier/vim-prettier/pull/72) ([mitermayer](https://github.com/mitermayer))
- Including extra information on the autoload header and doc header [\#70](https://github.com/prettier/vim-prettier/pull/70) ([mitermayer](https://github.com/mitermayer))
- adding suppor for vim8 versions older than 8.0.0015 to use async job API [\#66](https://github.com/prettier/vim-prettier/pull/66) ([mitermayer](https://github.com/mitermayer))
## [0.2.3](https://github.com/prettier/vim-prettier/tree/0.2.3) (2017-10-08)
[Full Changelog](https://github.com/prettier/vim-prettier/compare/0.2.2...0.2.3)
**Merged pull requests:**
- Making sure we can still save the results of last prettier async run on [\#65](https://github.com/prettier/vim-prettier/pull/65) ([mitermayer](https://github.com/mitermayer))
## [0.2.2](https://github.com/prettier/vim-prettier/tree/0.2.2) (2017-10-07)
[Full Changelog](https://github.com/prettier/vim-prettier/compare/0.2.1...0.2.2)
**Merged pull requests:**
- bugfix: Fixing auto command params to use extensions instead of magic [\#64](https://github.com/prettier/vim-prettier/pull/64) ([mitermayer](https://github.com/mitermayer))
## [0.2.1](https://github.com/prettier/vim-prettier/tree/0.2.1) (2017-10-07)
[Full Changelog](https://github.com/prettier/vim-prettier/compare/0.2.0...0.2.1)
**Fixed bugs:**
- Overwrites Buffer1 with contents of Buffer2 [\#62](https://github.com/prettier/vim-prettier/issues/62)
- Confused by file type overrides [\#60](https://github.com/prettier/vim-prettier/issues/60)
**Merged pull requests:**
- bugfix: fixing race condition incorrect buffer formating [\#63](https://github.com/prettier/vim-prettier/pull/63) ([mitermayer](https://github.com/mitermayer))
- bug: Fixing config overwrite value for non js by levaraging --stdin-f… [\#61](https://github.com/prettier/vim-prettier/pull/61) ([mitermayer](https://github.com/mitermayer))
## [0.2.0](https://github.com/prettier/vim-prettier/tree/0.2.0) (2017-10-04)
[Full Changelog](https://github.com/prettier/vim-prettier/compare/0.1.3...0.2.0)
**Fixed bugs:**
- `--parser` with value `postcss` is deprecated [\#59](https://github.com/prettier/vim-prettier/issues/59)
## [0.1.3](https://github.com/prettier/vim-prettier/tree/0.1.3) (2017-09-30)
[Full Changelog](https://github.com/prettier/vim-prettier/compare/0.1.2...0.1.3)
## [0.1.2](https://github.com/prettier/vim-prettier/tree/0.1.2) (2017-09-26)
[Full Changelog](https://github.com/prettier/vim-prettier/compare/0.1.1...0.1.2)
**Implemented enhancements:**
- Allow configuration to set lookup path for `prettier` cli on `.vimrc` [\#56](https://github.com/prettier/vim-prettier/issues/56)
**Merged pull requests:**
- issue/56 - Allowing user path overwrite configuration [\#57](https://github.com/prettier/vim-prettier/pull/57) ([mitermayer](https://github.com/mitermayer))
- Fixed some typos in the README [\#55](https://github.com/prettier/vim-prettier/pull/55) ([Haegin](https://github.com/Haegin))
- feature: Adding more commands [\#54](https://github.com/prettier/vim-prettier/pull/54) ([mitermayer](https://github.com/mitermayer))
## [0.1.1](https://github.com/prettier/vim-prettier/tree/0.1.1) (2017-09-18)
[Full Changelog](https://github.com/prettier/vim-prettier/compare/0.1.0...0.1.1)
**Implemented enhancements:**
- Upgrade to support prettier 1.6 [\#51](https://github.com/prettier/vim-prettier/issues/51)
## [0.1.0](https://github.com/prettier/vim-prettier/tree/0.1.0) (2017-09-14)
[Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.15...0.1.0)
**Merged pull requests:**
- Issue/51 adding support for prettier 1.7 [\#52](https://github.com/prettier/vim-prettier/pull/52) ([mitermayer](https://github.com/mitermayer))
## [0.0.15](https://github.com/prettier/vim-prettier/tree/0.0.15) (2017-08-30)
[Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.14...0.0.15)
**Fixed bugs:**
- PrettierAsync does not work on Windows [\#46](https://github.com/prettier/vim-prettier/issues/46)
**Closed issues:**
- :Prettier make cursor history wrong when navigating with \<C-O\> [\#48](https://github.com/prettier/vim-prettier/issues/48)
**Merged pull requests:**
- Making sure that after formatting we preserve in the same line [\#50](https://github.com/prettier/vim-prettier/pull/50) ([mitermayer](https://github.com/mitermayer))
- Added extensions to vim configuration example [\#49](https://github.com/prettier/vim-prettier/pull/49) ([niftylettuce](https://github.com/niftylettuce))
- Async command was not working for windows this patch will make sure it [\#47](https://github.com/prettier/vim-prettier/pull/47) ([mitermayer](https://github.com/mitermayer))
## [0.0.14](https://github.com/prettier/vim-prettier/tree/0.0.14) (2017-08-24)
[Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.13...0.0.14)
**Fixed bugs:**
- :Prettier causes :Ggrep to lose history [\#39](https://github.com/prettier/vim-prettier/issues/39)
**Closed issues:**
- Trailing comma is causing issues with IE10/11 [\#45](https://github.com/prettier/vim-prettier/issues/45)
**Merged pull requests:**
- Add instructions on changing the mapping to README [\#43](https://github.com/prettier/vim-prettier/pull/43) ([eddiezane](https://github.com/eddiezane))
- bugfix: should not clear quickfix unless opened by vim-prettier itself [\#40](https://github.com/prettier/vim-prettier/pull/40) ([mitermayer](https://github.com/mitermayer))
## [0.0.13](https://github.com/prettier/vim-prettier/tree/0.0.13) (2017-08-13)
[Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.12...0.0.13)
**Implemented enhancements:**
- Include changelog [\#35](https://github.com/prettier/vim-prettier/issues/35)
## [0.0.12](https://github.com/prettier/vim-prettier/tree/0.0.12) (2017-08-06)
[Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.11...0.0.12)
**Implemented enhancements:**
- Bump internal plugin dependencie to use prettier to 1.5.3 [\#34](https://github.com/prettier/vim-prettier/issues/34)
- Add MIT license [\#33](https://github.com/prettier/vim-prettier/issues/33)
**Closed issues:**
- Unable to disable 'single-quote' [\#32](https://github.com/prettier/vim-prettier/issues/32)
- "failed to parse buffer", but prettier from console works well [\#31](https://github.com/prettier/vim-prettier/issues/31)
- Autoformat "all" files by default. [\#30](https://github.com/prettier/vim-prettier/issues/30)
- Neovim support for job/channel to allow async formatting [\#25](https://github.com/prettier/vim-prettier/issues/25)
**Merged pull requests:**
- Adding changelog file [\#38](https://github.com/prettier/vim-prettier/pull/38) ([mitermayer](https://github.com/mitermayer))
- Adding MIT license [\#37](https://github.com/prettier/vim-prettier/pull/37) ([mitermayer](https://github.com/mitermayer))
- Bumping prettier internal dependencie plugin to 1.5.3 [\#36](https://github.com/prettier/vim-prettier/pull/36) ([mitermayer](https://github.com/mitermayer))
## [0.0.11](https://github.com/prettier/vim-prettier/tree/0.0.11) (2017-07-12)
[Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.10...0.0.11)
**Fixed bugs:**
- Json parser should not include comma at the end [\#26](https://github.com/prettier/vim-prettier/issues/26)
**Merged pull requests:**
- adding-support-for-vim7 - adding support for vim7 [\#29](https://github.com/prettier/vim-prettier/pull/29) ([mitermayer](https://github.com/mitermayer))
## [0.0.10](https://github.com/prettier/vim-prettier/tree/0.0.10) (2017-07-02)
[Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.9...0.0.10)
**Implemented enhancements:**
- should support filetype detection when none is available [\#23](https://github.com/prettier/vim-prettier/issues/23)
**Merged pull requests:**
- bugfix: json parser should not add extra comma to the end [\#27](https://github.com/prettier/vim-prettier/pull/27) ([mitermayer](https://github.com/mitermayer))
## [0.0.9](https://github.com/prettier/vim-prettier/tree/0.0.9) (2017-07-01)
[Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.8...0.0.9)
**Implemented enhancements:**
- bump plugin dependency to prettier 1.5 [\#22](https://github.com/prettier/vim-prettier/issues/22)
- add support for GraphQL parsing [\#21](https://github.com/prettier/vim-prettier/issues/21)
**Merged pull requests:**
- feature/add-filetype-support - Adding filetype detection support when [\#24](https://github.com/prettier/vim-prettier/pull/24) ([mitermayer](https://github.com/mitermayer))
## [0.0.8](https://github.com/prettier/vim-prettier/tree/0.0.8) (2017-06-30)
[Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.7...0.0.8)
**Implemented enhancements:**
- Partial formatting support [\#14](https://github.com/prettier/vim-prettier/issues/14)
**Closed issues:**
- prettier add extra comma at the last parameter of function [\#18](https://github.com/prettier/vim-prettier/issues/18)
**Merged pull requests:**
- Add JSON/GraphQL parser \(prettier 1.5\) [\#17](https://github.com/prettier/vim-prettier/pull/17) ([vutran](https://github.com/vutran))
- Fix default settings [\#16](https://github.com/prettier/vim-prettier/pull/16) ([vutran](https://github.com/vutran))
## [0.0.7](https://github.com/prettier/vim-prettier/tree/0.0.7) (2017-06-20)
[Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.6...0.0.7)
**Merged pull requests:**
- feature: enabling partial buffer conversion [\#15](https://github.com/prettier/vim-prettier/pull/15) ([mitermayer](https://github.com/mitermayer))
- fixed typo [\#13](https://github.com/prettier/vim-prettier/pull/13) ([wangsongiam](https://github.com/wangsongiam))
- Adding async command and configuration controls [\#12](https://github.com/prettier/vim-prettier/pull/12) ([mitermayer](https://github.com/mitermayer))
## [0.0.6](https://github.com/prettier/vim-prettier/tree/0.0.6) (2017-06-07)
[Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.5...0.0.6)
## [0.0.5](https://github.com/prettier/vim-prettier/tree/0.0.5) (2017-06-06)
[Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.4...0.0.5)
**Implemented enhancements:**
- Populate quickfix with prettier parsing errors [\#5](https://github.com/prettier/vim-prettier/issues/5)
**Merged pull requests:**
- Bumping support to latest prettier ^1.4.X and enabling support for [\#11](https://github.com/prettier/vim-prettier/pull/11) ([mitermayer](https://github.com/mitermayer))
## [0.0.4](https://github.com/prettier/vim-prettier/tree/0.0.4) (2017-05-31)
[Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.3...0.0.4)
**Fixed bugs:**
- Prettier CLI expects params 'false' instead of 0 [\#9](https://github.com/prettier/vim-prettier/issues/9)
## [0.0.3](https://github.com/prettier/vim-prettier/tree/0.0.3) (2017-05-28)
[Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.2...0.0.3)
**Implemented enhancements:**
- Make the prettier command run async [\#4](https://github.com/prettier/vim-prettier/issues/4)
**Fixed bugs:**
- Fallback plugins not working [\#7](https://github.com/prettier/vim-prettier/issues/7)
**Merged pull requests:**
- Prettier CLI seems to expect 'false' for some parameters instead of 0 [\#10](https://github.com/prettier/vim-prettier/pull/10) ([mitermayer](https://github.com/mitermayer))
- bugfix: fixing bug where prettier installation of the plugin was never [\#8](https://github.com/prettier/vim-prettier/pull/8) ([mitermayer](https://github.com/mitermayer))
- Adding support for async formating and making it default for autosave [\#6](https://github.com/prettier/vim-prettier/pull/6) ([mitermayer](https://github.com/mitermayer))
## [0.0.2](https://github.com/prettier/vim-prettier/tree/0.0.2) (2017-05-26)
[Full Changelog](https://github.com/prettier/vim-prettier/compare/0.0.1...0.0.2)
**Fixed bugs:**
- Should not overwrite buffer when prettier fails to parse file [\#2](https://github.com/prettier/vim-prettier/issues/2)
**Merged pull requests:**
- bugfix: Making sure that when prettier fail to parse buffer we do not [\#3](https://github.com/prettier/vim-prettier/pull/3) ([mitermayer](https://github.com/mitermayer))
- Adding working example GIF [\#1](https://github.com/prettier/vim-prettier/pull/1) ([mitermayer](https://github.com/mitermayer))
## [0.0.1](https://github.com/prettier/vim-prettier/tree/0.0.1) (2017-05-24)
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*

@ -0,0 +1,7 @@
Copyright 2017 Mitermayer Reis
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@ -0,0 +1,226 @@
## vim-prettier [![Travis CI Build Status](https://travis-ci.org/prettier/vim-prettier.svg?branch=master)](https://travis-ci.org/prettier/vim-prettier) [![Discord](https://img.shields.io/discord/435481502113857536.svg)](https://discord.gg/9bWM9PH)
A vim plugin wrapper for prettier, pre-configured with custom default prettier
settings.
---
**Note:** We are currently working towards a major release on branch `release/1.x`, while under development bugfixes will be applied to master branch and then ported back to `release/1.x` branch.
If you have feature request and/or suggestions please comment on issue [1.0 release](https://github.com/prettier/vim-prettier/issues/126)
---
By default it will auto format **javascript**, **typescript**, **less**,
**scss**, **css**, **json**, **graphql** and **markdown** files if they
have/support the "@format" pragma annotation in the header of the file.
![vim-prettier](/media/vim-prettier.gif?raw=true 'vim-prettier')
### INSTALL
Install with [vim-plug](https://github.com/junegunn/vim-plug), assumes node and
yarn|npm installed globally.
```vim
" post install (yarn install | npm install) then load plugin only for editing supported files
Plug 'prettier/vim-prettier', {
\ 'do': 'yarn install',
\ 'for': ['javascript', 'typescript', 'css', 'less', 'scss', 'json', 'graphql', 'markdown', 'vue'] }
```
or simply enable for all formats by:
```vim
" post install (yarn install | npm install) then load plugin only for editing supported files
Plug 'prettier/vim-prettier', { 'do': 'yarn install' }
```
For those using [vim-pathogen](https://github.com/tpope/vim-pathogen), you can run the following in a terminal:
```
cd ~/.vim/bundle
git clone https://github.com/prettier/vim-prettier
```
If using other vim plugin managers or doing manual setup make sure to have
`prettier` installed globally or go to your vim-prettier directory and either do
`npm install` or `yarn install`
### Prettier Executable resolution
When installed via vim-plug, a default prettier executable is installed inside
vim-prettier.
vim-prettier executable resolution:
1. Look for user defined prettier cli path from vim configuration file
2. Traverse parents and search for Prettier installation inside `node_modules`
3. Look for a global prettier installation
4. Use locally installed vim-prettier prettier executable
### USAGE
Prettier by default will run on auto save but can also be manually triggered by:
```vim
<Leader>p
```
or
```vim
:Prettier
```
If your are on vim 8+ you can also trigger async formatting by:
```vim
:PrettierAsync
```
You can check what is the `vim-prettier` plugin version by:
```vim
:PrettierVersion
```
You can send commands to the resolved `prettier` cli by:
```
:PrettierCli <q-args>
```
You can check what is the resolved `prettier` cli path by:
```vim
:PrettierCliPath
```
You can check what is the resolved `prettier` cli version by:
```vim
:PrettierCliVersion
```
### Configuration
Change the mapping to run from the default of `<Leader>p`
```vim
nmap <Leader>py <Plug>(Prettier)
```
Disable auto formatting of files that have "@format" tag
```vim
let g:prettier#autoformat = 0
```
Set the prettier CLI executable path
```vim
let g:prettier#exec_cmd_path = "~/path/to/cli/prettier"
```
The command `:Prettier` by default is synchronous but can also be forced async
```vim
let g:prettier#exec_cmd_async = 1
```
By default parsing errors will open the quickfix but can also be disabled
```vim
let g:prettier#quickfix_enabled = 0
```
By default we auto focus on the quickfix when there are errors but can also be disabled
```vim
let g:prettier#quickfix_auto_focus = 0
```
To enable vim-prettier to run in files without requiring the "@format" doc tag.
First disable the default autoformat, then update to your own custom behaviour
Running before saving sync:
```vim
let g:prettier#autoformat = 0
autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue Prettier
```
Running before saving async (vim 8+):
```vim
let g:prettier#autoformat = 0
autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue PrettierAsync
```
Running before saving, changing text or leaving insert mode:
```vim
" when running at every change you may want to disable quickfix
let g:prettier#quickfix_enabled = 0
let g:prettier#autoformat = 0
autocmd BufWritePre,TextChanged,InsertLeave *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue PrettierAsync
```
### Overwrite default prettier configuration
**Note:** vim-prettier default settings differ from prettier intentionally.
However they can be configured by:
```vim
" max line length that prettier will wrap on
" Prettier default: 80
let g:prettier#config#print_width = 80
" number of spaces per indentation level
" Prettier default: 2
let g:prettier#config#tab_width = 2
" use tabs over spaces
" Prettier default: false
let g:prettier#config#use_tabs = 'false'
" print semicolons
" Prettier default: true
let g:prettier#config#semi = 'true'
" single quotes over double quotes
" Prettier default: false
let g:prettier#config#single_quote = 'true'
" print spaces between brackets
" Prettier default: true
let g:prettier#config#bracket_spacing = 'false'
" put > on the last line instead of new line
" Prettier default: false
let g:prettier#config#jsx_bracket_same_line = 'true'
" avoid|always
" Prettier default: avoid
let g:prettier#config#arrow_parens = 'always'
" none|es5|all
" Prettier default: none
let g:prettier#config#trailing_comma = 'all'
" flow|babylon|typescript|css|less|scss|json|graphql|markdown
" Prettier default: babylon
let g:prettier#config#parser = 'flow'
" cli-override|file-override|prefer-file
let g:prettier#config#config_precedence = 'prefer-file'
" always|never|preserve
let g:prettier#config#prose_wrap = 'preserve'
```
### REQUIREMENT(S)
If prettier installation can't be found no code formatting will happen

@ -0,0 +1,426 @@
" vim-prettier: A vim plugin wrapper for prettier, pre-configured with custom default prettier settings.
"
" Script Info {{{
"==========================================================================================================
" Name Of File: prettier.vim
" Description: A vim plugin wrapper for prettier, pre-configured with custom default prettier settings.
" Maintainer: Mitermayer Reis <mitermayer.reis at gmail.com>
" Version: 0.2.7
" Usage: Use :help vim-prettier-usage, or visit https://github.com/prettier/vim-prettier
"
"==========================================================================================================
" }}}
let s:root_dir = fnamemodify(resolve(expand('<sfile>:p')), ':h')
let s:prettier_job_running = 0
let s:prettier_quickfix_open = 0
function! prettier#PrettierCliPath() abort
let l:execCmd = s:Get_Prettier_Exec()
if l:execCmd != -1
echom l:execCmd
else
call s:Suggest_Install_Prettier()
endif
endfunction
function! prettier#PrettierCli(user_input) abort
let l:execCmd = s:Get_Prettier_Exec()
if l:execCmd != -1
let l:out = system(l:execCmd. ' ' . a:user_input)
echom l:out
else
call s:Suggest_Install_Prettier()
endif
endfunction
function! prettier#Prettier(...) abort
let l:execCmd = s:Get_Prettier_Exec()
let l:async = a:0 > 0 ? a:1 : 0
let l:startSelection = a:0 > 1 ? a:2 : 1
let l:endSelection = a:0 > 2 ? a:3 : line('$')
let l:config = getbufvar(bufnr('%'), 'prettier_ft_default_args', {})
if l:execCmd != -1
let l:cmd = l:execCmd . s:Get_Prettier_Exec_Args(l:config)
" close quickfix if it is opened
if s:prettier_quickfix_open
call setqflist([], 'r')
cclose
let s:prettier_quickfix_open = 0
endif
if l:async && v:version >= 800 && exists('*job_start')
call s:Prettier_Exec_Async(l:cmd, l:startSelection, l:endSelection)
elseif l:async && has('nvim') && g:prettier#nvim_unstable_async
call s:Prettier_Exec_Async_Nvim(l:cmd, l:startSelection, l:endSelection)
else
call s:Prettier_Exec_Sync(l:cmd, l:startSelection, l:endSelection)
endif
else
call s:Suggest_Install_Prettier()
endif
endfunction
function! s:Prettier_Exec_Async_Nvim(cmd, startSelection, endSelection) abort
let l:async_cmd = a:cmd
if has('win32') || has('win64')
let l:async_cmd = 'cmd.exe /c ' . a:cmd
endif
let l:lines = getline(a:startSelection, a:endSelection)
let l:dict = {
\ 'start': a:startSelection - 1,
\ 'end': a:endSelection,
\ 'buf_nr': bufnr('%'),
\ 'content': join(l:lines, "\n"),
\}
let l:out = []
let l:err = []
let l:job = jobstart([&shell, &shellcmdflag, l:async_cmd], {
\ 'on_stdout': {job_id, data, event -> extend(l:out, data)},
\ 'on_stderr': {job_id, data, event -> extend(l:err, data)},
\ 'on_exit': {job_id, status, event -> s:Prettier_Job_Nvim_Exit(status, l:dict, l:out, l:err)},
\ })
call jobsend(l:job, l:lines)
call jobclose(l:job, 'stdin')
endfunction
function! s:Prettier_Job_Nvim_Exit(status, info, out, err) abort
if a:status != 0
echoerr join(a:err, "\n")
return
endif
if len(a:out) == 0 | return | endif
let l:last = a:out[len(a:out) - 1]
let l:out = l:last ==? '' ? a:out[0:len(a:out) - 2] : a:out
if a:info.content == join(l:out, "\n")
" no change
return
endif
call nvim_buf_set_lines(a:info.buf_nr, a:info.start, a:info.end, 0, l:out)
endfunction
function! prettier#Autoformat(...) abort
let l:curPos = getpos('.')
let l:maxLineLookup = 50
let l:maxTimeLookupMs = 500
let l:pattern = '@format'
let l:search = @/
let l:winview = winsaveview()
" we need to move selection to the top before looking up to avoid
" scanning a very long file
call cursor(1, 1)
" Search starting at the start of the document
if search(l:pattern, 'n', l:maxLineLookup, l:maxTimeLookupMs) > 0
" autoformat async
call prettier#Prettier(1)
endif
" Restore the selection and if greater then before it defaults to end
call cursor(l:curPos[1], l:curPos[2])
" Restore view
call winrestview(l:winview)
" Restore search
let @/=l:search
endfunction
function! s:Prettier_Exec_Sync(cmd, startSelection, endSelection) abort
let l:bufferLinesList = getbufline(bufnr('%'), a:startSelection, a:endSelection)
" vim 7 does not have support for passing a list to system()
let l:bufferLines = v:version <= 800 ? join(l:bufferLinesList, "\n") : l:bufferLinesList
let l:out = split(system(a:cmd, l:bufferLines), '\n')
" check system exit code
if v:shell_error
call s:Prettier_Parse_Error(l:out)
return
endif
if (s:Has_Content_Changed(l:out, a:startSelection, a:endSelection) == 0)
return
endif
call s:Apply_Prettier_Format(l:out, a:startSelection, a:endSelection)
endfunction
function! s:Prettier_Exec_Async(cmd, startSelection, endSelection) abort
let l:async_cmd = a:cmd
if has('win32') || has('win64')
let l:async_cmd = 'cmd.exe /c ' . a:cmd
endif
let l:bufferName = bufname('%')
if s:prettier_job_running != 1
let s:prettier_job_running = 1
let l:job = job_start([&shell, &shellcmdflag, l:async_cmd], {
\ 'err_cb': {channel, msg -> s:Prettier_Job_Error(msg)},
\ 'close_cb': {channel -> s:Prettier_Job_Close(channel, a:startSelection, a:endSelection, l:bufferName)}})
let l:stdin = job_getchannel(l:job)
call ch_sendraw(l:stdin, join(getbufline(bufnr(l:bufferName), a:startSelection,a:endSelection), "\n"))
call ch_close_in(l:stdin)
endif
endfunction
function! s:Prettier_Job_Close(channel, startSelection, endSelection, bufferName) abort
let l:out = []
let l:currentBufferName = bufname('%')
let l:isInsideAnotherBuffer = a:bufferName != l:currentBufferName ? 1 : 0
while ch_status(a:channel) ==# 'buffered'
call add(l:out, ch_read(a:channel))
endwhile
" nothing to update
if (s:Has_Content_Changed(l:out, a:startSelection, a:endSelection) == 0)
let s:prettier_job_running = 0
return
endif
if len(l:out)
" This is required due to race condition when user quickly switch buffers while the async
" cli has not finished running, vim 8.0.1039 has introduced setbufline() which can be used
" to fix this issue in a cleaner way, however since we still need to support older vim versions
" we will apply a more generic solution
if (l:isInsideAnotherBuffer)
if (bufloaded(str2nr(a:bufferName)))
try
silent exec 'sp '. escape(bufname(bufnr(a:bufferName)), ' \')
call s:Prettier_Format_And_Save(l:out, a:startSelection, a:endSelection)
catch
echohl WarningMsg | echom 'Prettier: failed to parse buffer: ' . a:bufferName | echohl NONE
finally
" we should then hide this buffer again
if a:bufferName == bufname('%')
silent hide
endif
endtry
endif
else
call s:Prettier_Format_And_Save(l:out, a:startSelection, a:endSelection)
endif
let s:prettier_job_running = 0
endif
endfunction
function! s:Prettier_Format_And_Save(lines, start, end) abort
call s:Apply_Prettier_Format(a:lines, a:start, a:end)
write
endfunction
function! s:Prettier_Job_Error(msg) abort
call s:Prettier_Parse_Error(split(a:msg, '\n'))
let s:prettier_job_running = 0
endfunction
function! s:Handle_Parsing_Errors(out) abort
let l:errors = []
for l:line in a:out
" matches:
" file.ext: SyntaxError: Unexpected token (2:8)sd
" stdin: SyntaxError: Unexpected token (2:8)
" [error] file.ext: SyntaxError: Unexpected token (2:8)
let l:match = matchlist(l:line, '^.*: \(.*\) (\(\d\{1,}\):\(\d\{1,}\)*)')
if !empty(l:match)
call add(l:errors, { 'bufnr': bufnr('%'),
\ 'text': l:match[1],
\ 'lnum': l:match[2],
\ 'col': l:match[3] })
endif
endfor
if len(l:errors)
let l:winnr = winnr()
call setqflist(l:errors, 'r')
botright copen
if !g:prettier#quickfix_auto_focus
" Return the cursor back to the main buffer.
exe l:winnr . 'wincmd w'
endif
let s:prettier_quickfix_open = 1
endif
endfunction
function! s:Has_Content_Changed(content, startLine, endLine) abort
return getbufline(bufnr('%'), 1, line('$')) == s:Get_New_Buffer(a:content, a:startLine, a:endLine) ? 0 : 1
endfunction
function! s:Get_New_Buffer(lines, start, end) abort
return getbufline(bufnr('%'), 1, a:start - 1) + a:lines + getbufline(bufnr('%'), a:end + 1, '$')
endfunction
function! s:Apply_Prettier_Format(lines, startSelection, endSelection) abort
" store view
let l:winview = winsaveview()
let l:newBuffer = s:Get_New_Buffer(a:lines, a:startSelection, a:endSelection)
" we should not replace contents if the newBuffer is empty
if empty(l:newBuffer)
return
endif
" delete all lines on the current buffer
silent! execute '%delete _'
" replace all lines from the current buffer with output from prettier
let l:idx = 0
for l:line in l:newBuffer
silent! call append(l:idx, l:line)
let l:idx += 1
endfor
" delete trailing newline introduced by the above append procedure
silent! execute '$delete _'
" Restore view
call winrestview(l:winview)
endfunction
" By default we will default to our internal
" configuration settings for prettier
function! s:Get_Prettier_Exec_Args(config) abort
" Allow params to be passed as json format
" convert bellow usage of globals to a get function o the params defaulting to global
let l:cmd = ' --print-width ' .
\ get(a:config, 'printWidth', g:prettier#config#print_width) .
\ ' --tab-width ' .
\ get(a:config, 'tabWidth', g:prettier#config#tab_width) .
\ ' --use-tabs ' .
\ get(a:config, 'useTabs', g:prettier#config#use_tabs) .
\ ' --semi ' .
\ get(a:config, 'semi', g:prettier#config#semi) .
\ ' --single-quote ' .
\ get(a:config, 'singleQuote', g:prettier#config#single_quote) .
\ ' --bracket-spacing ' .
\ get(a:config, 'bracketSpacing', g:prettier#config#bracket_spacing) .
\ ' --jsx-bracket-same-line ' .
\ get(a:config, 'jsxBracketSameLine', g:prettier#config#jsx_bracket_same_line) .
\ ' --arrow-parens ' .
\ get(a:config, 'arrowParens', g:prettier#config#arrow_parens) .
\ ' --trailing-comma ' .
\ get(a:config, 'trailingComma', g:prettier#config#trailing_comma) .
\ ' --parser ' .
\ get(a:config, 'parser', g:prettier#config#parser) .
\ ' --config-precedence ' .
\ get(a:config, 'configPrecedence', g:prettier#config#config_precedence) .
\ ' --prose-wrap ' .
\ get(a:config, 'proseWrap', g:prettier#config#prose_wrap) .
\ ' --stdin-filepath ' .
\ simplify(expand('%:p')) .
\ ' --no-editorconfig '.
\ ' --loglevel error '.
\ ' --stdin '
return l:cmd
endfunction
" By default we will search for the following
" => user defined prettier cli path from vim configuration file
" => locally installed prettier inside node_modules on any parent folder
" => globally installed prettier
" => vim-prettier prettier installation
" => if all fails suggest install
function! s:Get_Prettier_Exec() abort
let l:user_defined_exec_path = fnamemodify(g:prettier#exec_cmd_path, ':p')
if executable(l:user_defined_exec_path)
return l:user_defined_exec_path
endif
let l:local_exec = s:Get_Prettier_Local_Exec()
if executable(l:local_exec)
return fnameescape(l:local_exec)
endif
let l:global_exec = s:Get_Prettier_Global_Exec()
if executable(l:global_exec)
return fnameescape(l:global_exec)
endif
let l:plugin_exec = s:Get_Prettier_Plugin_Exec()
if executable(l:plugin_exec)
return fnameescape(l:plugin_exec)
endif
return -1
endfunction
function! s:Get_Prettier_Local_Exec() abort
return s:Get_Exec(getcwd())
endfunction
function! s:Get_Prettier_Global_Exec() abort
return s:Get_Exec()
endfunction
function! s:Get_Prettier_Plugin_Exec() abort
return s:Get_Exec(s:root_dir)
endfunction
function! s:Get_Exec(...) abort
let l:rootDir = a:0 > 0 ? a:1 : 0
let l:exec = -1
if isdirectory(l:rootDir)
let l:dir = s:Traverse_Dir_Search(l:rootDir)
if l:dir != -1
let l:exec = s:Get_Path_To_Exec(l:dir)
endif
else
let l:exec = s:Get_Path_To_Exec()
endif
return l:exec
endfunction
function! s:Get_Path_To_Exec(...) abort
let l:rootDir = a:0 > 0 ? a:1 : -1
let l:dir = l:rootDir != -1 ? l:rootDir . '/.bin/' : ''
return l:dir . 'prettier'
endfunction
function! s:Traverse_Dir_Search(rootDir) abort
let l:root = a:rootDir
let l:dir = 'node_modules'
while 1
let l:search_dir = l:root . '/' . l:dir
if isdirectory(l:search_dir)
return l:search_dir
endif
let l:parent = fnamemodify(l:root, ':h')
if l:parent == l:root
return -1
endif
let l:root = l:parent
endwhile
endfunction
function! s:Prettier_Parse_Error(errors) abort
echohl WarningMsg | echom 'Prettier: failed to parse buffer.' | echohl NONE
if g:prettier#quickfix_enabled
call s:Handle_Parsing_Errors(a:errors)
endif
endfunction
" If we can't find any prettier installing we then suggest where to get it from
function! s:Suggest_Install_Prettier() abort
echohl WarningMsg | echom 'Prettier: no prettier executable installation found.' | echohl NONE
endfunction

@ -0,0 +1,184 @@
*vim-prettier.txt* A prettier plugin for vim.
-------------------------------------------------------
vim-prettier: plugin wrapper for prettier
-------------------------------------------------------
Author: Mitermayer Reis <mitermayer.reis@gmail.com>
WebSite: https://prettier.io/
Repository: https://github.com/prettier/vim-prettier
License: MIT style license
Version: 0.2.7
==============================================================================
CONTENTS *vim-prettier-contents*
Introduction |vim-prettier-introduction|
Install |vim-prettier-install|
Usage |vim-prettier-usage|
Configuration |vim-prettier-configuration|
Requirements |vim-prettier-requirements|
==============================================================================
INTRODUCTION *vim-prettier-introduction*
A vim plugin wrapper for prettier, pre-configured with
custom default prettier settings.
By default it will auto format javascript, typescript, less, scss, css,
json, and graphql files that have '@format' annotation in the header of the file.
When installed via vim-plug, a default prettier executable is installed inside
vim-prettier.
vim-prettier executable resolution:
1. Look for user defined prettier cli path from vim configuration file
2. Traverse parents and search for Prettier installation inside `node_modules`
3. Look for a global prettier installation
4. Use locally installed vim-prettier prettier executable
==============================================================================
INSTALL *vim-prettier-install*
Install with [vim-plug](https://github.com/junegunn/vim-plug), assumes
node and yarn|npm installed globally.
>
Plug 'prettier/vim-prettier', {
\ 'do': 'yarn install',
\ 'for': ['javascript', 'typescript', 'css',
\ 'less', 'scss', 'json', 'graphql', 'markdown', 'vue'] }
<
or simply enable for all formats by:
>
Plug 'prettier/vim-prettier', { 'do': 'yarn install' }
<
If using other vim plugin managers or doing manual setup make sure to have
`prettier` installed globally or go to your vim-prettier directory and
either do `npm install` or `yarn install`
==============================================================================
USAGE *vim-prettier-usage*
Prettier by default will run on auto save but can also
be manually triggered by:
>
<Leader>p
<
or
>
:Prettier
<
If your are on vim 8+ you can also trigger async formatting by:
>
:PrettierAsync
<
You can check what is the `vim-prettier` plugin version by:
>
:PrettierVersion
<
You can send commands to the resolved `prettier` cli by:
>
:PrettierCli <q-args>
<
You can check what is the resolved `prettier` cli path by:
>
:PrettierCliPath
<
You can check what is the resolved `prettier` cli version by:
>
:PrettierCliVersion
<
==============================================================================
CONFIGURATION *vim-prettier-configuration*
Disable auto formatting of files that have "@format" tag
>
let g:prettier#autoformat = 0
<
Set the prettier CLI executable path
>
let g:prettier#exec_cmd_path = "~/path/to/cli/prettier"
<
The command `:Prettier` by default is synchronous but can also be forced async
>
let g:prettier#exec_cmd_async = 1
<
By default parsing errors will open the quickfix but can also be disabled
>
let g:prettier#quickfix_enabled = 1
<
By default we auto focus on the quickfix when there are errors but can also be disabled
>
let g:prettier#quickfix_auto_focus = 0
<
To enable vim-prettier to run in files without requiring the "@format" doc tag.
First disable the default autoformat, then update to your own custom behaviour
Running before saving sync:
>
let g:prettier#autoformat = 0
autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue Prettier
<
Running before saving async (vim 8+):
>
let g:prettier#autoformat = 0
autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue PrettierAsync
<
Running before saving, changing text or leaving insert mode:
>
" when running at every change you may want to disable quickfix
let g:prettier#quickfix_enabled = 0
let g:prettier#autoformat = 0
autocmd BufWritePre,TextChanged,InsertLeave *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue PrettierAsync
<
Overwrite default prettier configuration
**Note:** vim-prettier default settings differ from prettier intentionally.
However they can be configured by:
>
" max line length that prettier will wrap on
let g:prettier#config#print_width = 80
" number of spaces per indentation level
let g:prettier#config#tab_width = 2
" use tabs over spaces
let g:prettier#config#use_tabs = 'false'
" print semicolons
let g:prettier#config#semi = 'true'
" single quotes over double quotes
let g:prettier#config#single_quote = 'true'
" print spaces between brackets
let g:prettier#config#bracket_spacing = 'false'
" put > on the last line instead of new line
let g:prettier#config#jsx_bracket_same_line = 'true'
" avoid|always
let g:prettier#config#arrow_parens = 'always'
" none|es5|all
let g:prettier#config#trailing_comma = 'all'
" flow|babylon|typescript|css|less|scss|json|graphql|markdown
let g:prettier#config#parser = 'flow'
" cli-override|file-override|prefer-file
let g:prettier#config#config_precedence = 'prefer-file'
" always|never|preserve
let g:prettier#config#prose_wrap = 'preserve'
<
==============================================================================
REQUIREMENT(S) *vim-prettier-requirements*
If prettier is not installed locally, globally or inside vim-prettier project
no code formatting will happen
==============================================================================
vim:tw=78:ts=4:ft=help:norl:noet:fen:noet:

@ -0,0 +1 @@
autocmd BufNewFile,BufReadPost *.css setfiletype css

@ -0,0 +1 @@
autocmd BufNewFile,BufReadPost *.graphql,*.gql setfiletype graphql

@ -0,0 +1 @@
autocmd BufNewFile,BufReadPost *.js setfiletype javascript

@ -0,0 +1 @@
autocmd BufNewFile,BufReadPost *.json setfiletype json

@ -0,0 +1 @@
autocmd BufNewFile,BufReadPost *.less setfiletype less

@ -0,0 +1 @@
autocmd BufNewFile,BufReadPost *.markdown,*.md,*.mdown,*.mkd,*.mkdn setfiletype markdown

@ -0,0 +1 @@
autocmd BufNewFile,BufReadPost *.scss setfiletype scss

@ -0,0 +1 @@
autocmd BufNewFile,BufReadPost *.ts setfiletype typescript

@ -0,0 +1 @@
autocmd BufNewFile,BufReadPost *.vue setfiletype vue

@ -0,0 +1,10 @@
let b:prettier_ft_default_args = {
\ 'parser': 'css',
\ }
augroup Prettier
autocmd!
if g:prettier#autoformat
autocmd BufWritePre *.css call prettier#Autoformat()
endif
augroup end

@ -0,0 +1,10 @@
let b:prettier_ft_default_args = {
\ 'parser': 'graphql',
\ }
augroup Prettier
autocmd!
if g:prettier#autoformat
autocmd BufWritePre *.graphql,*.gql call prettier#Autoformat()
endif
augroup end

@ -0,0 +1,6 @@
augroup Prettier
autocmd!
if g:prettier#autoformat
autocmd BufWritePre *.js,*.jsx,*.mjs call prettier#Autoformat()
endif
augroup end

@ -0,0 +1,10 @@
let b:prettier_ft_default_args = {
\ 'parser': 'json',
\ }
augroup Prettier
autocmd!
if g:prettier#autoformat
autocmd BufWritePre *.json call prettier#Autoformat()
endif
augroup end

@ -0,0 +1,10 @@
let b:prettier_ft_default_args = {
\ 'parser': 'less',
\ }
augroup Prettier
autocmd!
if g:prettier#autoformat
autocmd BufWritePre *.less call prettier#Autoformat()
endif
augroup end

@ -0,0 +1,10 @@
let b:prettier_ft_default_args = {
\ 'parser': 'markdown',
\ }
augroup Prettier
autocmd!
if g:prettier#autoformat
autocmd BufWritePre *.markdown,*.md,*.mdown,*.mkd,*.mkdn call prettier#Autoformat()
endif
augroup end

@ -0,0 +1,10 @@
let b:prettier_ft_default_args = {
\ 'parser': 'scss',
\ }
augroup Prettier
autocmd!
if g:prettier#autoformat
autocmd BufWritePre *.scss call prettier#Autoformat()
endif
augroup end

@ -0,0 +1,10 @@
let b:prettier_ft_default_args = {
\ 'parser': 'typescript',
\ }
augroup Prettier
autocmd!
if g:prettier#autoformat
autocmd BufWritePre *.ts,*.tsx call prettier#Autoformat()
endif
augroup end

@ -0,0 +1,10 @@
let b:prettier_ft_default_args = {
\ 'parser': 'vue',
\ }
augroup Prettier
autocmd!
if g:prettier#autoformat
autocmd BufWritePre *.vue call prettier#Autoformat()
endif
augroup end

Binary file not shown.

After

Width:  |  Height:  |  Size: 559 KiB

@ -0,0 +1,14 @@
{
"name": "vim-prettier",
"author": "Mitermayer Reis <mitermayer.reis@gmail.com>",
"version": "0.2.7",
"description": "Vim plugin for prettier",
"license": "MIT",
"repository": {
"type": "git",
"url": "git://github.com/prettier/vim-prettier.git"
},
"dependencies": {
"prettier": "^1.10.2"
}
}

@ -0,0 +1,102 @@
" vim-prettier: A vim plugin wrapper for prettier, pre-configured with custom default prettier settings.
"
" Script Info {{{
"==========================================================================================================
" Name Of File: prettier.vim
" Description: A vim plugin wrapper for prettier, pre-configured with custom default prettier settings.
" Maintainer: Mitermayer Reis <mitermayer.reis at gmail.com>
" Version: 0.2.7
" Usage: Use :help vim-prettier-usage, or visit https://github.com/prettier/vim-prettier
"
"==========================================================================================================
" }}}
if exists('g:loaded_prettier')
finish
endif
let g:loaded_prettier = 1
" => Plugin config
" autoformating enabled by default upon saving
let g:prettier#autoformat = get(g:, 'prettier#autoformat', 1)
" experimental async flag will be disabled by default until is stable
let g:prettier#nvim_unstable_async = get(g:,'prettier#nvim_unstable_async', 0)
" path to prettier cli
let g:prettier#exec_cmd_path = get(g:, 'prettier#exec_cmd_path', 0)
" calling :Prettier by default runs synchronous
let g:prettier#exec_cmd_async = get(g:, 'prettier#exec_cmd_async', 0)
" when having formatting errors will open the quickfix by default
let g:prettier#quickfix_enabled = get(g:, 'prettier#quickfix_enabled', 1)
" => Prettier CLI config
" max line lengh that prettier will wrap on
let g:prettier#config#print_width = get(g:, 'prettier#config#print_width', 80)
" number of spaces per indentation level
let g:prettier#config#tab_width = get(g:,'prettier#config#tab_width', 2)
" use tabs over spaces
let g:prettier#config#use_tabs = get(g:,'prettier#config#use_tabs', 'false')
" print semicolons
let g:prettier#config#semi = get(g:,'prettier#config#semi', 'true')
" single quotes over double quotes
let g:prettier#config#single_quote = get(g:,'prettier#config#single_quote', 'true')
" print spaces between brackets
let g:prettier#config#bracket_spacing = get(g:,'prettier#config#bracket_spacing', 'false')
" put > on the last line instead of new line
let g:prettier#config#jsx_bracket_same_line = get(g:,'prettier#config#jsx_bracket_same_line', 'true')
" avoid wrapping a single arrow function param in parens
let g:prettier#config#arrow_parens = get(g:,'prettier#config#arrow_parens', 'avoid')
" none|es5|all
let g:prettier#config#trailing_comma = get(g:,'prettier#config#trailing_comma', 'all')
" flow|babylon|typescript|postcss|json|graphql
let g:prettier#config#parser = get(g:,'prettier#config#parser', 'flow')
" cli-override|file-override|prefer-file
let g:prettier#config#config_precedence = get(g:, 'prettier#config#config_precedence', 'prefer-file')
" always|never|preserve
let g:prettier#config#prose_wrap = get(g:, 'prettier#config#prose_wrap', 'preserve')
" Don't leave the quicklist focused on error.
let g:prettier#quickfix_auto_focus = get(g:, 'prettier#quickfix_auto_focus', 1)
" synchronous by default
command! -nargs=? -range=% Prettier call prettier#Prettier(g:prettier#exec_cmd_async, <line1>, <line2>)
" prettier async
command! -nargs=? -range=% PrettierAsync call prettier#Prettier(1, <line1>, <line2>)
" prints vim-prettier version
command! -nargs=? -range=% PrettierVersion echom '0.2.7'
" call prettier cli
command! -nargs=? -range=% PrettierCli call prettier#PrettierCli(<q-args>)
" call prettier cli to get its version
command! -nargs=? -range=% PrettierCliVersion call prettier#PrettierCli('--version')
" prints prettier resolved cli path
command! -nargs=? -range=% PrettierCliPath call prettier#PrettierCliPath()
" map command
if !hasmapto('<Plug>(Prettier)') && maparg('<Leader>p', 'n') ==# ''
nmap <unique> <Leader>p <Plug>(Prettier)
endif
nnoremap <silent> <Plug>(Prettier) :Prettier<CR>
nnoremap <silent> <Plug>(PrettierAsync) :PrettierAsync<CR>
nnoremap <silent> <Plug>(PrettierVersion) :PrettierVersion<CR>
nnoremap <silent> <Plug>(PrettierCli) :PrettierCli<CR>
nnoremap <silent> <Plug>(PrettierCliVersion) :PrettierCliVersion<CR>
nnoremap <silent> <Plug>(PrettierCliPath) :PrettierCliPath<CR>
Loading…
Cancel
Save