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

Closed
ckknight opened this Issue Jun 4, 2011 · 11 comments

Projects

None yet

9 participants

@ckknight
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.

e.g.

if (blargh) {
    var stuff;

    doOtherStuff();
}

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
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.search(/\s+$/);
-            if (option.trailing && ~tw)
+            if (option.trailing && ~tw && !~s.search(/^\s+$/))
                 warningAt("Trailing whitespace.", line, tw);

             return true;
@valueof
Member
valueof commented Jun 11, 2011

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

@valueof valueof closed this Jun 11, 2011
@jussi-kalliokoski

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

@medikoo
medikoo commented Feb 12, 2013

+1

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.

@nikmartin

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

@doberkofler

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
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
domenic commented Jan 29, 2014

Yes, how do we get rid of this change?

@rwaldron
Member

Yes, how do we get rid of this change?

+1

@valueof
Member
valueof commented Jan 29, 2014

Send a patch for the 2.x branch?

@rwaldron
Member

Awesome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment