File tree Expand file tree Collapse file tree 1 file changed +60
-0
lines changed Expand file tree Collapse file tree 1 file changed +60
-0
lines changed Original file line number Diff line number Diff line change
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
You can’t perform that action at this time.
0 commit comments