Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Add option to allow for "trailing" whitespace on an empty line #182

ckknight opened this Issue · 11 comments

9 participants


The option for checking trailing whitespace is nice, but in cases where the line is completely blank except for whitespace, this is slightly unnerving, since I tend to line up the whitespace with the rest of the block.


if (blargh) {
    var stuff;


The blank line is indented with the rest of the block, but JSHint now sees this as an error. Is there a way to turn this specific case into a non-error while keeping general trailing whitespace checks?


Here is a solution:

diff --git a/jshint.js b/jshint.js
index dbba31b..d2dfde3 100644
--- a/jshint.js
+++ b/jshint.js
@@ -875,7 +875,7 @@ var JSHINT = (function () {

             // Check for trailing whitespaces
             tw =\s+$/);
-            if (option.trailing && ~tw)
+            if (option.trailing && ~tw && !^\s+$/))
                 warningAt("Trailing whitespace.", line, tw);

             return true;

I've applied that (with tests) in 801c0e8.

@valueof valueof closed this

Is there a way to disable this change? I personally find "empty" lines with whitespace in them annoying.



Indeed, that demands rather patch for an editor than jshint. It probably should never land, and if such decision was made, it should definitely be an option that is off by default.


I also do not like whitespace on blank lines. By definition, option "white" as documented should do this if it follows crockford's rules, because jslint complains about whitespace on blank lines


I agree and don't like empty lines with whitespaces in it. Generally I don't see why moving away from crockford's rules if there isn't a very compelling reason to do so.


I want to consider a blank line with only whitespace as "trailing whitespace" and ensure that it is reported as an error. Now that there is this change, is there a setting that I can turn on to ensure that whitespace-only lines are reported as an error?


Yes, how do we get rid of this change?


Yes, how do we get rid of this change?



Send a patch for the 2.x branch?



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.