This commit is contained in:
namniak
2014-06-27 00:31:51 -04:00
parent e9951d2934
commit 6ddb18a127
1442 changed files with 274017 additions and 0 deletions
+103
View File
@@ -0,0 +1,103 @@
# Usage examples
## Wildcards
In this example, running `grunt jshint:all` (or `grunt jshint` because `jshint` is a [multi task](http://gruntjs.com/configuring-tasks#task-configuration-and-targets)) will lint the project's Gruntfile as well as all JavaScript files in the `lib` and `test` directories and their subdirectores, using the default JSHint options.
```js
// Project configuration.
grunt.initConfig({
jshint: {
all: ['Gruntfile.js', 'lib/**/*.js', 'test/**/*.js']
}
});
```
## Linting before and after concatenating
In this example, running `grunt jshint` will lint both the "beforeconcat" set and "afterconcat" sets of files. This is not ideal, because `dist/output.js` may get linted before it gets created via the [grunt-contrib-concat plugin](https://github.com/gruntjs/grunt-contrib-concat) `concat` task.
In this case, you should lint the "beforeconcat" files first, then concat, then lint the "afterconcat" files, by running `grunt jshint:beforeconcat concat jshint:afterconcat`.
```js
// Project configuration.
grunt.initConfig({
concat: {
dist: {
src: ['src/foo.js', 'src/bar.js'],
dest: 'dist/output.js'
}
},
jshint: {
beforeconcat: ['src/foo.js', 'src/bar.js'],
afterconcat: ['dist/output.js']
}
});
```
## Specifying JSHint options and globals
In this example, custom JSHint options are specified. Note that when `grunt jshint:uses_defaults` is run, those files are linted using the default options, but when `grunt jshint:with_overrides` is run, those files are linted using _merged_ task/target options.
```js
// Project configuration.
grunt.initConfig({
jshint: {
options: {
curly: true,
eqeqeq: true,
eqnull: true,
browser: true,
globals: {
jQuery: true
},
},
uses_defaults: ['dir1/**/*.js', 'dir2/**/*.js'],
with_overrides: {
options: {
curly: false,
undef: true,
},
files: {
src: ['dir3/**/*.js', 'dir4/**/*.js']
},
}
},
});
```
## Ignoring specific warnings
If you would like to ignore a specific warning:
```shell
[L24:C9] W015: Expected '}' to have an indentation at 11 instead at 9.
```
You can toggle it by prepending `-` to the warning id as an option:
```js
grunt.initConfig({
jshint: {
ignore_warning: {
options: {
'-W015': true,
},
src: ['**/*.js'],
},
},
});
```
## Ignoring specific files
Occasionally application files and third party libraries share the same directory. To exclude third party code, but include all current and future application files, use a glob for `files` and specifically exclude libraries using `ignores`. In this example, the jQuery file is matched by the glob but subsequently ignored when JSHint does its analysis.
```js
grunt.initConfig({
jshint: {
files: ['js/*.js'],
options: {
ignores: ['js/jquery.js']
}
}
});
```
+66
View File
@@ -0,0 +1,66 @@
# Options
Any specified option will be passed through directly to [JSHint][], thus you can specify any option that JSHint supports. See the [JSHint documentation][] for a list of supported options.
[JSHint]: http://www.jshint.com/
[JSHint documentation]: http://www.jshint.com/docs/
A few additional options are supported:
## globals
Type: `Object`
Default value: `null`
A map of global variables, with keys as names and a boolean value to determine if they are assignable. This is not a standard JSHint option, but is passed into the `JSHINT` function as its third argument. See the [JSHint documentation][] for more information.
## jshintrc
Type: `String`
Default value: `null`
If this filename is specified, options and globals defined therein will be used. The `jshintrc` file must be valid JSON and looks something like this:
```json
{
"curly": true,
"eqnull": true,
"eqeqeq": true,
"undef": true,
"globals": {
"jQuery": true
}
}
```
*Be aware that `jshintrc` settings are not merged with your Grunt options.*
## extensions
Type: `String`
Default value: `''`
A list of non-dot-js extensions to check.
## ignores
Type: `Array`
Default value: `null`
A list of files and dirs to ignore. This will override your `.jshintignore` file if set and does not merge.
## force
Type: `Boolean`
Default value: `false`
Set `force` to `true` to report JSHint errors but not fail the task.
## reporter
Type: `String`
Default value: `null`
Allows you to modify this plugins output. By default it will use a built-in Grunt reporter. Set the path to your own custom reporter or to one of the built-in JSHint reporters: `jslint` or `checkstyle`.
See also: [Writing your own JSHint reporter.](http://jshint.com/docs/reporters/)
## reporterOutput
Type: `String`
Default value: `null`
Specify a filepath to output the results of a reporter. If `reporterOutput` is specified then all output will be written to the given filepath instead of printed to stdout.
+3
View File
@@ -0,0 +1,3 @@
Task targets, files and options may be specified according to the grunt [Configuring tasks](http://gruntjs.com/configuring-tasks) guide.
For more explanations of the lint errors JSHint will throw at you please visit [jslinterrors.com](http://jslinterrors.com/).