Vim-prettier: Vim-prettier doesn't use project config

Created on 18 Nov 2018  ยท  27Comments  ยท  Source: prettier/vim-prettier

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

What is the current/expected behavior?
Vim-prettier is not using project's config. This is my config:

module.exports = {
  printWidth: 80,
  tabWidth: 2,
  useTabs: false,
  semi: true,
  singleQuote: false,
  trailingComma: "all",
  bracketSpacing: true,
};

And when I type :Prettier it formats my code from:

import { x } from "x"; to import {x} from 'x';

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

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

What is your prettier executable path - (output of :PrettierCliPath) ?
/Volumes/D\ 2/projects/foo/node_modules/.bin/prettier

Did this work in previous versions of vim-prettier and/or prettier ?
Dunno, I'm using it first time

Maybe I skiped some instalation step? I'm using Vundle as plugin manager, I've added line Plugin 'prettier/vim-prettier' and typed yarn install at .vim/bundle/vim-prettier.

bug help wanted

Most helpful comment

I have the same issue.

All 27 comments

Hi @szymkab

Can you please provide a bit more context on this issue ?

  • You have pasted the snippet of your config, however could you also let me know how is that saved as ? Is it a .prettierrc ? Is it a prettier.config.json ? Is it on your package.json ?
  • When you run the command prettier, did you edit a file that exists within the scope of the project where you defined that config file ? If you traverse the file you are editing upwards would you find the config file ?
  • if you run prettier from the command line from the same place where you opened vim, do you get same results ?

Thanks a lot!

  1. prettier.config.js
  2. Yes it is in the scope of the project and I would find it if I traverse upwards. Structure looks like this:
Project Root/
โ”‚
โ”œโ”€โ”€ source/
โ”‚   โ””โ”€โ”€ bar/
โ”‚       โ””โ”€โ”€ foo.js
โ””โ”€โ”€ prettier.config.js
  1. If I run prettier from cli it formats files according to config rules.

Will try to reproduce this issue and keep you posted. Do you have any custom vim-prettier configuration on your .vimrc ?

Nope, I don't have

I have the same issue.

Since 2 people are confirming this issue I will try to replicate this again

not respecting my package.json, or .prettierrc either. Updated to latest master as of today.

@ryanflorence thanks for checking, I will try to find some time to fix this ASAP. It looks like a regression caused by some incompatibilities with latest prettier bin releases.

I will try to investigate this ASAP, in the meantime I am also open for PR's

In the meantime can you all test adding this to your vimrc ?

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

I will investigate this issue as soon as I can get some free time

I would like to investigate prettier cli itself. It sounds like a regression. Note that https://prettier.io/docs/en/cli.html#config-precedence

prefer-file
If a config file is found will evaluate it and ignore other CLI options. If no config file is found CLI options will evaluate as normal.
This option adds support to editor integrations where users define their default configuration but want to respect project specific configuration.

Can you folks try again on release/1.x ?

To test this on the release/1.x branch do on your .vimrc

Plug 'prettier/vim-prettier', {
  \ 'do': 'yarn install',
  \ 'branch': 'release/1.x',
  \ 'for': [
    \ 'javascript',
    \ 'typescript',
    \ 'css',
    \ 'less',
    \ 'scss',
    \ 'json',
    \ 'graphql',
    \ 'markdown',
    \ 'vue',
    \ 'lua',
    \ 'php',
    \ 'python',
    \ 'ruby',
    \ 'html',
    \ 'swift' ] }

Unfortunately, I'm seeing the same behavior. Unless I have something configured incorrectly.

@esparkman any chance you could create a small repro ? I would love to fix this ASAP or at least find out what is happening.

@mitermayer for sure I'll let you know here when it's pushed up.

Will look into it soon and comment in here the findings and follow up steps. Thanks a lot for that

@esparkman some questions that may aid on my investigations:

  • Where were you opening vim from ? (the root of the project, the same directory of the file ? other..?
  • Which file was it failing for you ?

thanks a lot!

I open from the Projects root directory

vue-admin-dashboard on ๎‚  master via โฌข v10.15.0
โ€ข3% โžœ vim .

From within the Project I've been testing in src/components/Header.vue
I don't have Lint on Save enabled. So I am manually running :Prettier when I want to lint.

Should now be fixed on release/1.x branch https://github.com/prettier/vim-prettier/pull/160

Pleas make sure to update prettier deps to latest when testing

Cc @shuLhan

Could you test this case to see if your PR fixed this issue ? (Please if possible check with the latest prettier CLI install dep)

@mitermayer it seems to work fine for me with the release/1.x branch.

@mitermayer I can't reproduce this issue.

@szymkab are you sure there are no other plugins that may interfere with formatting? Just to make sure, create a new .vimrc, clear all bundles, and retry it again.

Closing this as this is working on release/1.x and I will promoting that version soon

I seem to be having this issue too, and I'm using the release you mentioned earlier, even though it should be there by default already. Still, it doesn't take my config file into account. I'm using a .prettierrc file.

@marcmarina please use master that release has been already merged to master

Was this page helpful?
0 / 5 - 0 ratings

Related issues

christopherball picture christopherball  ยท  4Comments

larister picture larister  ยท  4Comments

dedoyle picture dedoyle  ยท  11Comments

n-xlkt picture n-xlkt  ยท  5Comments

andreiglingeanu picture andreiglingeanu  ยท  12Comments