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.

Default behavior on Windows is to report a failure for every line of every file due to linebreak-style and CRLF

See original GitHub issue

The default behavior of Windows and git on Windows is to use the CRLF pair for line endings. The default behavior of XO on Windows is to report a linebreak-style violation for every line of code in a typical project.

Although it is possible to change the default behavior of git or via .gitattributes, many tools on Windows do not handle LF-only endings well (and not all projects use git).

The most practical workaround seems to be to disable linebreak-style via xo.rules.linebreak-style in package.json, but this is discouraged by the documentation.

The general experience seems a bit harsh and may discourage new users from continuing.

Two solutions come to mind:

  1. Disable the linebreak-style rule by default in XO
  2. Create a top-level linebreak setting in XO (like space and semicolon)

One of the primary appeals of XO is that it is configuration-free. However, the default behavior means that will rarely be possible on Windows.

D:\T>git clone https://github.com/sindresorhus/cat-names.git
Cloning into 'cat-names'...

D:\T>cd cat-names

D:\T\cat-names>npm install xo@0.17.1

D:\T\cat-names>node_modules\.bin\xo

  index.js:1:14
  ×   1:14  Expected linebreaks to be LF but found CRLF.           linebreak-style
  ×   2:56  Expected linebreaks to be LF but found CRLF.           linebreak-style
  ×   3:44  Expected linebreaks to be LF but found CRLF.           linebreak-style
  ×   4:1   Expected linebreaks to be LF but found CRLF.           linebreak-style
  ×   5:24  Expected linebreaks to be LF but found CRLF.           linebreak-style
  ×   6:46  Expected linebreaks to be LF but found CRLF.           linebreak-style

  ...

  39 errors

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:10
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
DavidAnsoncommented, Dec 24, 2016

Checking the state of the world as I write this reply, I find things are better than they used to be. (Yay!)

However:

The default text editor, notepad.exe, shows everything in an LF-only file on one long, unusable line.

The default for all new files is CRLF, such as those created on the command-line: dir > CRLF.txt or in editors like VS Code, etc…

PowerShell can read LF files, but it outputs CRLF by default (as above): Get-Content "LF.txt" | Set-Content "CRLF.txt".

And we’ve covered the default git behavior that needs to be changed. There are many articles about how to do so on the web - which seems like a sign people have trouble understanding/doing so.

It’s possible to adopt an LF-only approach on Windows, but it feels like that’s swimming upstream.

What are the arguments in favor of using LF-only?

2reactions
mastilvercommented, Oct 2, 2017

I used to have this kind of issue, just add the following .gitattributes to the root of your project:

* text=auto
*.js text eol=lf
Read more comments on GitHub >

github_iconTop Results From Across the Web

Expected linebreaks to be 'LF' but found CRLF - Stack Overflow
By default Visual Studio Code opens my files in CRLF (i'm using Windows 10) which causes my git pre-commit hooks to fail. I...
Read more >
CRLF - MDN Web Docs Glossary: Definitions of Web-related ...
CR and LF are control characters or bytecode that can be used to mark a line break in a text file.
Read more >
linebreak-style - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Fixing misaligned Linux and Windows line endings
Windows and Linux line endings don't match, which causes trouble if you're moving files from a Windows desktop to a Linux container.
Read more >
How to Get Consistent Line Breaks in VS Code (LF vs CRLF)
Windows on the other hand is “special” and defaults to CR/LF (carriage ... fix all files in your project that have the wrong...
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