vim-prettier
vim-prettier copied to clipboard
Run Prettier only if project contains prettier configuration
Do you want to request a feature or report a bug?
feature
What is the current/expected behavior?
Currently Prettier is always called whether the project you're working on is using Prettier or not. I'd like to be able to run prettier only if the project is configured to use Prettier. This behaviour could be enabled using a variable.
What do you think?
What version of vim-prettier
are you using - (output of :PrettierVersion
) ?
0.2.7
What version of prettier
are you using - (output of :PrettierCliVersion
) ?
Prettier: no prettier executable installation found.
What is your prettier
executable path - (output of :PrettierCliPath
) ?
Prettier: no prettier executable installation found.
Did this work in previous versions of vim-prettier and/or prettier ?
I don't know.
Hi @charlyx ,
How did you install vim-prettier
? If you installed using vim-plug
you should still be able to use the prettier
executable even if your project does not have prettier installed.
Otherwise you can always do the following:
- go to vim prettier installation directory
~/.vim/*/vim-prettier/
- install deps with either
npm install
oryarn install
Please note that depending on your OS the installation of vim-prettier
may be in different directories.
Hi @mitermayer, thanks for your answer. I don't have any problem running prettier. I'm asking for a feature I believe does not exist.
My problem is that I would like to not run prettier on every project. I would like to be able to run it only if my project is configured for using prettier. This is what I described in my issue:
Currently Prettier is always called whether the project you're working on is using Prettier or not. I'd like to be able to run prettier only if the project is configured to use Prettier. This behaviour could be enabled using a variable.
I hope my message makes it clearer.
Do you have any idea on the subject though?
That sounds like a reasonable feature request I can work on it
@mitermayer did you have a chance to work on it? If not, I'd be happy to make a PR. Do you have any guidelines to get me started?
Hi @charlyx ,
Sorry been super busy lately with work! A PR would be super welcome! If you do a PR to release/1.x
branch it will be a lot easier to merge as development for master branch are mostly to bugfixes. I probably need to work on vim-prettier
for a day or two to finalize the release
I would also love this feature.
Just remember that not all projects have a prettier configuration file. Some use the default prettier configuration. Perhaps vim-prettier could run only if prettier is named as a direct dependency in package.json.
In the meantime, I solved this by adding this to my init.vim
:
let g:prettier#autoformat = 0
if filereadable(findfile('.prettierrc.js', '.;'))
echo "Using prettier..."
autocmd BufWritePre *.js,*.jsx,*mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.yaml,*.html PrettierAsync
endif
This implementation only searches parent directories for .prettierrc.js
but could be easily expanded to check for other naming variations as well.
FYI: I have a branch that has a new prettier#autoformat_config_present
setting that will toggle auto-formatting based on whether a Prettier config can be found.
However, I haven't submitted a PR yet because I haven't been able to get this to work under master
; only under release/1.x
. According the standard PR submission form, new features should be based off of master
.
@mitermayer Do you have any guidance on how to proceed here? Maybe I should wait until the 1.x
branch has been fully merged?
Update: I've opened a formal PR here. There are still a few loose ends to tie up but feel free to comment.
I will aim to look into this sometime this week or next weekend, been very busy at work but I really want to release 1.x soon!
There are some bugs that i want to fix and some "todo" that i want to clean, but overall is very stable
👋 Just checking in - I know the holidays are coming up so no pressure if you're still tight on time. I've been using this change pretty regularly over the last month or so and have no major issues to report..
Hi @atomdmac, will try to get on this in the holidays! sorry trying to wrap up end of the year goals at work
This issue has been fixed already by @atomdmac
@mitermayer
I updated my plugin and Im still having this issue. Am I missing something?
Will reopen this issue for further investigation
@gWOLF3 Do you have any settings in your vimrc
that pertain to this plugin? I'm wondering if maybe it could just be a configuration issue.
I had the same issue today as @gWOLF3 . Following @mitermayer fixed it.
- go to vim prettier installation directory
~/.vim/*/vim-prettier/
- install deps with either
npm install
oryarn install
About vim-prettier I have nothing special in my .vimrc, only Plug 'prettier/vim-prettier', { 'do': 'npm install' }
. (I didn't installed yarn)
VIM v8.1, Catalina 10.15.4.
Great work, great plugin. Thanks all for your time.
It could also be nice to have the feature to only format if Prettier is in your dependencies.