vim-prettier icon indicating copy to clipboard operation
vim-prettier copied to clipboard

prettier config default values

Open gko opened this issue 5 years ago • 8 comments

Hello,

Thank you very much for plugin. I use it every day and love it! ❤️

I wanted to ask whether it's really necessary to set the default values for prettier within the plugin: https://github.com/prettier/vim-prettier/blob/7a6fddd0eb41f498ddc24aa6e34063dee7f04c2e/plugin/prettier.vim#L63-L136

The defaults that are present in the plugin are for prettier 2.x, so if you happen to work on a project with prettier 1.9 and forget to set arrow-parens to avoid in your config it will become always and then you will have conflicts with eslint.

Do you think that we probably should not pass the option at all if its value is not specified in prettier config and user .vimrc?

gko avatar Oct 07 '20 13:10 gko

I would also love it if this plugin didn't force a set of options and just let prettier do its own thing. In the mean time, I drafted this workaround:

if prettier#PrettierCli('--version') < '2.0'
  let g:prettier#config#arrow_parens = 'avoid'
end

CGamesPlay avatar Oct 27 '20 08:10 CGamesPlay

The Readme states:

Note: vim-prettier default settings differ from prettier intentionally.

It would be good to know why this is the case. I found this behaviour surprising.

tomgrim avatar Nov 30 '20 12:11 tomgrim

I have been caught out today but vim-prettier using my shiftwidth instead of using the prettier default for tabWidth. I'd be grateful if there was an option to use default as a config value that basically means "don't set it and leave it to whatever prettier wants to do". Perhaps with time I'll adjust my vim to fall inline with the prettier settings but it as been confusing though I can see it is clearly documented.

This is mostly happening because my new team seems to be relying on prettier defaults for a lot so there is no config but my vim setup is old and crufty and so has some file type plugin settings lurking around which don't match prettier and I'd rather the prettier output matched my team and then I could bring my editor inline when I wanted but save in the knowledge that my code fits the team, rather than have the prettier output match my editor and have to bring my editor inline with the team straight away.

Though typing this out, it all sounds a bit subjective. I was just caught out and had to start printing out the command that vim-prettier was running to understand it all.

Thanks for the project though :)

michaeljones avatar Nov 30 '20 17:11 michaeljones

Yeah, a little confused myself as to why there are defaults.

Had to add:-

let g:prettier#config#tab_width = '2'
let g:prettier#config#print_width = '80'

To get it to play nice with eslint at this end. Prettier 2.2.1.

gaving avatar Jan 13 '21 10:01 gaving

The fact that the saved files are not guaranteed to pass prettier --check is a deal-breaking bug for me, unfortunately. Which is a shame, because the plugin works great otherwise!

ojohnny avatar Feb 13 '21 19:02 ojohnny

I've also found this to be a bit of an issue. It looks like we will have to add a config file to our project to set the defaults to whatever prettier is using or alternatively I have to modify my vim configs. I agree with @michaeljones that an option to just use default prettier settings would be preferable if this behaviour is required for others.

samuel-buuk avatar Jul 16 '21 15:07 samuel-buuk

Probably worth pointing out that the official Prettier website also recommends using ALE to handle the rewriting. I've dropped this plugin and switched to it successfully. I wish that ALE had a sync mode, but the experience isn't bad and it does use the proper prettier configuration.

https://prettier.io/docs/en/vim.html#alehttpsgithubcomdense-analysisale

CGamesPlay avatar Jul 16 '21 17:07 CGamesPlay

You can set it to ignore the CLI configuration options in favor of your .prettierrc like this:

let g:prettier#config#config_precedence = 'prefer-file'

twm avatar Oct 28 '21 00:10 twm