Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run Prettier only if project contains prettier configuration #182

Open
charlyx opened this issue Apr 2, 2019 · 18 comments
Open

Run Prettier only if project contains prettier configuration #182

charlyx opened this issue Apr 2, 2019 · 18 comments

Comments

@charlyx
Copy link

charlyx commented Apr 2, 2019

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.

@mitermayer
Copy link
Member

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:

  1. go to vim prettier installation directory ~/.vim/*/vim-prettier/
  2. install deps with either npm install or yarn install

Please note that depending on your OS the installation of vim-prettier may be in different directories.

@charlyx
Copy link
Author

charlyx commented Apr 4, 2019

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?

@mitermayer
Copy link
Member

That sounds like a reasonable feature request I can work on it

@charlyx
Copy link
Author

charlyx commented Apr 14, 2019

@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?

@mitermayer
Copy link
Member

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

@openjck
Copy link

openjck commented Jun 20, 2019

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.

@atomdmac
Copy link
Contributor

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.

@atomdmac
Copy link
Contributor

atomdmac commented Oct 9, 2019

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?

@atomdmac
Copy link
Contributor

Update: I've opened a formal PR here. There are still a few loose ends to tie up but feel free to comment.

@mitermayer
Copy link
Member

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

@atomdmac
Copy link
Contributor

atomdmac commented Nov 24, 2019

👋 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..

@mitermayer
Copy link
Member

Hi @atomdmac, will try to get on this in the holidays! sorry trying to wrap up end of the year goals at work

@mitermayer
Copy link
Member

This issue has been fixed already by @atomdmac

@gWOLF3
Copy link

gWOLF3 commented Apr 17, 2020

@mitermayer

I updated my plugin and Im still having this issue. Am I missing something?

@mitermayer
Copy link
Member

Will reopen this issue for further investigation

@mitermayer mitermayer reopened this Apr 17, 2020
@atomdmac
Copy link
Contributor

@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.

@dimitri-bourreau
Copy link

I had the same issue today as @gWOLF3 . Following @mitermayer fixed it.

  1. go to vim prettier installation directory ~/.vim/*/vim-prettier/
  2. install deps with either npm install or yarn 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.

@wylie39
Copy link
Contributor

wylie39 commented Feb 28, 2021

It could also be nice to have the feature to only format if Prettier is in your dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants