-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Fix eslint errors on Windows #4364
Fix eslint errors on Windows #4364
Conversation
On Windows, when run `npm run lint`, a **LOT** of the following errors appeared: ``` error Expected linebreaks to be 'LF' but found 'CRLF' linebreak-style ``` This error only occurs on Windows because the `linebreak-style` eslint setting was set to "unix". This is fixed by making the eslint config file a Javascript script and setting the platform based on the build platform. Thus, the `linebreak-style` will be "windows" or "unix" depending on the users platform.
Codecov Report
@@ Coverage Diff @@
## master #4364 +/- ##
==========================================
- Coverage 92.77% 92.75% -0.03%
==========================================
Files 119 119
Lines 8448 8448
==========================================
- Hits 7838 7836 -2
- Misses 610 612 +2
Continue to review full report at Codecov.
|
Can confirm, way too many linebreak errors during lint. |
which is quite bad, as we'll end-up with mixed line breaks if we allow both. |
To add I think this may be better addressed via a .gitattributes and/or a .editorconfig file to force LF. If we merge this in we're not really guaranteeing that someone will be checking out CRLF and then committing LF style. They could even be checking out LF on windows, and then this would cause problems. @addisonElliott can you instead make this function via gitattributes on a per-repo basis as mentioned above? We could also do editorconfig, but not really sure that's needed if gitattributes is properly set. It could be nice, if we can, to auto-set checkout CRLF commit LF only on windows so nothing there gets mad at the files. In that case we could keep the change you've proposed here. |
@flovilmart the CI should catch PRs with CRLF style line endings with the same error as was reported initially here. I don't believe we'd have an issue considering that, even if someone changed the line endings in a commit, should just fail. |
The issue is with git:
For example, the default behavior of git on Windows systems is to convert LF linebreaks to CRLF when checking out files, but to store the linebreaks as LF when committing a change. This will cause the linebreak-style rule to report errors if configured with the "unix" setting, because the files that ESLint sees will have CRLF linebreaks. If you use git, you may want to add a line to your .gitattributes file to prevent git from converting linebreaks in .js files:
…On Nov 21, 2017, 16:12 -0500, Benjamin Wilson Friedman ***@***.***>, wrote:
@flovilmart the CI should catch PRs with CRLF style line endings with the same error as was reported initially here. I don't believe we'd have an issue considering that, even if someone changed the line endings in a commit, should just fail.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Add .gitattributes that will convert line endings automatically to LF when uploading to GitHub
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.
All should be explicitely eol=lf, we don’t have any bat file, so please remove this line.
.eslintrc.json
Outdated
@@ -15,7 +15,6 @@ | |||
}, | |||
"rules": { | |||
"indent": ["error", 2], | |||
"linebreak-style": ["error", "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.
This should be reverted
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.
If we implement the gitattributes file, then the line endings will be converted to LF upon pushing to repository. I removed this line because I found it to be a redundant check in lint.
Do you think it's still worthwhile to have in?
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.
We'll need this to ensure that our lint is appropriate. Even if it may be redundant, without it we're not actually linting properly.
I added a gitattributes file. There is more information about it here. Basically, when cloning the repository, all text files will be converted to the host platform's line endings. The exception is for files where the EOL is specified. I set *.sh files to use LF because I had issues running bootstrap.sh in Cygwin due to this. In addition, I made *.bat files use CRLF files regardless. When committing files to the repository, the text files will be converted to LF. This will not affect your working directory line endings. Since the conversion to the correct line endings will be done upon pushing, I removed the eslint check. Let me check on this but I think the |
As per ESLint doc, you have to force all JS not to convert to CRLF, removing the lint line is not acceptable. See previous comments. |
@flovilmart I'm not sure that there should be an
So setting an eol for each of the filetypes would force it to be LF line endings when cloning the repository which is not what you want for users on Windows since they will need CRLF. The text=auto part will normalize the line endings for checking it into the repository to be LF regardless. |
Update: I did some testing with this branch to ensure that the gitattributes is doing what is desired. I cloned the repository and branch and all files were converted to CRLF except the bootstrap.sh which had LF endings. Next, I uploaded a Javascript file with CRLF line endings on Windows to a new branch. I cloned that on a Linux repository and it had LF line endings. That leads me to believe that it is being uploaded as LF. I can confirm it was uploaded as LF since I downloaded the file straight from Github and it had LF endings. |
But please, leave the lint this way you'll know for sure if nothing as been wrongly changed when cloning on a windows machine. |
Also, worth asking, what's your development environment on windows? editor, shell etc... perhaps we should recommend https://msdn.microsoft.com/en-us/commandline/wsl/about |
Include lint check for line endings
@flovilmart Sure thing, I restored the lint check. The line endings are not converted from CRLF to LF until after pushing to the repository so the lint check determines OS type and sets line break style from there. I am using Cygwin as my shell and Notepad++ as my editor. |
@addisonElliott You would have to explicitly indicate The rule @flovilmart was mentioning is this further down the page. Basically, as it stands we are strictly adhering to LF. I'm pretty sure Notepad++ plays nice with LF line endings too. If you modify the .gitattributes appropriately to preserve LF on checkout (against your global settings) your editor and others should respect it accordingly. |
I see the confusion now! My intention was to have the repository be checked out in whatever line ending suits the OS but convert to LF when committing. Then, my initial change to eslint could stay. I was following based on what you said:
However, it seems @flovilmart was thinking we should just have LF line endings upon checkout and then have the eslint check stay the same. I'm fine with either, just let me know what would be preferred and I'll make the changes accordingly. |
Ahhh, sorry for the confusion in my comment there! Yes, I think it would be nice to have CRLF upon checkout (general habit), but most IDEs and editors and will also play nice with LF nowadays on windows. On that note, and considering we strictly want LF in all cases, I would also like us to go LF on checkout and revert the eslint check 👍 . |
Restore eslint linebreak style check for unix since LF line endings will be enforced
@flovilmart @montymxb Okay, so hopefully this is the final commit! Instead of doing On Windows, if I did I tested this by cloning my repository and specific branch. All files (including ones like PATENTS which has no file extension) were LF line endings. In addition, running lint check received no errors! |
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 took a look at this on windows and I can confirm this looks good! No more crazy amounts of lint errors. If you can just add those few extra types that would be fantastic.
A note for anyone else on windows that these changes only take effect on the initial clone (correct me if I'm wrong). If you already have an existing local repo and then receive these changes your line endings will remain as they were before, and that should be just fine.
@@ -0,0 +1,11 @@ | |||
* text=auto eol=lf | |||
|
|||
*.js text |
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.
We should also add:
- *.txt
- *.yml
- *.sql
Just to be thorough and cover our travis yml, a text test file and some .sql files we use for Postgres. Wouldn't want anything unexpected to sneak through on those.
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.
Good idea. Added
This was necessary because git was showing that the CRLF line endings were being converted to LF for PNG files on Windows
I've restarted the failed test, unrelated to those changes and will merge. |
Awesome, thanks again for helping us out with the windows setup @addisonElliott ! |
* Fix eslint errors on Windows On Windows, when run `npm run lint`, a **LOT** of the following errors appeared: ``` error Expected linebreaks to be 'LF' but found 'CRLF' linebreak-style ``` This error only occurs on Windows because the `linebreak-style` eslint setting was set to "unix". This is fixed by making the eslint config file a Javascript script and setting the platform based on the build platform. Thus, the `linebreak-style` will be "windows" or "unix" depending on the users platform. * Remove linespace ending check in Lint Add .gitattributes that will convert line endings automatically to LF when uploading to GitHub * Remove bat file extension from gitattributes Include lint check for line endings * Change tabs to spaces * Force LF line endings for each file upon downloading Restore eslint linebreak style check for unix since LF line endings will be enforced * Add a few more text files to the gitattributes * Added png as binary file to gitattributes file This was necessary because git was showing that the CRLF line endings were being converted to LF for PNG files on Windows
On Windows, when running
npm run lint
, a LOT of the following errorsappeared:
This error only occurs on Windows because the
linebreak-style
eslintsetting was set to "unix". This is fixed by making the eslint config
file a Javascript script and setting the platform based on the build
OS.
Thus, the
linebreak-style
will be "windows" or "unix" depending on theusers platform.