43

JSHint and JSLint are awesome tools.

However, the "mixed spaces and tabs" warning dominates the report. Is there a way to suppress these warnings, or is there a similar service that allows white space warnings to get suppressed?

Matt Ball
  • 354,903
  • 100
  • 647
  • 710
Crashalot
  • 33,605
  • 61
  • 269
  • 439
  • i solved it ultimately by writing a simple JS script to adjust white space in the code before pasting it into jshint. – Crashalot Nov 25 '12 at 23:55
  • There is a trick, remove all the white space(\t,\n,\0, spaces). rebuild it. It should work. – M2012 Jun 29 '15 at 10:23

3 Answers3

59

It's not possible to switch off this warning with a flag, and the JSHint maintainer doesn't want to add a flag for this.

However, it is possible to turn off warnings according to their number. In this case, you'd write:

/* jshint -W099 */

If you're using a JSHint configuration file, you can specify this there too:

{
    "-W099": true, // allowed mixed tabs and spaces
}

Alternatively, there's a custom reporter available to switch off this warning.

Wilfred Hughes
  • 29,846
  • 15
  • 139
  • 192
44
/*jshint smarttabs:true */

See smarttabs, under "Relaxing Options." http://www.jshint.com/docs/options/

This option suppresses warnings about mixed tabs and spaces when the latter are used for alignmnent only. The technique is called SmartTabs.

barnyr
  • 5,678
  • 21
  • 28
Matt Ball
  • 354,903
  • 100
  • 647
  • 710
  • 3
    you are way too awesome. but you and your 78.3K points already knew that. – Crashalot Apr 23 '12 at 18:48
  • Hmm, weird, we pasted this at the top of the script block, and it's still showing the warning ... is there something else we need to do? – Crashalot Apr 23 '12 at 18:51
  • Hm - I had an extra space between `/*` and `jshint`; that might be the cause. Edited. – Matt Ball Apr 23 '12 at 18:53
  • 1
    Nope, we just tried that, too (saw it from reading the docs). We're supposed to just put this line at the top of the code block right? Nothing else? – Crashalot Apr 23 '12 at 18:56
  • Yup. It depends on how you're actually using spaces. If the code's white space is simply sloppy, and _not_ just using spaces for aligment only, this option won't help you. – Matt Ball Apr 23 '12 at 18:58
  • Yes, **iff** there is an error. For example: http://www.jshint.com/reports/409010 – Matt Ball Apr 23 '12 at 19:08
  • I see smarttabs:true up top in this report... anyway, we'll try to work through this. Probably something stupid on our end. – Crashalot Apr 23 '12 at 19:10
  • Are there alternative services for JS validation since SmartTabs was not the solution? We still see the "mixed tabs and spaces" warning even with SmartTabs set to true. – Crashalot Apr 23 '12 at 19:36
  • 1
    I think JSLint's "Tolerate messy white space" option will work for you. You're going to get some much more opinionated warnings/errors from JSLint, however. – Matt Ball Apr 23 '12 at 20:10
  • 2
    i solved it ultimately by writing a simple JS script to adjust white space in the code before pasting it into jshint. thanks! – Crashalot Apr 26 '12 at 06:36
  • 6
    The `smarttabs` option has been removed from jshint: https://github.com/jshint/jshint/commit/4035fef1af4ef426e9dc99918ca3aac0ce44b784 – Rob W Jul 21 '14 at 12:07
5

Answer for 2014: upgrade jshint As @RobW mentioned earlier, jshint no longer complains about mixed spaces and tabs. I have tested this by upgrading to jshint@2.5.10 and re-linting my document, which no longer complains (I consistently indent using tabs, but commenting out lines in SublimeText triggered this warning).

sudo npm update -g jshint
mikemaccana
  • 110,530
  • 99
  • 389
  • 494