Line terminators
See original GitHub issuehttp://www.ecma-international.org/ecma-262/7.0/index.html#sec-line-terminators
Code Point Unicode Name Abbreviation U+000A LINE FEED (LF) <LF>
U+000D CARRIAGE RETURN (CR) <CR>
U+2028 LINE SEPARATOR <LS>
U+2029 PARAGRAPH SEPARATOR <PS>
…
LineTerminatorSequence:: <LF> <CR>[lookahead ≠ <LF>] <LS> <PS> <CR><LF>
(In practice these days, everyone uses \n
/<LF>
except Windows which uses \r\n
/<CR><LF>
.)
It seems like prettier sometimes assumes that \n
/<LF>
is the only newline. We need to grep through the code base and fix those cases.
A question is how it should be fixed. Use utility functions everywhere? It’s easy to forget, though, and add new places of .indexOf('\n')
and similar in the future. Another idea is to replace all other newlines before parsing: text.replace(/\r\n|[\r\u2028\u2029]/g, '\n')
.
EDIT: No we cannot replace all line terminal sequences before parsing. That would change the contents of template literals and multiline strings.
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Line terminator - Wikipedia
Line terminator · Newline, a special character or sequence of characters signifying the end of a line of text · Electrical termination, at...
Read more >What is a Line Terminator and how does it apply to comments?
A line terminator is an actual ascii character which is invisible to humans but important to computers. The line terminator character tells ...
Read more >Line terminators - Informatica Documentation
A line terminator is a one or two-character sequence that marks the end of a line of the input character sequence. The following...
Read more >3.4. Line Terminators - The Java® Language Specification ...
3.4. Line Terminators ... A Java compiler next divides the sequence of Unicode input characters into lines by recognizing line terminators. ... Lines...
Read more >Line terminators on Windows and UNIX - 4Js
On Windows™ platforms, DOS formatted text files use CR/LF as line terminators. You can manage these type of files with the base.Channel class....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Hashnode Post
No results found
I don’t think that we should handle anything except for \r and \r\n. For those two, we should have good support, if something is broken, please report an error and we’ll fix it. The big things are:
Looks like there’s a few places where we only consider \n in the printer https://github.com/jlongster/prettier/blob/master/src/printer.js that we need to fix (search for \n)
Just for future reference:
This statement is wrong. prettier already does exactly this normalization. And it leaves all line terminator characters inside strings alone as it should.