34

I find that JSLint produces lots of warnings of the form:

Expected 'foo' to have an indentation at X instead at Y.

The JSLint options documentation describes an indent option that recognizes a numerical value representing the amount of space for each level of indentation. This option allows me to say things like use 2 spaces per level of indentation. I just write something like this at the top of my JavaScript file:

/*jslint indent: 2 */

OK, great. Now JSLint knows how much to indent for each level of indentation, but JSLint seems to be hardcoded to decide what level of indentation each line should have.

Suppose I want to indent my code differently than the way JSLint prescribes. Can I do this with some JSLint option? If not, can I at least turn off the indentation warnings? I tried:

/*jslint indent: false */

but that did not cause indentation warnings to be elided; it caused a JSLint error.

Greg Mattes
  • 33,090
  • 15
  • 73
  • 105

2 Answers2

51

What a difference that morning coffee makes:

/*jslint white: true */
Dmitry Evseev
  • 11,533
  • 3
  • 34
  • 48
Greg Mattes
  • 33,090
  • 15
  • 73
  • 105
  • 2
    Of course, this still doesn't addressthe issue of specifying another formatting style. – Greg Mattes Nov 01 '09 at 18:52
  • 9
    This only worked for me when I had /* jslint white: true */ which is odd. – synthesizerpatel Nov 23 '13 at 09:57
  • I am trying to configure this in Sublime 2? Do you always have to add this on top of your JS files - or it can be globally set for JSLint plugin in Sublime? – azec-pdx Jan 13 '14 at 20:51
  • 2
    This says it needs to be set to true: http://jslinterrors.com/expected-exactly-one-space-between-a-and-b – Will Jun 24 '14 at 02:30
  • 3
    @synthesizepatel (Your comment is three years old now, but just for the records:) `/* jslint white: true */` won't work because jslint requires to be no space between the opening block comment (`/*`) and the keyword `jslint`. Basically: `/* jslint` is wrong, `/*jslint` is right. – mauroc8 Jan 07 '17 at 06:52
-3

If you don't want to disable JSLint, you can remove the double indentations (e.g. when defining multiple var's in a javascript file) by adjusting this setting:

Options > Editor > Formatting > Language: Javascript > Continuation Indentation - set to 4.

Now you can use ctrl shift f to format code, and JSLint doesn't freak out...

Nathan Todd
  • 73
  • 1
  • 5