grunt-jsbint

Validate files with JSBint.

grunt-jsbint

Validate files with jsbint.

Getting Started

This plugin requires Grunt ~0.4.0

If you haven't used Gruntbefore, be sure to check out the Getting Startedguide, as it explains how to create a Gruntfileas well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-jsbint --save-dev

One the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-jsbint');

Jsbint task

Run this task with the grunt jsbintcommand.

Task targets, files and options may be specified according to the grunt Configuring tasksguide.

Options

Any specified option will be passed through directly to jsbint, thus you can specify any option that jsbint supports. See the jsbint documentationfor a list of supported options.

A few additional options are supported:

globals

Type: ObjectDefault 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 jsbint option, but is passed into the jsbintfunction as its third argument. See the jsbint documentationfor more information.

jshintrc

Type: StringDefault value: null

If this filename is specified, options and globals defined therein will be used. The jshintrcfile must be valid JSON and looks something like this:

{
  "curly": true,
  "eqnull": true,
  "eqeqeq": true,
  "undef": true,
  "globals": {
    "jQuery": true
  }
}

Usage examples

Wildcards

In this example, running grunt jsbint:all(or grunt jsbintbecause jsbintis a [multi task][]) will lint the project's Gruntfile as well as all JavaScript files in the liband testdirectories and their subdirectores, using the default jsbint options.

// Project configuration.
grunt.initConfig({
  jsbint: {
    all: ['Gruntfile.js', 'lib/**/*.js', 'test/**/*.js']
  }
});

Linting before and after concatenating

In this example, running grunt jsbintwill lint both the "beforeconcat" set and "afterconcat" sets of files. This is not ideal, because dist/output.jsmay get linted before it gets created via the grunt-contrib-concat pluginconcattask.

In this case, you should lint the "beforeconcat" files first, then concat, then lint the "afterconcat" files, by running grunt jsbint:beforeconcat concat jsbint:afterconcat.

// Project configuration.
grunt.initConfig({
  concat: {
    dist: {
      src: ['src/foo.js', 'src/bar.js'],
      dest: 'dist/output.js'
    }
  },
  jsbint: {
    beforeconcat: ['src/foo.js', 'src/bar.js'],
    afterconcat: ['dist/output.js']
  }
});

Specifying jsbint options and globals

In this example, custom jsbint options are specified. Note that when grunt jsbint:uses_defaultsis run, those files are linted using the default options, but when grunt jsbint:with_overridesis run, those files are linted using mergedtask/target options.

// Project configuration.
grunt.initConfig({
  jsbint: {
    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']
      },
    }
  },
});

HomePage

https://github.com/gmuteam/jsbint

Repository

https://github.com/gmuteam/jsbint


上一篇:jsbint
下一篇:grunt-size

相关推荐

官方社区

扫码加入 JavaScript 社区