Default behavior on Windows is to report a failure for every line of every file due to linebreak-style and CRLF
See original GitHub issueThe 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:
- Disable the
linebreak-style
rule by default in XO - Create a top-level
linebreak
setting in XO (likespace
andsemicolon
)
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:
- Created 7 years ago
- Reactions:10
- Comments:8 (1 by maintainers)
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?
I used to have this kind of issue, just add the following
.gitattributes
to the root of your project: