Skip to content
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

Closed
wants to merge 5 commits into from

Conversation

joaocgreis
Copy link
Member

Checklist
  • tests and code linting passes
  • the commit message follows commit guidelines
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 by autocrlf 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 using autocrlf should not be affected.

Fixes: #6912

cc @nodejs/testing @nodejs/platform-windows

@joaocgreis joaocgreis added meta Issues and PRs related to the general management of the project. tools Issues and PRs related to the tools directory. labels May 27, 2016
@ChALkeR ChALkeR added the windows Issues and PRs related to the Windows platform. label May 27, 2016
@@ -1,2 +1,13 @@
* text=auto
Copy link
Member

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 

Copy link
Member Author

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"]
Copy link
Contributor

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).

Copy link
Member

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.

Copy link
Member

@Trott Trott Jun 1, 2016

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.
@joaocgreis
Copy link
Member Author

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 text=auto has been working well in Windows for a long time. Furthermore, a checkout of master and a checkout of this PR without the last commit are binary equal (except for the files changed here). So, I believe that this PR without the last commit is the best trade-off.

@orangemocha
Copy link
Contributor

orangemocha commented Jun 17, 2016

+1 for undoing the last commit, and using text=auto.

@joaocgreis
Copy link
Member Author

@bnoordhuis would a change in tools/jslint.js to check for CRLF when process.platform === 'win32' be better in your opinion?

@bnoordhuis
Copy link
Member

That seems like a reasonable solution.

@a-metta
Copy link
Contributor

a-metta commented Sep 10, 2016

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.

@Trott
Copy link
Member

Trott commented Sep 18, 2016

@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:

node tools\eslint\bin\eslint.js --fix --cache --rulesdir=tools\eslint-rules benchmark lib test tools

This is basically what vcbuild.bat lint runs, but with the --fix option added.

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

@joaocgreis
Copy link
Member Author

joaocgreis commented Sep 19, 2016

I have another fix for this in progress, with changes in tools/jslint.js as mentioned above. Just have to test it well and I'll open a PR.

@a-metta
Copy link
Contributor

a-metta commented Sep 19, 2016

@Trott thanks, that actually fixes the tests and i can run vcbuild test 👍
@joaocgreis that's awesome! let me know if you want any additional testing done and i can absolutely help out 👍

@Trott
Copy link
Member

Trott commented Sep 19, 2016

@joaocgreis Note that there has been a change such that the jslint task in Makefile and vcbuild.bat no longer uses jslint.js so that it can take advantage of ESLint's caching of results. On CI, we still use jslint.js. Since we don't have this problem on CI, you can probably ignore jslint.js.

You can change vcbuild.bat to override the rule on the command line. http://eslint.org/docs/user-guide/command-line-interface#rule I think you can disable the rule with --rule='linebreak-style: 0'.

@joaocgreis
Copy link
Member Author

Replaced by #8785

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
meta Issues and PRs related to the general management of the project. tools Issues and PRs related to the tools directory. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

jslint fails with linebreak on windows
6 participants