-
Notifications
You must be signed in to change notification settings - Fork 30.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable line ending normalization in git, not in the linter #7019
Conversation
@@ -1,2 +1,13 @@ | |||
* text=auto |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wildcard text=auto
is rather dangerous, IMO. It will happily mangle binary files if git perceives them to be text files and can be brutal to debug. I'd use a whitelisting approach, like:
*.js text=auto
*.md text=auto # just an example, don't know if this should apply to *.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used text=auto
for its simplicity. We are testing with it on Windows now, so we know it's most likely working fine. But I agree it can be a pain to debug in extreme cases, I'll try to make something along the lines you suggested.
@@ -60,7 +60,6 @@ rules: | |||
indent: [2, 2, {SwitchCase: 1}] | |||
key-spacing: [2, {mode: "minimum"}] | |||
keyword-spacing: 2 | |||
linebreak-style: [2, "unix"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than removing this rule, can you change its value to the default value? The net result would be the same as removing it, but having the explicit value might prevent people in the future from readding the "wrong" rule (at least they might be prompted to look at the commit history for that line).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unix
is the default value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The options with this rule are unix
, windows
, or disabling/removing the rule. If we want to leave the line there and have the rule explicitly disabled, change 2
to 0
. We don't do that for any other rules, though, if that matters.
Git should convert the line endings of text files to CRLF on Windows and only LF on Unix. It should also convert line endings of text files stored in the repository to only LF.
Linebreak style should be enforced by git in a cross platform way, and not by the linter. Fixes: nodejs#6912
using text=auto this file is handled correctly by git, but with the new configuration it is not. Better add an exception in both cases just in case.
b7188c2
to
a4298de
Compare
Updated. @bnoordhuis the last commit has the best balance of extensions I could come up with (out of close to 400 file extensions and unique file names), but I don't think it should go in. For two reasons:
Letting git handle this with |
+1 for undoing the last commit, and using |
@bnoordhuis would a change in |
That seems like a reasonable solution. |
Hi any updates on this? Currently master is still broken for someone working on windows. I've tried these changes locally and they seem to be fixing running vcbuild test on windows. Let me know if there is anything that I can help with as well. |
@n0f3 This might be not much of an answer, perhaps, but if all your line endings are CRLF and that is the only lint error you are getting, and you don't mind converting to all LF endings, you can use this to have eslint fix the issue for you:
This is basically what As far as this PR, I'd defer to @joaocgreis, @bnoordhuis, and @orangemocha on the status. Although it might not be a terrible idea to ask someone at Microsoft what they think the best solution is. /cc @joshgav |
I have another fix for this in progress, with changes in |
@Trott thanks, that actually fixes the tests and i can run vcbuild test 👍 |
@joaocgreis Note that there has been a change such that the You can change |
Replaced by #8785 |
Checklist
Affected core subsystem(s)
meta, tools
Description of change
After #6685 landed, linting is broken on Windows because line endings are CRLF and the linter expects only LF (ref #6912). The linter rule is necessary because files committed to the repository should be strictly LF.
In Windows, it's recommended to use git with
core.autocrlf=true
, but this was not enforced and the Unix counterpart (core.autocrlf=input
) wasn't even recommended. The first commit of this PR adds* text=auto
to.gitattributes
(as described in https://git-scm.com/docs/gitattributes ), forcing end-of-line normalization for files detected to be text on all systems. Unix users will check out LF files, Windows users will check out CRLF files, and the files stored in the repository will be LF. Git detection of text vs binary files should not be a problem, as it is used byautocrlf
and currently done in CI.Exceptions are added for some text files currently committed as CRLF (only from dependencies), and should be removed when those files are updated. The exception for text fixtures is left as it were, since those were also ignored by ESLint.
With this change, the linter rule is no longer necessary and can be removed, fixing
vcbuild jslint
on Windows.Note: Windows users not using
autocrlf
will have to reset the files in the working dir as explained in https://help.github.com/articles/dealing-with-line-endings/#refreshing-a-repository-after-changing-line-endings . Unix users and Windows users usingautocrlf
should not be affected.Fixes: #6912
cc @nodejs/testing @nodejs/platform-windows