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

ckknight opened this Issue Jun 4, 2011 · 11 comments


None yet

9 participants

ckknight commented Jun 4, 2011

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?

ckknight commented Jun 4, 2011

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;
valueof commented Jun 11, 2011

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

@valueof valueof closed this Jun 11, 2011

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

medikoo commented Feb 12, 2013


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.

englercj commented Jan 4, 2014

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?

domenic commented Jan 29, 2014

Yes, how do we get rid of this change?


Yes, how do we get rid of this change?


valueof commented Jan 29, 2014

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