aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitermayer Reis <mitermayer.reis@gmail.com>2020-02-09 12:48:07 +1100
committerGitHub <noreply@github.com>2020-02-09 12:48:07 +1100
commiteda018b6af2983758db06ce0ad6139f5b0651861 (patch)
treeeb9f4b818aa90ab9217e743ebfb0463afccd52c9
parent56fb126b73516756ab71c1c71b888b3b36bcf3fe (diff)
parent8a3fa163dcf78a23fcace64f675365ab47fee1b8 (diff)
downloadvim-prettier-eda018b6af2983758db06ce0ad6139f5b0651861.tar.xz
Merge pull request #224 from simnalamburt/autoformat_require_pragma
New option: prettier#autoformat_require_pragma
-rw-r--r--README.md25
-rw-r--r--autoload/prettier.vim4
-rw-r--r--plugin/prettier.vim3
3 files changed, 14 insertions, 18 deletions
diff --git a/README.md b/README.md
index c70703a..feb6b4b 100644
--- a/README.md
+++ b/README.md
@@ -138,6 +138,12 @@ Enable auto formatting of files that have "@format" or "@prettier" tag
let g:prettier#autoformat = 1
```
+Allow auto formatting for files without "@format" or "@prettier" tag
+
+```vim
+let g:prettier#autoformat_require_pragma = 0
+```
+
Toggle the `g:prettier#autoformat` setting based on whether a config file can be found in the current directory or any parent directory. Note that this will override the `g:prettier#autoformat` setting!
```vim
@@ -181,28 +187,13 @@ By default we auto focus on the quickfix when there are errors but can also be d
let g:prettier#quickfix_auto_focus = 0
```
-To enable vim-prettier to auto run in files without requiring the "@format" or "@prettier" doc tag.
-First ensure that `g:prettier#autoformat` is not enabled on your `vimrc` (it should be disabled by default), then update to your own custom behaviour
-
-Running before saving sync:
-
-```vim
-autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.yaml,*.html Prettier
-```
-
-Running before saving async (vim 8+):
-
-```vim
-autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.yaml,*.html PrettierAsync
-```
-
-Running before saving, changing text or leaving insert mode:
+To running vim-prettier not only before saving, but also after changing text or leaving insert mode:
```vim
" when running at every change you may want to disable quickfix
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
+autocmd TextChanged,InsertLeave *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.yaml,*.html PrettierAsync
```
### Overwrite default prettier configuration
diff --git a/autoload/prettier.vim b/autoload/prettier.vim
index d4c3171..ebe6abd 100644
--- a/autoload/prettier.vim
+++ b/autoload/prettier.vim
@@ -36,7 +36,9 @@ endfunction
" Allows @format and @prettier pragma support upon saving
function! prettier#Autoformat(...) abort
- call prettier#Prettier(1, 1, line('$'), 0, { 'requirePragma': 'true'})
+ call prettier#Prettier(1, 1, line('$'), 0, {
+ \ 'requirePragma': g:prettier#autoformat_require_pragma ? 'true' : 'false'
+ \ })
endfunction
" Main prettier command
diff --git a/plugin/prettier.vim b/plugin/prettier.vim
index 4ffa9cb..01eb098 100644
--- a/plugin/prettier.vim
+++ b/plugin/prettier.vim
@@ -20,6 +20,9 @@ let g:loaded_prettier = 1
" autoformating disabled by default upon saving
let g:prettier#autoformat = get(g:, 'prettier#autoformat', 0)
+" autoformating requires pragma by default
+let g:prettier#autoformat_require_pragma = get(g:, 'prettier#autoformat_require_pragma', 1)
+
" whether to turn autoformatting on if a prettier config file is found
let g:prettier#autoformat_config_present = get(g:, 'prettier#autoformat_config_present', 0)