Skip to content
This repository

Add tab option to set tabwidth without turning on indent error checking. #1198

Closed
wants to merge 1 commit into from

4 participants

Jeremy Whiting Wolfgang Kluge Fabrício Matté Anton Kovalyov
Jeremy Whiting

This commit fixes issue #1196

Wolfgang Kluge

What's the purpose of this option?
Please provide an example.

Jeremy Whiting
Wolfgang Kluge

And why do we need an option for it?
Shouldn't tabs always be counted as 1 character (for error reports)?

I may miss the point, but I think this is a greater issue. jshint just can't count tabs easily because they are replaced with n space characters while lexing a source line (inherited from jslint).

Please provide test cases with your pull requests.

Fabrício Matté

Shouldn't tabs always be counted as 1 character (for error reports)?

@WolfgangKluge I believe they should. But in fact, they are counted as 4 characters if "indent": false. Try:

\t1

Replace \t with a literal tab and JSHint will report a missing semicolon at character 6 when it should be character 3 (after the "1").

Now if we set "indent": 1 option, it correctly reports the missing semi-colon at character 3. However, this also outputs an indentation error.

I'm making a Sublime Text plugin and this is a performance killer. It is possible to use "indent": 1 with a custom reporter to filter out indent errors, but obviously, this will output an warning for EVERY indented line - a terrible unnecessarily overhead generated which I have to workaround with even more overhead (having to iterate over the errors array to filter out the indentation errors).

edit: Another workaround, use "indent": 1 and temporarily add //jshint -W015\n at the top of the file before running it through JSHint. Obviously all errors/warnings' line reports will be offset'ed by +1 in comparison to the original file in this case. This will suffice for my use-case for the time being, but obviously this completely disables indentation warnings so it is not a solution for every use case.

Anton Kovalyov
Owner

This will be irrelevant soon since we're moving from style checking. indent won't generate style warnings.

Fabrício Matté

@antonkovalyov Is the indent option being removed then, since it will no longer produce warnings? Or will it still have any use?

Anton Kovalyov
Owner

@UltCombo indent will be used to set indentation level for correct character locations and such.

jugglinmike jugglinmike referenced this pull request in fb55/domhandler
Closed

Introduce JSHint #5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 2 changed files with 3 additions and 1 deletion. Show diff stats Hide diff stats

  1. +2 0  src/stable/jshint.js
  2. +1 1  src/stable/lex.js
2  src/stable/jshint.js
@@ -159,6 +159,7 @@ var JSHINT = (function () {
159 159 valOptions = {
160 160 maxlen : false,
161 161 indent : false,
  162 + tab : false,
162 163 maxerr : false,
163 164 predef : false,
164 165 quotmark : false, //'single'|'double'|true
@@ -4399,6 +4400,7 @@ var JSHINT = (function () {
4399 4400 state.option = newOptionObj;
4400 4401 state.ignored = newIgnoredObj;
4401 4402
  4403 + state.option.tab = state.option.tab || 4;
4402 4404 state.option.indent = state.option.indent || 4;
4403 4405 state.option.maxerr = state.option.maxerr || 50;
4404 4406
2  src/stable/lex.js
@@ -227,7 +227,7 @@ function Lexer(source) {
227 227 this.from = 1;
228 228 this.input = "";
229 229
230   - for (var i = 0; i < state.option.indent; i += 1) {
  230 + for (var i = 0; i < state.option.tab; i += 1) {
231 231 state.tab += " ";
232 232 }
233 233 }

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.