Question

I like the idea behind JSLINT but sometimes it is a little too strict, in my opinion needlessly so.

Recently I found JSHINT. It's a little more flexible, allows more options to be turned on or off.

But JSHINT is throwing an error on code that I think looks right. For example, JSHINT barfs on its own code. If I run JSHINT on JSHINT.js, it gives me this:

enter image description here

I don't understand that. See the error message near the bottom of that image? JSHINT seems to want the indentation to be different than it is. It's not complaining about the lack of the curly. I have curly:false which says to not require curlies around one-liner if statements.

The odd thing is, JSHINT.js source code uses a 4-space indent everywhere, but it throws errors about the indent only for these few lines. Why?

Am I doing this wrong? Is there something else I should be configuring?


EDITED - originally I had been playing around with JSHINT, and I put the combine() call on the same line as the if statement. I've reverted the JSHINT code back to what it was originally, to show that the errors remain.

enter image description here

This is done with JSHINT using these options:

options = {
    curly      : false, // no curly fascism
    wsh        : true,  // WScript is allowed
    white      : true,  // true: 'sloppy' whitespace is ok
    plusplus   : false, // false == ok to use ++
    passfail   : false  // do not stop after first error
    //radix      : true   // do not puke on parseInt() with no radix
};

EDIT2

Here's a gif that shows what JSHINT, in its original form, really wants. When the red highlights disappear, it means JSHINT is happy for that particular line. (This is using flymake-for-jslint in emacs).

enter image description here

As you can see, if I indent the line in an odd way, JSHINT relaxes.

Answer

I think the answer is in this github issue. I modified JSHINT, line 2264, like this:

***************
*** 2256,2262 ****
--- 2261,2270 ----
                          nexttoken, '{', nexttoken.value);

              noreach = true;
+             // cheeso - fix for https://github.com/jshint/jshint/issues/87
+             indent += option.indent;
              a = [statement()];
+             indent = old_indent;
              noreach = false;
          }

...and it stopped complaining about its own formatting.

Was it helpful?

Solution 2

I think the answer is in [this github issue][4]. I modified JSHINT, line 2264, like this:

***************
*** 2256,2262 ****
--- 2261,2270 ----
                          nexttoken, '{', nexttoken.value);

              noreach = true;
+             // cheeso - fix for https://github.com/jshint/jshint/issues/87
+             indent += option.indent;
              a = [statement()];
+             indent = old_indent;
              noreach = false;
          }

...and it stopped complaining about its own formatting.

OTHER TIPS

JSHint maintainer here. Based on your screenshot, it errors because the combine is on the same line as your if clause which is against white option's rules.

Are you sure that your copy of JSHint was not modified by anybody? We have unit tests for JSHint and one of the tests checks JSHint's own source code with itself. And, as you can see from the attached example, everything passes just fine.

jshint passing jshint screenshot

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top