Add .gitattributes to normalize how line endings are stored #4240
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related to issue #4238
Problem
Line endings in the repo are inconsistent between CRLF (Windows) and LF (Unix/Git).
Solution
Add a .gitattributes file so that git will normalize files as they are checked in, while still allowing developers to use their native line endings locally.
Issue #4238 suggests an additional cleanup task to fix existing files that were already checked in as CRLF. I am happy to open that task as a PR as well (just let me know), but I thought that the core maintainers might prefer to do so since it will be a scary diff (every line changed in 30 files).
Context
Currently around 5% of the source files are stored as CRLF (Windows), and the other 95% are LF (Unix) (see full report in #4238).
This causes issues for developers on both platforms:
For example,
mat4.js
andvec2.js
use different line endings - should a developer change them to be consistent, or leave them as they are? What format should they use for a new file?By using
.gitattributes
to normalize line endings at checkin/checkout, no-one will have to think about line endings ever again 🥳I confirm I have read the contributing guidelines and signed the Contributor License Agreement.