Atom text editor remove trailing whitespace on save

SaveWhitespaceSublimetext3Removing WhitespaceAtom Editor

Save Problem Overview


I use Sublime text. Now I am trying Atom. When I save any file in sublime text it does not include any trailing blank line. But saving any file in Atom leaves a trailing blank line. How do I force Atom not to leave trailing white spaces?

Save Solutions


Solution 1 - Save

Under your Atom Preferences go to Packages tab and search for whitespace. Click on the whitespace package and uncheck Ensure Single Trailing Newline option

enter image description here

Solution 2 - Save

On global level this can be changed using settings in Whitespace package, but if you want to disable it for a specific language you have to use syntax-scoped properties in your config.cson.

'.text.html.php': # php overrides
  whitespace:
    ensureSingleTrailingNewline: false
    removeTrailingWhitespace: false
    
'.source.ruby': # ruby overrides
  whitespace:
    ensureSingleTrailingNewline: false
    removeTrailingWhitespace: false

To see the scope of language go to Packages tab and search for your language.

Click on the settings of the language package and you can see the scope:

Solution 3 - Save

Go to packages and find "whitespace", go to it's settings and uncheck the last checkbox.

Settings Settings screenshot

Checkbox Checkbox screenshot

Solution 4 - Save

To add to Dan Moldavan's answer.

I experienced this issue when working on a Rails Application.

I added a .editorconfig file with the following properties:

# editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

And I added a .gitattributes file with the following properties:

# Enforce Unix newlines
* text=auto eol=lf

And then my Atom Editor threw a problem:

> 1 problem affecting .gitattributes

> whitespace: It is possible that the "whitespace"-package prevents the following properties from working reliably: insert_final_newline, trim_trailing_whitespace. You may try reconfiguring or disabling the "whitespace"-package to solve regarding issues.

Here's how I fixed it:

  • Open your Atom Editor
  • Go to Edit > Preferences > Packages
  • Type in whitespace
  • Click on the package that shows up
  • Untick the following:
    • Ensure Single Trailing Newline
    • Ignore Whitespace On Current Line
  • Leave Ignore Whitespace Only Lines unticked

Screenshot of the fix

Save and close the settings.

That's all.

I hope this helps

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNasif Md. TanjimView Question on Stackoverflow
Solution 1 - SaveDan MoldovanView Answer on Stackoverflow
Solution 2 - SaveRajkaran MishraView Answer on Stackoverflow
Solution 3 - SavePattycake JrView Answer on Stackoverflow
Solution 4 - SavePromise PrestonView Answer on Stackoverflow