question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trimming final newline is not POSIX standards compliant

See original GitHub issue

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.63.2
  • OS Version: Ubuntu 20.04

Steps to Reproduce:

  1. Type anything in the editor and save it to a file
  2. Run cat to read the file

I am becoming increasingly annoyed by Visual Studio Code users because files are created without final newline.

Screenshot from 2022-01-21 19-23-19

This results in mangled shell prompt as shown above. In a sane world shell prompt starts on a new line.

Feel free to do this on Windows, but don’t bring this madness to Linux and Mac. You’re just wasting our time explaining how to turn off trimming and why trimming is bad.

In POSIX line ends with newline: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_206 and text file consists of 0 or more lines: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_403 Hence text file ends with a newline character

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:12
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
lattwoodcommented, Dec 8, 2022

@alexdima what about POSIX macOS?

While changing the default may be unexpected for some users who are accustomed to working around the lack of newline at the end, they’re literally working around a bug. 😂

This kinda smells of the emacs-spacebar xkcd. https://xkcd.com/1172/

edit: I checked the Wikipedia article on POSIX.

  • macOS: POSIX Certified
  • Linux: mostly POSIX-compliant
  • Windows: requires WSL or other POSIX compatibility layers for it

This has become a bit of a recurring issue everywhere I’ve worked. People that use vim/emacs/sublime/IntelliJ end up producing POSIX compliant files, but the folks using VSCode don’t, and they have to be reminded every pull request. While developers should be comfortable configuring their tools, they should come with sane defaults.

Edit 2: on further reflection, anyone who needs to produce a file that doesn’t end in a newline knows they need to, but everyone should be creating files that end with a newline by default. This came after reading @laurivosandi’s comment below.

4reactions
laurivosandicommented, Jan 21, 2022

This default does not adhere to POSIX standard. People should not take extra steps to be standards compliant.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is a NEWLINE character at line end required by LSB (Linux ...
The POSIX standard tells us that a line is. A sequence of zero or more non- <newline> characters plus a terminating <newline> character....
Read more >
What's the significance of the "No newline at end of file" log?
It indicates that you do not have a newline (usually \n , aka LF or CRLF) at the end of file. That is,...
Read more >
Newline - Wikipedia
Newline is a control character or sequence of control characters in character encoding specifications such as ASCII, EBCDIC, Unicode, etc.
Read more >
2. Shell Command Language
Since the escaped <newline> is removed entirely from the input and is not replaced by ... Quote removal (see Quote Removal) shall always...
Read more >
Changing {% include %} to strip a trailing newline
The reporter suggested removing the trailing newline in the attrs.html template but Adam Johnson reported: "POSIX states that all text files ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found