diff options
| author | Mitermayer Reis <mitermayer.reis@gmail.com> | 2020-09-07 19:36:23 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-07 19:36:23 +1000 |
| commit | 340182bbfedd18dd3eb3cac8adc62be0de90b3f4 (patch) | |
| tree | dd57b367910b336c7f7297cc5e2b0aa804a48cec | |
| parent | e12223182a51c85528159cb8baf4339998eb9797 (diff) | |
| parent | ec8dc2bc344985c09e34fd6a4aff73702e2b7967 (diff) | |
| download | vim-prettier-340182bbfedd18dd3eb3cac8adc62be0de90b3f4.tar.xz | |
Merge branch 'master' into issue/232-adding-support-for-prettier-2.x
| -rw-r--r-- | README.md | 14 | ||||
| -rw-r--r-- | autoload/prettier/job/async/neovim.vim | 2 | ||||
| -rw-r--r-- | autoload/prettier/resolver/executable.vim | 7 | ||||
| -rw-r--r-- | doc/prettier.txt | 11 | ||||
| -rw-r--r-- | ftplugin/ruby.vim | 2 | ||||
| -rw-r--r-- | ftplugin/yaml.vim | 2 | ||||
| -rw-r--r-- | plugin/prettier.vim | 28 | ||||
| -rw-r--r-- | yarn.lock | 12 |
8 files changed, 62 insertions, 16 deletions
@@ -76,6 +76,20 @@ vim-prettier executable resolution: 3. Look for a global prettier installation 4. Use locally installed vim-prettier prettier executable +### Prettier Stylelint + +To use an alternative command, like +[`prettier-stylelint`](https://github.com/hugomrdias/prettier-stylelint), set +this at the buffer level, e.g.: + +```vim +au FileType css,scss let b:prettier_exec_cmd = "prettier-stylelint" +``` + +vim-prettier will look for the executable in the same places it looks for +`prettier`, and will fall back to `prettier` if it can't find +`b:prettier_exec_cmd` + ### USAGE Prettier by default will run on auto save but can also be manually triggered by: diff --git a/autoload/prettier/job/async/neovim.vim b/autoload/prettier/job/async/neovim.vim index 7f69f4e..35e5f82 100644 --- a/autoload/prettier/job/async/neovim.vim +++ b/autoload/prettier/job/async/neovim.vim @@ -42,6 +42,8 @@ endfunction " " note that somehow we exectuing both async and sync on nvim when using the autoformat function! s:onExit(status, info, out, err) abort + if len(a:out) == 0 | return | endif + let l:currentBufferNumber = bufnr('%') let l:isInsideAnotherBuffer = a:info.buf_nr != l:currentBufferNumber ? 1 : 0 let l:last = a:out[len(a:out) - 1] diff --git a/autoload/prettier/resolver/executable.vim b/autoload/prettier/resolver/executable.vim index 8d233ab..0cb0b02 100644 --- a/autoload/prettier/resolver/executable.vim +++ b/autoload/prettier/resolver/executable.vim @@ -33,7 +33,12 @@ endfunction function! s:GetExecPath(...) abort let l:rootDir = a:0 > 0 ? a:1 : -1 let l:dir = l:rootDir != -1 ? l:rootDir . '/.bin/' : '' - return l:dir . 'prettier' + let l:path = l:dir . get(b:, 'prettier_exec_cmd', 'prettier') + if executable(l:path) + return l:path + else + return l:dir . 'prettier' + endif endfunction " Searches for the existence of a directory accross diff --git a/doc/prettier.txt b/doc/prettier.txt index 3751da0..be76055 100644 --- a/doc/prettier.txt +++ b/doc/prettier.txt @@ -158,6 +158,17 @@ Running before saving, changing text or leaving insert mode: let g:prettier#quickfix_enabled = 0 autocmd BufWritePre,TextChanged,InsertLeave *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.yaml,*.html PrettierAsync < +Buffer-level custom commands + +To use an alternative command, like `prettier-stylelint`, set this at the +buffer level with `b:prettier_exec_cmd`, e.g.: +> + au FileType css,scss let b:prettier_exec_cmd = "prettier-stylelint" +< +vim-prettier will look for the executable in the same places it looks for +`prettier`, and will fall back to `prettier` if it can't find +`b:prettier_exec_cmd` + Overwrite default prettier configuration **Note:** vim-prettier default settings differ from prettier intentionally. diff --git a/ftplugin/ruby.vim b/ftplugin/ruby.vim index f93997d..53d13cf 100644 --- a/ftplugin/ruby.vim +++ b/ftplugin/ruby.vim @@ -4,5 +4,5 @@ let b:prettier_ft_default_args = { augroup Prettier autocmd! - autocmd BufWritePre *.ruby call prettier#Autoformat() + autocmd BufWritePre *.rb,*.ruby call prettier#Autoformat() augroup end diff --git a/ftplugin/yaml.vim b/ftplugin/yaml.vim index 2d0564d..60f669b 100644 --- a/ftplugin/yaml.vim +++ b/ftplugin/yaml.vim @@ -4,5 +4,5 @@ let b:prettier_ft_default_args = { augroup Prettier autocmd! - autocmd BufWritePre *.yaml call prettier#Autoformat() + autocmd BufWritePre *.yml,*.yaml call prettier#Autoformat() augroup end diff --git a/plugin/prettier.vim b/plugin/prettier.vim index 32391e2..04ca780 100644 --- a/plugin/prettier.vim +++ b/plugin/prettier.vim @@ -33,7 +33,7 @@ let g:prettier#autoformat_config_files = get(g:, 'prettier#autoformat_config_fil \'.prettierrc.yaml', \'.prettierrc.js', \'.prettierrc.config.js', - \'.prettierrc.json' + \'.prettierrc.json', \'.prettierrc.toml']) " path to prettier cli @@ -59,67 +59,81 @@ let g:prettier#preset#config = get(g:,'prettier#preset#config', 'default') " Max line length that prettier will wrap on: a number or 'auto' (use " textwidth). " default: 'auto' +" See more: https://prettier.io/docs/en/options.html#print-width let g:prettier#config#print_width = get(g:, 'prettier#config#print_width', 'auto') " number of spaces per indentation level: a number or 'auto' (use " softtabstop) " default: 'auto' +" See more: https://prettier.io/docs/en/options.html#tab-width let g:prettier#config#tab_width = get(g:,'prettier#config#tab_width', 'auto') " use tabs instead of spaces: true, false, or auto (use the expandtab setting). " default: 'auto' +" See more: https://prettier.io/docs/en/options.html#tabs let g:prettier#config#use_tabs = get(g:,'prettier#config#use_tabs', 'auto') " flow|babylon|typescript|css|less|scss|json|graphql|markdown or empty string " (let prettier choose). " default: '' +" See more: https://prettier.io/docs/en/options.html#parser let g:prettier#config#parser = get(g:,'prettier#config#parser', '') " cli-override|file-override|prefer-file " default: 'file-override' +" See more: https://prettier.io/docs/en/cli.html#--config-precedence let g:prettier#config#config_precedence = get(g:, 'prettier#config#config_precedence', 'file-override') " always|never|preserve " default: 'preserve' +" See more: https://prettier.io/docs/en/options.html#prose-wrap let g:prettier#config#prose_wrap = get(g:, 'prettier#config#prose_wrap', 'preserve') " css|strict|ignore " default: 'css' +" See more: https://prettier.io/docs/en/options.html#html-whitespace-sensitivity let g:prettier#config#html_whitespace_sensitivity = get(g:, 'prettier#config#html_whitespace_sensitivity', 'css') " print semicolons " default: 'true' +" See more: https://prettier.io/docs/en/options.html#semicolons let g:prettier#config#semi = get(g:,'prettier#config#semi', 'true') " Use single quotes instead of double quotes. " default: 'false' +" See more: https://prettier.io/docs/en/options.html#quotes let g:prettier#config#single_quote = get(g:,'prettier#config#single_quote', 'false') " print spaces between brackets " default: 'true' +" See more: https://prettier.io/docs/en/options.html#bracket-spacing let g:prettier#config#bracket_spacing = get(g:,'prettier#config#bracket_spacing', 'true') " put > on the last line instead of new line " default: 'false' +" See more: https://prettier.io/docs/en/options.html#jsx-brackets let g:prettier#config#jsx_bracket_same_line = get(g:,'prettier#config#jsx_bracket_same_line', 'false') " avoid wrapping a single arrow function param in parens " avoid|always " default: 'always' +" See more: https://prettier.io/docs/en/options.html#arrow-function-parentheses let g:prettier#config#arrow_parens = get(g:,'prettier#config#arrow_parens', 'always') -" Print trailing commas wherever possible when multi-line. -" none|es5|all -" default: 'es5' -let g:prettier#config#trailing_comma = get(g:,'prettier#config#trailing_comma', 'es5') - " Define the flavor of line endings " lf|crlf|cr|all " defaut: 'lf' let g:prettier#config#end_of_line = get(g:, 'prettier#config#end_of_line', 'lf') +" Print trailing commas wherever possible when multi-line. +" none|es5|all +" default: 'es5' +" See more: https://prettier.io/docs/en/options.html#trailing-commas +let g:prettier#config#trailing_comma = get(g:,'prettier#config#trailing_comma', 'es5') + " restrict itself to only format files that contain a special comment @prettier or @format -let g:prettier#config#require_pragma = get(g:, 'prettier#config#require_pragma', 'false') +" See more: https://prettier.io/docs/en/options.html#require-pragma +let g:prettier#config#require_pragma= get(g:, 'prettier#config#require_pragma', 'false') " synchronous by default command! -nargs=? -range=% Prettier call prettier#Prettier(g:prettier#exec_cmd_async, <line1>, <line2>, g:prettier#partial_format) @@ -75,9 +75,9 @@ acorn-walk@^6.0.1: integrity sha512-7evsyfH1cLOCdAzZAd43Cic04yKydNx0cF+7tiA19p1XnLLPU4dpCQOqpjqwokFe//vS0QqfqqjCS2JkiIs0cA== acorn@^5.5.3: - version "5.7.3" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.7.3.tgz#67aa231bf8812974b85235a96771eb6bd07ea279" - integrity sha512-T/zvzYRfbVojPWahDsE5evJdHb3oJoQfFbsrKM7w5Zcs++Tr257tia3BmMP8XYVjp1S9RZXQMh7gao96BlqZOw== + version "5.7.4" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.7.4.tgz#3e8d8a9947d0599a1796d10225d7432f4a4acf5e" + integrity sha512-1D++VG7BhrtvQpNbBzovKNc1FLGGEE/oGe7b9xJm/RFHMBeUaUGpluV9RLjZa47YFdPcDAenEYuq9pQPcMdLJg== acorn@^6.0.1: version "6.4.0" @@ -2131,9 +2131,9 @@ lodash.sortby@^4.7.0: integrity sha1-7dFMgk4sycHgsKG0K7UhBRakJDg= lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.4: - version "4.17.15" - resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548" - integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A== + version "4.17.19" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b" + integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ== loose-envify@^1.0.0: version "1.4.0" |
