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

FormatCode adds line filled with spaces when run on .cc file #217

Open
jeroen-dhollander opened this issue May 9, 2023 · 3 comments
Open

Comments

@jeroen-dhollander
Copy link

Description

Running :FormatCode on a cpp source (not header) file causes a trailing line filled with whitespaces to appear at the end of the document.
Running :FormatCode again and again removes and re-adds and removes and ... this line.

Steps to reproduce

  1. Use this init.vim file:
call plug#begin('~/.local/share/nvim/plugged-minimal')
Plug 'google/vim-maktaba' " Needed for vim-codefmt
Plug 'google/vim-glaive' " Needed for vim-codefmt
Plug 'google/vim-codefmt' " Code formatting
call plug#end()
  1. Open any .cc file (for example I use base/run_loop.cc from the chromium project

  2. Run :FormatCode. Observe line with trailing whitespaces at the end of the file

  3. Run :FormatCode. Observe line with trailing whitespaces at the end of the file is gone.

  4. Repeat

My Setup

  • 'vim-codefmt' is up-to-date (I ran :PlugUpdate)
─❯ nvim --version
NVIM v0.7.2
╰─❯ clang-format --version
clang-format version google3-trunk (30af2fb33ed2f610abfa50e53df9712887b2bd25)

Gif of the bug

bug

Other things I tried

  • Manually running clang-format -i base/run_loop.cc from the command line does not introduce these whitespaces, which is why I opened the bug against vim-codefmt and not clang-format.

Please let me know if you need any more information.

Thanks!

@dbarnett
Copy link
Contributor

Can you confirm if clang-format is the actual formatter being used here? Tab complete after :FormatCode to see what formatters are installed and apply to .cc files, and check if running the one for clang-format has the same issue.

@jeroen-dhollander
Copy link
Author

Thanks for the response. I can confirm it is caused by clang-format (by running :FormatCode clang-format which reproduces the issue):

image

@jeroen-dhollander
Copy link
Author

Update: It is related to the presence of InsertNewlineAtEOF in the chromium .clang-format file.

Setting that to false (or removing it) makes the bug go away.

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

No branches or pull requests

2 participants