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

Remove trailing whitespaces from codebase #12980

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

aminya
Copy link
Contributor

@aminya aminya commented Dec 6, 2020

I noticed that this codebase is polluted with a lot of trailing whitespace which is very annoying for those who use modern editors that automatically remove the spaces, and so I decided to fix this issue.

This PR removes those by running the following bash command:
https://github.com/aminya/emscripten/blob/remove-trailing-whitespace/trailing_whitespace_remover.sh

I have checked in the script in case you need to run it again later. You can ask the new contributors to run this script before making a PR.

@sbc100
Copy link
Collaborator

sbc100 commented Dec 6, 2020

I generally agree that trailing whitespace bad, it its good to remove it, so I am generally supportive of this.

However I think we want to avoid modifying sources that were not authored as part of emscripten. So can you start be reverting any changes in tests/third_party (and also I noticed tests/gl_book). Also please revert changes in system/libc/musl and other third party libraries under system.

Also please revert other things that are either tool outputs or copies of third party files:

cmake/Modules/FindOpenAL.cmake
docs/emscripten_powered_by_logo.svg
docs/paper.tex
media/powered_by_logo.svg
media/switch_logo.svg
site/source/_themes/...

There may be more but lets start with that.... that should make the change a little easier to review too.

As an aside, my advice for those who dislike trailing whitespace (as I do) is not to configure your editor automatically remove all whitespace when you save. This can be quite annoying when you are editing files from an external project that you do not control. You don't want to unwittingly remove whitespace generating unexpected diffs.

Instead I find it much more effective to map a key to remove trailing whitespace when you choose to. For example I map <leader>-w in vim using nnoremap <leader>w :%s/\s\+$//<cr>:let @/=''<cr>. That way I can choose when I want to trim a given file and I won't be constantly having to worry about extra whitespace changes when working on random project out there. For the same reason I prefer to run clang-format manually rather than automatically on save.

@aminya
Copy link
Contributor Author

aminya commented Dec 6, 2020

I have updated the command. The paths you requested are now excluded.

There may be more but lets start with that.... that should make the change a little easier to review too.

For reviewing it may be easier if you run the above command yourself. I don't mind if you don't merge this PR in its current form.

@aminya aminya force-pushed the remove-trailing-whitespace branch 2 times, most recently from ff38095 to 6c517ee Compare December 6, 2020 17:42
Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

Looking much smaller.. just a few more to revert.

sbc100 added a commit that referenced this pull request Dec 6, 2020
sbc100 added a commit that referenced this pull request Dec 6, 2020
sbc100 added a commit that referenced this pull request Dec 6, 2020
@aminya
Copy link
Contributor Author

aminya commented Dec 6, 2020

I will wait for #12982 before updating this.

sbc100 added a commit that referenced this pull request Dec 6, 2020
sbc100 added a commit that referenced this pull request Dec 6, 2020
sbc100 added a commit that referenced this pull request Dec 7, 2020
@aminya aminya force-pushed the remove-trailing-whitespace branch 2 times, most recently from faa7f12 to ebc699c Compare December 8, 2020 08:21
@aminya
Copy link
Contributor Author

aminya commented Dec 8, 2020

I updated the command and ran it again.

I have checked in the script in case you need to run it again later. You can ask the new contributors to run this script before making a PR.

https://github.com/aminya/emscripten/blob/remove-trailing-whitespace/trailing_whitespace_remover.sh

Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

A few more exclusions for you...

I'm not sure we need special scripts checked in to f

@aminya aminya force-pushed the remove-trailing-whitespace branch from ebc699c to 98fab11 Compare December 8, 2020 21:33
@aminya
Copy link
Contributor Author

aminya commented Dec 8, 2020

I'm not sure we need special scripts checked in

I would definitely keep the script. In the future, new contributors should run it to make sure that no trailing whitespace creeps in. It is also needed for the other open PRs. They may contain some whitespace.

@aminya aminya force-pushed the remove-trailing-whitespace branch from cfc730c to 2e9a520 Compare December 9, 2020 14:45
Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

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

Please split out .gitattributes change and the addition of trailing_whitespace_remover.sh into separate PRs. I would rather discuses both of those separately, in isolation from the bulk of this change which is that actual whitespace removal.

I think we are almost there on the exclusions now!

@aminya aminya force-pushed the remove-trailing-whitespace branch 2 times, most recently from cd072a1 to 81313c1 Compare January 18, 2021 10:26
# line endings
* text=auto eol=lf
*.{cmd,[cC][mM][dD]} text eol=crlf
*.{bat,[bB][aA][tT]} text eol=crlf
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't have any files with mixed case extensions like this. I think just adding cmd and bat to the list below should be fine.

* text=auto eol=lf
*.{cmd,[cC][mM][dD]} text eol=crlf
*.{bat,[bB][aA][tT]} text eol=crlf
*.{vcxproj,vcxproj.filters} text eol=crlf
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing a newline at EOF.

@@ -0,0 +1,31 @@
git grep -I --name-only -z -e '' -- . \
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you put this in tools directory? And give it a #! line.

@@ -11,3 +11,9 @@ system/ linguist-vendored

AUTHORS merge=union
ChangeLog.md merge=union

# line endings
* text=auto eol=lf
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just to be clear, this means that for almost all files, developers will see unix line endings, even on windows? Why is that desirable?

Copy link
Contributor Author

@aminya aminya Jan 19, 2021

Choose a reason for hiding this comment

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

Any executable file that is supposed to run on Linux must be LF, and any executable that wants to run on Windows must be CRLF.
If someone clones this repository on Windows and then opens it in WSL, the line-endings will break because they become CRLF by default if no option is specified.

So, to fix these issues, one convention should be chosen. The easiest one is to specify CRLF for Windows executables and make everything else LF.

My addition is based on this:
https://rehansaeed.com/gitattributes-best-practices/

I can change the code to be less forceful for consistent line-ending. However, this only covers .sh files. It is usually common to use hash bangs for executables and not the file extension, and so those files will become faulty if they are accessed from another operating system.

# Set default behaviour to automatically normalize line endings.
* text=auto

# Force batch scripts to always use CRLF line endings so that if a repo is accessed
# in Windows via a file share from Linux, the scripts will work.
*.{cmd,[cC][mM][dD]} text eol=crlf
*.{bat,[bB][aA][tT]} text eol=crlf

# Force bash scripts to always use LF line endings so that if a repo is accessed
# in Unix via a file share from Windows, the scripts will work.
*.sh text eol=lf

Copy link
Collaborator

Choose a reason for hiding this comment

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

If this is just to support WSL users who are using a kind of hybrid environment I'm not sure it worth it. I would have though that WSL users already have to savy enough to setup global settings.

In any case, can we split out this PR so we can discuss the .gitattributes separately. It seems like its worth further discussion and I don't want to block to this PR.

@aminya aminya force-pushed the remove-trailing-whitespace branch from 81313c1 to 7931b71 Compare January 19, 2021 11:34
Base automatically changed from master to main March 8, 2021 23:49
@stale
Copy link

stale bot commented Apr 16, 2022

This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 30 days. Feel free to re-open at any time if this issue is still relevant.

@stale stale bot added the wontfix label Apr 16, 2022
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.

2 participants