Skip to content

pandell/gulp-jslint-simple

Repository files navigation

gulp-jslint-simple

Build status "dependencies" status "devDependencies" status

Run JSLint analysis

Git repository

Changelog

How is this package different from other JSLint runners?

Install

$ npm install --save-dev gulp-jslint-simple

Usage

var gulp = require('gulp');
var jslint = require('gulp-jslint-simple');

gulp.task('lint', function () {
    gulp.src('*.js')
        .pipe(jslint.run({
            // project-wide JSLint options
            node: true,
            vars: true
        }))
        .pipe(jslint.report({
            // example of using a JSHint reporter
            reporter: require('jshint-stylish').reporter
        }));
});

API

Assuming:

var jslint = require('gulp-jslint-simple');

jslint.run([options])

Creates a transform stream that expects Vinyl File objects in buffer mode (stream and null-contents modes are not supported) as input. The stream passes each incoming file object to the output unchanged. Each incoming object will be analysed using latest JSLint. If analysis fails, a property jslint will be added to the object. A property jshint pointing to jslint will also be added for compatibility with JSHint reporters.

options

Type: Object
Default: no options

Options to pass through to JSLINT function. Allows overriding default JSLint flags on a project level (flags can then be overridden again at a file level using /*jslint*/ comments).

options.includeData

Type: Boolean
Default: false

If true, jslint property is added even when analysis succeeds. Additionally, jslint.data property is populated with JSLINT.data() object that contains analysis details.

jslint.report([options])

Creates a transform stream that expects Vinyl File objects as input. The stream passes each incoming file object to the output unchanged. Each incoming object that contains a file that failed JSLint analysis will be reported using options.reporter.

options

Type: Object
Default: no options

Control report behaviour.

options.reporter

Type: Function
Default: jslint.report.defaultReporter

Reporter to use to report errors for files that failed JSLint analysis.

options.emitError

Type: Boolean
Default: false

If true, jslint.report will emit an error event when an incoming file fails JSLint analysis.

options.emitErrorAtEnd

Type: Boolean
Default: false

If true, jslint.report will emit an error event after the input stream has ended and at least one file failed analysis.

If neither options.emitError nor options.emitErrorAtEnd are set to true, no error event will be emitted. jslint.report stream then acts as a simple pass-through transform stream.

jslint.report.defaultReporter(results, data, options)

JSHint-reporter-compatible function that prints formatted message for each specified error result. File, line and row specification is printed in a format that is recognized by many editors and tools (clicking the file specification in such tools will open the specified file for editing at the specified location). Example output:

Example default reporter output

Contributing

  1. Clone git repository

  2. npm install (will install dev dependencies needed by the next step)

  3. npm start (will start a file system watcher that will re-lint JavaScript and JSON files + re-run all tests when change is detected)

  4. Make changes, don't forget to add tests, submit a pull request.

License

MIT © Pandell Technology