<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63150>63150</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-format option InsertNewlineAtEOF does not add newline
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
jasonfsmitty
</td>
</tr>
</table>
<pre>
On Fedora 36, running a local build from source of LLVM 16.0.4
The clang format option `InsertNewlineAtEOF : true` is not being applied, instead the newline is being removed:
```
[smithj1]$ /opt/llvm-16.0.4/bin/clang-format --version
clang-format version 16.0.4
[smithj1]$ printf "namespace aaa {}\n\n"
namespace aaa {}
[smithj1]$ printf "namespace aaa {}\n\n" | /opt/llvm-16.0.4/bin/clang-format --style="{ InsertNewlineAtEOF : true }"
namespace aaa {}
[smithj1]$ printf "namespace aaa {}\n\n" | /opt/llvm-16.0.4/bin/clang-format --style="{ InsertNewlineAtEOF : false }"
namespace aaa {}
[smithj1]$
```
This also happens in our codebase, where we leverage .clang-format files to auto-format sections of our repo:
```
[smithj1]$ grep NewlineAtEOF .clang-format
InsertNewlineAtEOF: true
[smithj1]$ cat test.cpp
#include <iostream>
int main(int argc, char* argv[])
{
std::cout << "Hello World" << std::endl;
return 0;
}
[smithj1]$ /opt/llvm-16.0.4/bin/clang-format --style=file -Werror test.cpp
#include <iostream>
int main(int argc, char* argv[])
{
std::cout << "Hello World" << std::endl;
return 0;
}
[smithj1]$
```
One counter-point that I can't explain, is that clang-format _does_ format properly when using plugins in VS Code and vim.
For vim, I'm using the [vim-clang-format](https://github.com/rhysd/vim-clang-format) plugin, with the following in `.vimrc`:
```
let g:clang_format#command = "/opt/llvm-16.0.4/bin/clang-format"
let g:clang_format#auto_format = 1
let g:clang_format#detect_style_file = 1
let g:clang_format#auto_filetypes = [ "c", "cpp" ]
let g:clang_format#enable_fallback_style = 0
```
If I open a file and save it with vim, it formats the file correctly including adding the newline at EOF.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcVk2P2zYQ_TX0ZWBDpixpffDBHxG6QNo9tEiOBkWOLKYUSZCUt_73BSk5WTdbZ7OnooBtWCI5b97MeySZ9_KkETek2JHiMGND6IzbfGHe6Nb3MoTLrDHisnnSUKMwjkFeEroHN2gt9QkYKMOZgmaQSkDrTA_eDI4jmBY-fvz0KyzLRbZYkexAsu34-0eHwBXTJ2iN61kAY4M0GkiZPWqPLvyGz0pq3IYPTzWQfAvBDUjKDKQHbQI0mKCtVRJFzEZqH5AJCB2CHhfHueM8h705oyD59mUSpMymz_hY7CLd7suSFAdCV0BobWwgtFbq3M8nErRupCa0TtnPp-zn8zM6L40eI92MTSO3RfgnlHVShxYIpZr16C3jCIwxINWOVAdS7HX6Ujquf3XSS2bvjg-k2v8UcR8uCkl-iLlVO7jTPYhIb2DwX8u9Zcq_N_nXhTZZQHpgyhvomLWoPUgNZnDAjcCGeYyqfu7QITwjKDyjYyeExQ2HVir0EAywIZjrS488mslH_8WADq35SemfHFq4qcQt7rjs-4J9derrYTkLENCHBbd2ikFoLjVXg0Ag-V4aHxyynuQfXqYrdYCexRY-xL_MnXisDu-YI3Qbn8_j7kXoelpX7a4B1j4k5-dbboYQUUgedUJ_QaUMfDZOiaSeceDrbNRCkfxbGIdhcBqyb-9-YLr3SDE2FOaf0Tnj_pelertBnjQCN4MO6ObWRDKhYwEegTNNaBUA_7IqMd3HnT4N3lT1KAz64_WEsc5YdOoSPaVh8PFcsGo4ydF5n36HvREITAs4y37xMpPauPguAj0SWvXT6njUkGJ3lv38JW4i9tCFYH2sDq0JrU8ydEOz4KYntHbdxQtC6-8W0vWUUbK-DF2CaI1S5jkCynRALs6ydzwW666nFQY4xU5GhOMVIeem7yNHkh9iY9-s0a-b37_EjRvQ8bo75AdY3p0tMCAPx6T6Y9L8j9eMCFJhuFj0I4FiF0nwRCQJlVubBFoc7sZCzZqIzJRqGP9zTCSFzO4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