|
1 | 1 | { "title": "JSHint CLI flags", "url": "/docs/cli", "template": "docs" }
|
2 | 2 |
|
3 |
| -# CLI flags |
| 3 | +# Command-line Interface |
4 | 4 |
|
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 |
6 | 121 |
|
7 | 122 | #### `--config`
|
8 | 123 |
|
|
0 commit comments