gulp-notify-linter-reporters
v1.0.3
Published
Reporters for linting errors using notifications
Downloads
4
Maintainers
Readme
gulp-notify-linter-reporters
A Node.js module for reporting lint errors via notifications on Mac, Windows, and Linux.
Install
$ npm install --save-dev gulp-notify-linter-reporters
Usage
Setup a gulpfile.js
with some linters:
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var jscs = require('gulp-jscs');
gulp.task('default', function() {
return gulp.src('**/*.js')
.pipe(jshint())
.pipe(jscs());
});
Reporting all linting errors together
var notifyLinterReporter = require('gulp-notify-linter-reporter');
...
gulp.task('default', function() {
return gulp.src('**/*.js')
.pipe(jshint())
.pipe(jscs());
.pipe(notifyLinterReporter())
});
Reporting specific linting errors
var notifyLinterReporter = require('gulp-notify-linter-reporter');
...
gulp.task('default', function() {
return gulp.src('**/*.js')
.pipe(jshint())
.pipe(jscs());
.pipe(notifyLinterReporter('jscs'))
});
Using a custom reporter
var notifyLinterReporter = require('gulp-notify-linter-reporter');
var myJSHintReporter = require(./my-jshint-reporter);
...
gulp.task('default', function() {
return gulp.src('**/*.js')
.pipe(jshint())
.pipe(notifyLinterReporter(myJSHintReporter, options))
});
API
notifyLinterReporter(String, *options)
Only report errors using the specified reporter. Available reporters: 'jscs'
, 'jshint'
.
notifyLinterReporter(Function, *options)
Use a custom reporter. See how to write a custom reporter.
notifyLinterReporter(*options)
Use all of the reporters. See node-notifier for all options.
Writing a custom reporter
A custom reporter is a function that returns an array of messages:
// Custom reporter
function reporter(files) {
var errors = files.map(function(file) {
return file.error.message;
});
return errors.filter(function(message) {
return message.length > 0;
});
}
module.exports = reporter;
Additionally, the reporter may specify a custom icon:
module.exports.icon = path.join(__dirname, 'myerror.png');
The reporter can also specify a custom message format using a formatter function. The formatter returns an Object
containing a title and/or a message.
function formatter(file, errors) {
return {
title: 'Something is wrong in: ' + file.relative,
message: 'There are ' + errors.length + ' errors.'
};
}
module.exports.formatter = formatter;
Special thanks to Mikael Brevik and his excellent gulp-notify