Skip to content

Commit 438f9ce

Browse files
author
James Allardice
committed
Added article on JSLint and JSHint indent option
1 parent c3b4ea8 commit 438f9ce

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

option-articles/indent.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<!---
2+
{
3+
"titles": [
4+
"indent"
5+
],
6+
"slugs": [
7+
"option-indent"
8+
],
9+
"linters": [
10+
"jslint",
11+
"jshint"
12+
],
13+
"author": "jallardice",
14+
"subject": "option"
15+
}
16+
-->
17+
18+
### What does this option do?
19+
20+
In JSLint and JSHint the `indent` option is used to enforce a specific tab width
21+
in your code. Both tools make their own assumptions about when indentation
22+
should occur but are largely identical in this regard. In the following example
23+
we specify an indentation width of 4 spaces. Both tools expect the body of an
24+
`if` statement to be indented so both will warn if the identation is not of the
25+
required width:
26+
27+
<!---
28+
{
29+
"linter": "jslint"
30+
}
31+
-->
32+
```javascript
33+
/*jslint indent: 4 */
34+
function doSomething(x) {
35+
"use strict";
36+
if (x) {
37+
return;
38+
}
39+
}
40+
```
41+
42+
### When should I use this option?
43+
44+
With JSLint you'll get an "Expected '{a}' at column {b}, not column {c}" error
45+
any time an incorrect indentation width is found. In JSHint you'll get an
46+
"Expected '{a}' to have an indentation at {b} instead at {c}" error under the
47+
same circumstances. By enabling the validation of indentation you can ensure it
48+
remains consistent throughout your code which will make it much easier to read.
49+
Common values for this option are `4` and `2` but the exact number depends on
50+
your personal preference and existing conventions.
51+
52+
Note that in JSHint this is an *enforcing* option which means JSHint does not
53+
apply it by default. If you do not explicitly set this option to an integer
54+
JSHint will not warn about indentation anywhere in your code.
55+
56+
#### Recommendation
57+
58+
- **JSLint** - Set this option to `2` or `4` to enable indentation validation
59+
60+
- **JSHint** - Set this option to `2` or `4` to enable indentation validation

0 commit comments

Comments
 (0)