Skip to content

Clean up whitespace related issues in entire project #126

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

Merged
merged 8 commits into from
Jun 11, 2018
Merged

Conversation

Butt4cak3
Copy link
Contributor

@Butt4cak3 Butt4cak3 commented Jun 9, 2018

When merged, this pull request will clean up all text files. It removes trailing whitespace, converts line endings to LF, adds a .gitattribute file and improves the existing .editorconfig file.

The reason to remove unneeded whitespace is to avoid confusing diffs and merge conflicts. Many modern and popular text editors remove trailing whitespace automatically. If 2 or more contributors submit PRs that edit the same file (e. g. 2 code examples for one chapter, both editing the .md), their editors could both automatically trim the whitespace, resulting in merge conflicts down the line.

During the cleanup process, I noticed that all C# source files have been commited with CRLF (Windows) line endings, rather than LF like all other files in the repository. The files also have a UTF-8 Byte Order Mark (BOM), which is generally discouraged. According to The Unicode Standard - 2.6 Encoding Schemes:

Use of a BOM is neither required nor recommended for UTF-8, but may
be encountered in contexts where UTF-8 data is converted from other encoding forms that
use a BOM or where the BOM is used as a UTF-8 signature.

Therefore, I converted the files to have LF line endings for consistency and removed their BOMs. I also added a .gitignore file with a rule that should force .cs files to always have LF line endings in the repository.

Lastly, I edited the existing .editorconfig file to account for more file types.

Butt4cak3 added 4 commits June 9, 2018 12:02
Removed trailing whitespace, changed line endings from CRLF to LF and
removed the UTF-8 BOM
C# source files are now forced to have LF line endings
.gitattributes Outdated
@@ -0,0 +1,2 @@
# Force C# source files to have LF line endings
*.cs text eol=lf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just force all text files to have LF line endings

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you go about this? We can't use * afaik because we have some binary files (mostly images) here and there. Can you use *.{txt,md,c,cpp,cs,...} in .gitattributes? I couldn't find documentation on whether this syntax is valid or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tried. You can't use that syntax. I hope there is another way to specify a rule for more than one file type, because I'd rather have a whitelist for text files than a blacklist for binary files.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* text=auto eol=lf

Butt4cak3 added 2 commits June 9, 2018 20:20
And also added them to .gitattributes and .editorconfig
@Butt4cak3
Copy link
Contributor Author

Alright. So apparently there is no reason to group rules in .gitattributes, so I went ahead and created one rule for every file type present in .editorconfig. I also changed an OCAML file to LF and added the file extension to both configurations.

@june128 june128 added Implementation Edit This provides an edit to an algorithm implementation. (Code and maybe md files are edited.) Chapter Edit This changes the archive's chapters. (md files are edited.) labels Jun 9, 2018
@leios
Copy link
Member

leios commented Jun 10, 2018

This is obviously a needed change. Should I leave it up for more discussion or merge it soon?

@leios leios merged commit 2e7f37d into master Jun 11, 2018
@june128 june128 added General and removed Implementation Edit This provides an edit to an algorithm implementation. (Code and maybe md files are edited.) Chapter Edit This changes the archive's chapters. (md files are edited.) labels Jun 11, 2018
@Butt4cak3 Butt4cak3 deleted the whitespace branch June 28, 2018 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants