Skip to content

autoformat_config_present does not re-evaluate the presence of the prettier config file after vim is started #233

@cjlarose

Description

@cjlarose

Do you want to request a feature or report a bug?

Bug

What is the current/expected behavior?

The logic surrounding autoformat_config_present basically only runs once (when the plugin is loaded). It is desirable for that logic to be deferred until the buffer is actually written in at least two cases:

  1. If you create a prettier config file in the project after you started the vim instance or
  2. If you just happened to have started vim in a different directory, then :cd'ed into the directory where a prettier config file resides (or a subdirectory of such a directory)

The former bug is hopefully straightforward, but I've given more detail for the latter bug below in case it's not clear.

STR:

In .vimrc

let g:prettier#autoformat = 0 " default setting
let g:prettier#autoformat_config_present = 1 " default is 0

Example project structure:

mkdir vim-prettier-pwd-test
mkdir vim-prettier-pwd-test/plugin
echo '{}' > vim-prettier-pwd-test/plugin/.prettierrc
cat > vim-prettier-pwd-test/plugin/index.ts <<'EOF'
/**
 * @format
 */
console.log('hello');
EOF
tree -a vim-prettier-pwd-test
vim-prettier-pwd-test
└── plugin
    ├── .prettierrc
    └── index.ts

1 directory, 2 files

Open vim, :cd (or :lcd or :tcd in nvim), open the file and save

cd vim-prettier-pwd-test
nvim
:cd plugin
:e index.ts
:w

Expected

Prettier runs when you save the buffer

Observed

Prettier does not run

What version of vim-prettier are you using - (output of :PrettierVersion) ?

1.0.0-alpha

What version of prettier are you using - (output of :PrettierCliVersion) ?

2.0.4

What is your prettier executable path - (output of :PrettierCliPath) ?

/Users/chris.larose/vim-prettier-pwd-test/plugin/node_modules/.bin/prettier

Did this work in previous versions of vim-prettier and/or prettier ?

Pretty sure the same behavior has been present since the introduction of autoformat_config_present in #212

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions