Skip to content

Commit 88c019d

Browse files
committed
Extend CLI documentation
1 parent 5c10518 commit 88c019d

File tree

2 files changed

+121
-14
lines changed

2 files changed

+121
-14
lines changed

pages/cli.md

Lines changed: 117 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,123 @@
11
{ "title": "JSHint CLI flags", "url": "/docs/cli", "template": "docs" }
22

3-
# CLI flags
3+
# Command-line Interface
44

5-
The JSHint CLI program accepts the following flags:
5+
The JSHint CLI can be installed via npm (see [the Installation page](/install)
6+
for instructions).
7+
8+
Contents: [Specifying Input](#specifying-input) · [Specifying Linting
9+
Options](#specifying-linting-options) · [Special Options](#special-options) ·
10+
[Ignoring Files](#ignoring-files) · [Flags](#flags)
11+
12+
<a name="specifying-input"></a>
13+
14+
### Specifying Input
15+
16+
The `jshint` executable accepts paths to files, which it will read and lint:
17+
18+
$ jshint myfile.js
19+
myfile.js: line 10, col 39, Octal literals are not allowed in strict mode.
20+
21+
1 error
22+
23+
If a file path is a dash (`-`) then JSHint will read from standard input.
24+
25+
<a name="specifying-linting-options"></a>
26+
27+
### Specifying Linting Options
28+
29+
The `jshint` executable is capable of applying [linting options](/docs/options)
30+
specified in an external [JSON](http://json.org/)-formatted file. Such a file
31+
might look like this:
32+
33+
{
34+
"curly": true,
35+
"eqeqeq": true,
36+
"nocomma": true
37+
}
38+
39+
`jshint` will look for this configuration in a number of locations, stopping at
40+
the first positive match:
41+
42+
1. The location specified with the `--config` [flag](#flags)
43+
2. A file named `package.json` located in the current directory or any parent
44+
of the current directory (the configuration should be declared as the
45+
`jshintConfig` attribute of that file's JSON value)
46+
3. A file named `.jshintrc` located in the current directory or any parent of
47+
the current directory
48+
4. A file named `.jshintrc` located in the current user's "home" directory
49+
(where defined)
50+
51+
If this search yields no results, `jshint` will lint the input code as if no
52+
linting rules had been enabled.
53+
54+
The command-line interface offers some [special options](#special-options) in
55+
addition to [the ones available in other contexts](/docs/options)
56+
57+
<a name="special-options"></a>
58+
59+
### Special Options
60+
61+
The following options concern the file system and are only available from
62+
within configuration files (i.e. not from inline directives or the API):
63+
64+
#### `extends`
65+
66+
Use another configuration file as a "base". The value of this option should be
67+
a file path to another configuration file, and the path should be relative to
68+
the current file.
69+
70+
For example, you might define a `.jshintrc` file in the top-level directory of
71+
your project (say, `./.jshintrc') to specify the [linting
72+
options](/docs/options) you would like to use in your entire project:
73+
74+
{
75+
"undef": true,
76+
"unused": true
77+
}
78+
79+
You may want to re-use this configuration for your project's automated tests,
80+
but also [allow for global
81+
variables](http://localhost:4000/docs/options#globals) that are specific to the
82+
test environment. In this case, you could create a a new file in their test
83+
directory, (`./test/.jshintrc` for example), and include the following
84+
configuration:
85+
86+
{
87+
"extends": "../.jshintrc",
88+
"globals": {
89+
"test": false,
90+
"assert": false
91+
}
92+
}
93+
94+
#### `overrides`
95+
96+
Specify options that should only be applied to files matching a given path
97+
pattern.
98+
99+
The following configuration file [disallows variable
100+
shadowing](/docs/options#shadow) for *all* files and [allows expressions as
101+
statements](/docs/options#expr) for only those files ending in `-test.js`:
102+
103+
{
104+
"shadow": false,
105+
"overrides": {
106+
"lib/*-test.js": {
107+
"expr": true
108+
}
109+
}
110+
}
111+
112+
<a name="ignoring-files"></a>
113+
114+
### Ignoring Files
115+
116+
TODO
117+
118+
<a name="flags"></a>
119+
120+
### Flags
6121

7122
#### `--config`
8123

pages/docs.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ JSHint is a program that flags suspicious usage in programs written in JavaScrip
66
The core project consists of a library itself as well as a CLI program distributed
77
as a Node module.
88

9-
More docs: [List of all JSHint options](/docs/options/) · [CLI flags](/docs/cli/) ·
10-
[Writing your own reporter](/docs/reporters/) · [FAQ](/docs/faq/)
9+
More docs: [List of all JSHint options](/docs/options/) · [Command-line
10+
Interface](/docs/cli/) · [Writing your own reporter](/docs/reporters/) ·
11+
[FAQ](/docs/faq/)
1112

1213
### Basic usage
1314

@@ -18,16 +19,7 @@ working directory):
1819

1920
$ npm install jshint -g
2021

21-
After you've done that you should be able to use the `jshint` program. The
22-
simplest use case would be linting a single file or all JavaScript files in
23-
a directory:
24-
25-
$ jshint myfile.js
26-
myfile.js: line 10, col 39, Octal literals are not allowed in strict mode.
27-
28-
1 error
29-
30-
If a file path is a dash (`-`) then JSHint will read from standard input.
22+
After you've done that you should be able to use the `jshint` program.
3123

3224
### Configuration
3325

0 commit comments

Comments
 (0)