jshint loader for webpack
JavaScript
Switch branches/tags
Nothing to show
Clone or download
Permalink
Failed to load latest commit information.
.circleci refactor(defaults): update to latest webpack-defaults (#53) Apr 30, 2018
.github refactor(defaults): update to latest webpack-defaults (#53) Apr 30, 2018
example added example Jul 16, 2014
lib refactor(defaults): update to latest webpack-defaults (#53) Apr 30, 2018
test refactor(defaults): update to latest webpack-defaults (#53) Apr 30, 2018
.babelrc refactor(defaults): update to latest webpack-defaults (#53) Apr 30, 2018
.editorconfig refactor(defaults): update to latest webpack-defaults (#53) Apr 30, 2018
.eslintignore refactor(defaults): update to latest webpack-defaults (#53) Apr 30, 2018
.eslintrc.js refactor(defaults): update to latest webpack-defaults (#53) Apr 30, 2018
.gitattributes refactor(defaults): update to latest webpack-defaults (#53) Apr 30, 2018
.gitignore refactor(defaults): update to latest webpack-defaults (#53) Apr 30, 2018
.jshintrc Add some basic tests Aug 16, 2016
.prettierrc refactor(defaults): update to latest webpack-defaults (#53) Apr 30, 2018
CHANGELOG.md refactor(defaults): update to latest webpack-defaults (#53) Apr 30, 2018
LICENSE chore(license): update to JSF standard license (#33) Feb 21, 2017
README.md docs: fix sample config (#56) Aug 14, 2018
codecov.yml refactor(defaults): update to latest webpack-defaults (#53) Apr 30, 2018
commitlint.config.js refactor(defaults): update to latest webpack-defaults (#53) Apr 30, 2018
package-lock.json refactor(defaults): update to latest webpack-defaults (#53) Apr 30, 2018
package.json refactor(defaults): update to latest webpack-defaults (#53) Apr 30, 2018

README.md

npm node deps tests chat

jshint-loader

A JSHint loader module for webpack. Runs JSHint on JavaScript files in a bundle at build-time.

Requirements

This module requires a minimum of Node v6.9.0 and Webpack v4.0.0.

Getting Started

To begin, you'll need to install jshint-loader:

$ npm install jshint-loader --save-dev

Then add the loader to your webpack config. For example:

// webpack.config.js
module.exports = {
  module: {
    rules: [
      {
        test: /.js/,
        enforce: 'pre',
        exclude: /node_modules/,
        use: [
          {
            loader: `jshint-loader`,
            options: {...options}
          }
        ]
      }
    ]
  }
}

And run webpack via your preferred method.

Options

All valid JSHint options are valid on this object, in addition to the custom loader options listed below:

delete options.; delete options.; delete options.;

emitErrors

Type: Boolean Default: undefined

Instructs the loader to emit all JSHint warnings and errors as webpack errors.

failOnHint

Type: Boolean Default: undefined

Instructs the loader to cause the webpack build to fail on all JSHint warnings and errors.

reporter

Type: Function Default: undefined

A function used to format and emit JSHint warnings and errors.

Custom Reporter

By default, jshint-loader will provide a default reporter.

However, if you prefer a custom reporter, pass a function under the reporter property in jshint options. (see usage above)

The reporter function will be passed an array of errors/warnings produced by JSHint with the following structure:

[
{
    id:        [string, usually '(error)'],
    code:      [string, error/warning code],
    reason:    [string, error/warning message],
    evidence:  [string, a piece of code that generated this error]
    line:      [number]
    character: [number]
    scope:     [string, message scope;
                usually '(main)' unless the code was eval'ed]

    [+ a few other legacy fields that you don't need to worry about.]
},
// ...
// more errors/warnings
]

The reporter function will be excuted with the loader context as this. You may emit messages using this.emitWarning(...) or this.emitError(...). See webpack docs on loader context.

Note: JSHint reporters are not compatible with JSHint-loader! This is due to the fact that reporter input is only processed from one file; not multiple files. Error reporting in this manner differs from traditional reporters for JSHint since the loader plugin (i.e. JSHint-loader) is executed for each source file; and thus the reporter is executed for each file.

The output in webpack CLI will usually be:

...
WARNING in ./path/to/file.js
<reporter output>
...

`

Contributing

Please take a moment to read our contributing guidelines if you haven't yet done so.

CONTRIBUTING

License

MIT