aboutsummaryrefslogtreecommitdiff
path: root/plugin/prettier.vim
diff options
context:
space:
mode:
authorMitermayer Reis <mitermayer.reis@gmail.com>2020-01-08 13:08:21 -0800
committerGitHub <noreply@github.com>2020-01-08 13:08:21 -0800
commitf4e31d67aa1e0658c1a19a26e4bad9fc4691eab9 (patch)
treee5f9a74d33ad77cfbf77a19f44eee828b1aedce8 /plugin/prettier.vim
parent9c216df3a57d35dc90222473a3438697624c9a4f (diff)
parente144afaa17a5c4069c9b86558a2831e729429073 (diff)
downloadvim-prettier-f4e31d67aa1e0658c1a19a26e4bad9fc4691eab9.tar.xz
Merge pull request #212 from atomdmac/toggle-autoformat-by-config
Toggle the autoformat setting based on config file presence.
Diffstat (limited to 'plugin/prettier.vim')
-rw-r--r--plugin/prettier.vim21
1 files changed, 21 insertions, 0 deletions
diff --git a/plugin/prettier.vim b/plugin/prettier.vim
index 83656d3..4ffa9cb 100644
--- a/plugin/prettier.vim
+++ b/plugin/prettier.vim
@@ -20,6 +20,19 @@ let g:loaded_prettier = 1
" autoformating disabled by default upon saving
let g:prettier#autoformat = get(g:, 'prettier#autoformat', 0)
+" 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)
+
+" prettier config files to search current directory and parent directories for
+let g:prettier#autoformat_config_files = get(g:, 'prettier#autoformat_config_files', [
+ \'.prettierrc',
+ \'.prettierrc.yml',
+ \'.prettierrc.yaml',
+ \'.prettierrc.js',
+ \'.prettierrc.config.js',
+ \'.prettierrc.json'
+ \'.prettierrc.toml'])
+
" path to prettier cli
let g:prettier#exec_cmd_path = get(g:, 'prettier#exec_cmd_path', 0)
@@ -139,6 +152,14 @@ nnoremap <silent> <Plug>(PrettierCliPath) :PrettierCliPath<CR>
augroup Prettier
autocmd!
+ if g:prettier#autoformat_config_present
+ if prettier#IsConfigPresent(g:prettier#autoformat_config_files)
+ let g:prettier#autoformat = 1
+ else
+ let g:prettier#autoformat = 0
+ endif
+ endif
+
if g:prettier#autoformat
autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.yaml,*.html noautocmd | call prettier#Autoformat()
endif