From 0fcbb94bec20d4ddba7ea7943e73ee59299624c3 Mon Sep 17 00:00:00 2001 From: Emmanuel Joubaud Date: Thu, 20 Apr 2023 11:34:14 +0200 Subject: [PATCH] Explain how to disable vim-prettier default settings in readme I spent a while figuring out why vim-prettier was adding some default CLI options like `--tab-width=4`, which was breaking my CI build checking the codebase against a .prettierrc that (obviously) didn't include vim-prettier's default settings. In case anyone encounters a similar issue, here's what I found out: 1. vim-prettier always adds a bunch of CLI flags with its own default settings to the prettier command it runs. See https://github.com/prettier/vim-prettier/blob/e122231/autoload/prettier/resolver/config.vim#L8 2. it even overrides some of its own default settings, like if `g:prettier#config#tab_width` is set to `auto` (the default), it will set it to the value of the `shiftwidth` vim setting (see https://github.com/prettier/vim-prettier/blob/e122231/autoload/prettier/resolver/config.vim#L56). In my case it would set it to 4 on markdown files There's no option to prevent vim-prettier from adding all those CLI flags, but mercifully we can ask prettier to ignore them whenever a config file is passed with the `--config-precedence prefer-file` option. --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 8636310..6c05bed 100644 --- a/README.md +++ b/README.md @@ -282,6 +282,13 @@ let g:prettier#config#require_pragma = 'false' let g:prettier#config#end_of_line = get(g:, 'prettier#config#end_of_line', 'lf') ``` +To ignore vim-prettier default settings when a config file is found, set `config_precedence` to +[`file-override`](https://prettier.io/docs/en/cli.html#--config-precedence): + +``` +let g:prettier#config#config_precedence = 'file-override' +``` + ### REQUIREMENT(S) If the `prettier` executable can't be found by Vim, no code formatting will happen