Dealing With Trailing Whitespace

More than having trailing whitespace I hate to lose control of my code changes

With that said I’d like to share recommendations about dealing with trailing whitespace(TW).

Don’t auto-remove!

NOT at the global scope :)

While it’s really best practice to remove trailing whitespace before saving a file within your IDE, I’d not recommended doing so at least for the following reasons:

  • you will be encountering hard times contributing to the projects which not following such practice, there a lot…
  • two trailing spaces in markdown is a line break.

Follow the policy and keep the code clean

While trailing whitespace auto-removal is a matter of project policy (e.g. see the following stackoverflow question) you can keep your change sets clean with the tools like trailing-whitespace vim plugin, I’m sure there must be analog for your choice IDE.

But if you lucky working on the project which policy to not accept trailing whitespace, you can easily setup your IDE or SCM to auto-remove trailing whitespace just for this particular project.