This is an archive of the discontinued LLVM Phabricator instance.

Add missing NL (new line) at EOF (end of file)
ClosedPublic

Authored by mteodor on Sep 12 2017, 1:46 AM.

Details

Summary

clang-format.exe removes trailing new lines at end of file.

However, if no NL is found at EOF one should be added.

Let me know if you prefer this to be optional. Other Visual Studio extensions have this functionality configurable.

Diff Detail

Repository
rL LLVM

Event Timeline

mteodor created this revision.Sep 12 2017, 1:46 AM
mteodor retitled this revision from Add missing "NL" (new line) at EOF (end of file) to Add missing NL (new line) at EOF (end of file).Sep 12 2017, 1:49 AM
mteodor edited the summary of this revision. (Show Details)
hans edited edge metadata.Sep 13 2017, 11:47 AM

(Meta comment: please upload patches with more context so the rest of the files show up in the review. If you generate the patch with diff or git diff, do it by passing along -U9999.)

I don't know much about VS, but doesn't it already have an option to save files with newline at end of file?

If we want clang-format to do this, should it perhaps be part of clang-format.exe itself, rather than the plugin?

In D37732#869928, @hans wrote:

I don't know much about VS, but doesn't it already have an option to save files with newline at end of file?

Unfortunately, it doesn't have this option.

If we want clang-format to do this, should it perhaps be part of clang-format.exe itself, rather than the plugin?

That would be even better. However, since this is practically a Windows only problem I don't have many hopes.

In Linux/UNIX world, the POSIX requirement for LINE termination is implemented virtually by all text editors. Some don't even have an option to do otherwise.

hans added a comment.Sep 20 2017, 10:45 AM
In D37732#869928, @hans wrote:

I don't know much about VS, but doesn't it already have an option to save files with newline at end of file?

Unfortunately, it doesn't have this option.

If we want clang-format to do this, should it perhaps be part of clang-format.exe itself, rather than the plugin?

That would be even better. However, since this is practically a Windows only problem I don't have many hopes.

In Linux/UNIX world, the POSIX requirement for LINE termination is implemented virtually by all text editors. Some don't even have an option to do otherwise.

OK, I suppose that's a good case for donig this in the plugin.

I wonder if we'll need to expose this as a plugin option though, in case some users (for weird reasons, but some people seem to like it that way) don't want newline at the end of the file..

ClangFormatPackage.cs
331 ↗(On Diff #114780)

Please upload the file with context so it's easier to review.

445 ↗(On Diff #114780)

This lookslike an unrelated formatting change?

mteodor updated this revision to Diff 116308.Sep 22 2017, 12:29 AM

Update patch for full context (U9999).

Also, I removed the second part of the patch.

mteodor marked 2 inline comments as done.Sep 22 2017, 12:30 AM
mteodor added inline comments.Sep 22 2017, 12:33 AM
ClangFormatPackage.cs
445 ↗(On Diff #114780)

That was not a formatting change, but an attempt to make sure the Edit is closed after each Clang Format execution.

In D37732#876591, @hans wrote:

I wonder if we'll need to expose this as a plugin option though, in case some users (for weird reasons, but some people seem to like it that way) don't want newline at the end of the file..

We could add it later if requested. However, in my experience with this issue the response from other devs was: I don't care about this!.

Thus, this is only an editor problem so that we don't have to deal with it manually. No arguments against it.

hans accepted this revision.Sep 22 2017, 9:25 AM

This looks good to me. Do you have commit access, or would you like me to commit for you?

Update patch for full context (U9999).

Also, I removed the second part of the patch.

Thanks!

In D37732#876591, @hans wrote:

I wonder if we'll need to expose this as a plugin option though, in case some users (for weird reasons, but some people seem to like it that way) don't want newline at the end of the file..

We could add it later if requested. However, in my experience with this issue the response from other devs was: I don't care about this!.

Thus, this is only an editor problem so that we don't have to deal with it manually. No arguments against it.

Fair enough.

This revision is now accepted and ready to land.Sep 22 2017, 9:25 AM
In D37732#878897, @hans wrote:

This looks good to me. Do you have commit access, or would you like me to commit for you?

I don't have svn commit access. Please do that.

klimek edited edge metadata.Sep 25 2017, 4:56 AM

For what it's worth, I think it'd also be fine to always add a newline at the end of a file in clang-format, or have an option. I think this is fine, too, though.

This revision was automatically updated to reflect the committed changes.
danra added a subscriber: danra.Jun 24 2021, 5:53 AM
In D37732#876591, @hans wrote:
In D37732#869928, @hans wrote:

I don't know much about VS, but doesn't it already have an option to save files with newline at end of file?

Unfortunately, it doesn't have this option.

If we want clang-format to do this, should it perhaps be part of clang-format.exe itself, rather than the plugin?

That would be even better. However, since this is practically a Windows only problem I don't have many hopes.

In Linux/UNIX world, the POSIX requirement for LINE termination is implemented virtually by all text editors. Some don't even have an option to do otherwise.

OK, I suppose that's a good case for donig this in the plugin.

FWIW, I would be happy to have this in clang-format itself. With a few coders working on a few editors on different platforms, missing lines at EOF are likely to sneak in occasionally, requiring cleanup commits.