source-academy / modules

Modules that can be imported by programs in Source Academy, an online experiential environment for computational thinking
Apache License 2.0
8 stars 28 forks source link

Resolve line ending issues #273

Closed sayomaki closed 8 months ago

sayomaki commented 8 months ago

Description

Due to the changes in #244, this has caused a slightly annoying regression for Unix-based users (Linux, MacOS) especially when checking out the code and switching branches. There will always be ghost changes present for certain files (due to the line breaks differences, LF on Linux/MacOS and CRLF on Windows), leading to issues when trying to switch branches (that there are unstaged changes), stash not seeming to work (as the changes automatically appear back), and issues in reverting as mentioned in the Telegram group.

The cause of the issue appears to be forcing incompatible line endings, and git will try to "resolve" the issues but proves to be counter-intuitive due to the issues aforementioned.

As such, it will be better to let git handle the normalisation of the line endings, to apply the default line ending configuration for text files (which is LF) by specifying that in .gitattributes. This will ensure all code checked in to the repository be formatting uniformly with the same line breaks (i.e. LF).

Reasons for choosing this strategy instead of other solutions

Type of change

The first commit restores the .gitattributes back to auto detection mode without enforcing a specific line ending (and will default to LF), whereas the second commit revert all the files that have been commited to the repo since the merger of #244 to their LF line endings.

Merging this PR will close #209 as well.

Checking Line Endings as a Github Action Task

After some consideration on how the behavior of .gitattributes, it appears that setting this default value project-wide should be able to ensure uniformity of line endings across the repo, even for new users/contributors without explicitly setting up their git configuration to deal with line endings. (ensures that all code pushed to remote will be LF)

There is also additional compute time required to run the linting (via eslint) to check the line breaks, and that if there is any line break issues in a handful number of files, this can easily lead to a memory overflow in the node runtime as eslint only prints out the errors after all the files have been parsed, which could possibly obfuscate the issue (of line breaks) behind memory errors and failing tests.

As such, I have decided against including a check in the Github Actions runner for new pull requests.

Related Issues/PRs & References

Some reference articles used to evaluate the best solution moving forward, and they're definitely worth a good read/look.