2

When I use SublimeLinter for Sublime Text 2 with javascript it shows the red exclamation icon whenever there is a trailing whitespace, which shouldn't be a problem with javascript.

I did a bit of research and found that I could add the code below to the package user settings (SublimeLinter.sublime-settings) per the error codes found here: https://github.com/jcrocholl/pep8/blob/master/pep8.py

{
  "pep8_ignore": [ "E200", "W200", "200" ]
}

But for some reason the error icons still show.

Breck L
  • 60
  • 4
  • Trailing whitespace is the number one enemy of development, why would you ignore such important warnings? You'd rather have `"trim_trailing_white_space_on_save": true` in your user settings. – Fabrício Matté Oct 31 '13 at 16:33
  • Thanks Fabricio, I guess I didn't realize whitespace in javascript would be an issue. Added that code to my user settings and solved my problem. To clarify I added `"trim_trailing_white_space_on_save": true` to my Sublime Text user settings, not SublimeLinter user settings. – Breck L Oct 31 '13 at 16:57
  • No problem, it is not that it will easily break your code, but at the long run you will notice why it is a good practice to keep trailing white space. I've posted an answer with both possible solutions (SublimeLinter config and auto-trim trailing whitespace), also expanding my reasoning about whitespace. – Fabrício Matté Oct 31 '13 at 17:05

1 Answers1

2

You're looking in the wrong place - PEP8 is for Python code checking. SublimeLinter by default uses JSHint to lint JavaScript files. In this case, you can use this SublimeLinter config to silence the JavaScript trailing whitespace warnings:

{
    "jshint_options": {
        "trailing": false
    }
}

See JSHint Options#trailing


But honestly, this is not the ideal way to go. Trailing whitespace is pure evil. Why, you may ask? Well a couple reasons off the top of my head:

Hence, I'd suggest trimming trailing whitespace automatically. In ST2, go to Preferences -> Settings - User and add this config:

{
    "trim_trailing_white_space_on_save": true
}

This way, the trailing whitespaces are automatically removed upon the first Ctrl/Cmd+S, and not just for JavaScript, but any language you code in.

Community
  • 1
  • 1
Fabrício Matté
  • 69,329
  • 26
  • 129
  • 166