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

saving a file ignored in .prettierignore outputs part of the file back to the buffer #140

Closed
jesusgollonet opened this issue Jun 12, 2018 · 10 comments · Fixed by #142
Closed
Labels

Comments

@jesusgollonet
Copy link

jesusgollonet commented Jun 12, 2018

Description

If a file is part of .prettierignore, when editing the file and saving i'll get part of the buffer echoed back to the buffer.

Simplest test case

index.js

console.log('hello');
console.log('hello');

.prettierignore

index.js

open index.js and save, you'll get the following contents on the buffer

console.log('hello');
console.log('hello');console.log('hello');

save again and you'll get

console.log('hello');
console.log('hello');
console.log('hello');console.log('hello');console.log('hello');

etc.

The expected behaviour is that editing files which are ignored folder should work correctly, i.e: vim-prettier should do nothing with them.

Versions

vim-prettier 0.2.7
prettier 1.13.5
:PrettierCliPath prettier
Vim VIM - Vi IMproved 8.1 (2016 Sep 12, compiled Oct 2 2017 08:19:22) MacOS X (unix) version

It feels related to #92 but not sure

FWIW in vim 8.0.2 this bug was manifesting in completely blocking vim. I upgraded just now to see if that would fix it.

Cheers

@jesusgollonet jesusgollonet changed the title editing a file in an ignored folder with .prettierignore outputs part of the file back to the buffer saving a file ignored in .prettierignore outputs part of the file back to the buffer Jun 12, 2018
@mitermayer
Copy link
Member

Hi @jesusgollonet,

Thanks for reporting this issue. We will try to replicate this and comment in here our findings and in case we can confirm as a bug we will take action and try to fix it.

@jesusgollonet
Copy link
Author

It might not necessarily be caused by .prettierignore. Just now I got the same issue with a codebase that does not have .prettierignore or .prettierrc for that matter. I tried to disable other plugins to see if there was any strange interactions but couldn't find anything. I disabled vim-prettier and the issue was gone.

Don't have any experience with vim plugins unfortunately so not sure if I can help figure it out, but if you need help debugging do ping me. I've had to disable it for now as this makes it unusable but will take a look when i get some time (I really like it otherwise)

Cheers,
j

@mitermayer
Copy link
Member

Hi @jesusgollonet

I wonder if this could be a regression that we may have introduced in 0.2.7 do you mind trying to run vim-prettier with version 0.2.6 to see if the issue still occurs ?

Also do you have any vim-prettier configuration settings defined on your .vimrc ? Do you have any global .prettierc setup anywhere ?

Please try using vim-prettier with older release by updating your .vimrc to this

Plug 'prettier/vim-prettier', { 'tag': '0.2.6' }

Sorry for this inconvenience and we would love to help understand why this is happening. It looks like prettier is being run twice and is then duplicating the output

@jesusgollonet
Copy link
Author

jesusgollonet commented Jun 14, 2018

Hey! hah no need to be sorry. Glad to help pinpoint this

It looks like a regression on 0.2.7 indeed. I just Installed 0.2.6 and from a quick test in my test repo the behaviour was corrrect. As a double check I then reinstalled 0.2.7 and the bug was back.

This is the vim-prettier config i have in my .vimrc

let g:prettier#config#parser = 'babylon'
let g:prettier#autoformat = 0
autocmd BufWritePre *.js,*.json,*.css,*.scss,*.less,*.graphql PrettierAsync:w

However commenting those out didn't seem to change the behaviour (i.e: the bug was still present)

I don't have a global .prettierrc and it has happened for repos that both did and didn't have a local one.

Re: duplication, I was using neoformat before, but I was only enabling it on a project basis via a .vimrc.local and it was not enabled on the codebases where I ran into this bug.

@jesusgollonet
Copy link
Author

jesusgollonet commented Jun 14, 2018 via email

@mitermayer
Copy link
Member

cc @SamHowie ^^

@mitermayer
Copy link
Member

@jesusgollonet do you mind trying to update your .vimrc line from:

autocmd BufWritePre *.js,*.json,*.css,*.scss,*.less,*.graphql PrettierAsync:w

to

autocmd BufWritePre *.js,*.json,*.css,*.scss,*.less,*.graphql PrettierAsync

The command PrettierAsync already saves the file by default, the reason why its breaking for you is that you are saving the file twice upon each save. So when prettier response is back and format your document you are asking it to format it again as that line on your vimrc states that whenever the buffer is saved we should format it.

Can you try updating your .vimrc to remove the :w on the end and see if that fixes problem for you on 0.2.7 ?

@SamHowie
Copy link
Collaborator

@jesusgollonet

I have managed to reproduce your issue. It only occurs for me if a .prettierignore file exists and the file being saved is in the .prettierignore list.

I can verify that @mitermayer's suggestion above will not fix the problem (though it is probably a good idea to make that change anyway ;)

Now that I can reproduce it, I should be able to debug what's going on.

If 0.2.6 is working for you, I suggest staying on that release until a fix is in place. Sorry for the inconvenience.

@SamHowie
Copy link
Collaborator

@jesusgollonet

I have managed to reproduce your issue. It only occurs for me if a .prettierignore file exists and the file being saved is in the .prettierignore list.

I can verify that @mitermayer's suggestion above will not fix the problem (though it is probably a good idea to make that change anyway ;)

Now that I can reproduce it, I should be able to debug what's going on.

If 0.2.6 is working for you, I suggest staying on that release until a fix is in place. Sorry for the inconvenience!

@jesusgollonet
Copy link
Author

hey! no worries. I can also use 0.2.7 with

autocmd BufWritePre *.js,*.json,*.css,*.scss,*.less,*.graphql Prettier

which doesn't seem to have the issue. Again, let me know if I can help in any way.

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

Successfully merging a pull request may close this issue.

3 participants