GithubHelp home page GithubHelp logo

reporters's Introduction

reporters

Extracts information from csslint, jshint, ... reporters and allows you to handle them all in the same way.

Introduction

Don't you find it very frustrating that each package logs errors/warnings in it's own format. This package is an attempt to collect the error/warning information of node packages and log/handle them in your favorite way.

The default output format is in a Visual Studio friendly way (you can double click to go to the problem line):

C:/Users/JoVdB/MyProject/css/index.css(5,9): warning: Unknown property 'colour'. (rule: known-properties)

The application has a list of built-in reporters that can be used (gulp-csslint, gulp-jshint, gulp-typescript, gulp--sass, gulp-jasmine), or you can also create your own.

As output you can use one of the built-in outputs (Visual Studio style, notifier, beep) or create your own

All built-in reporters collect error/warning information (messages) that is passed to the output, it can contain following items:

  • sourceName: 'gulp-csslint'
  • type: 'warning' // 'info' or 'error'
  • filePath: c:/Users/JoVdB/MyProject/css/index.css
  • lineNbr: 5
  • colNbr: 9
  • description: Unknown property 'colour'. (rule: known-properties)
  • code: 'known-properties'

Installation

npm install gulp-csslint --save-dev

Samples

Examples are for gulp

jshint example:

var jshint = require('gulp-jshint');
var reporters = require('reporters');

gulp.task('jshint', function () {
  return gulp.src(['./**/*.js'])
    .pipe(jshint())
    .pipe(jshint.reporter(reporters('gulp-jshint')));
});

csslint example:

var csslint = require('gulp-csslint');
var reporters = require('reporters');

gulp.task('csslint', function () {
return gulp.src(['./**/*.css'])
  .pipe(csslint())
  .pipe(csslint.reporter(reporters('gulp-csslint')));

});

tslint/typescript example:

var typescript = require('gulp-typescript');
var tslint = require('gulp-tslint');
var reporters = require('reporters');

gulp.task('typescript', function () {
var tsResult = gulp.src(['./**/*.ts', '!./**/*.d.ts'])
  .pipe(tslint())
  .pipe(tslint.report(reporters('gulp-tslint', {warning: true})))
  .pipe(typescript({}, {}, reporters('gulp-typescript')));
tsResult.js
  .pipe(gulp.dest('js/')):

});

sass example:

var sass = require('gulp-sass');
var reporters = require('reporters');

gulp.task('csslint', function () {
return gulp.src(['./**/*.scss'])
  .pipe(sass({
    onError: reporters('gulp-sass')
  }))

});

jasmine example:

var jasmine = require('gulp-jasmine');
var reporters = require('reporters');

gulp.src('./**/*Spec.js')
  .pipe(jasmine({
    reporter: reporters('gulp-jasmine')
  }));

Configuration

getAvailable()

Returns a list of available built-in reporters. You can use one of the available reporters by calling reporters() with the reporter name:

var reporters = require('reporters');
reporters('gulp-jshint'); // returns reporter that can be used with the gulp-jshint package

Some reporters accept configuration properties:

var reporters = require('reporters');
reporters('gulp-jshint', {
  debug: true // log reporter information
});

debug = false

Enable to logs detailed information of what is done.

var reporters = require('reporters');
reporters.debug = true;

filterOrUpdate(messages)

This is your chance to remove or update messages before they are handled. You can use this to limit the number of messages handled.

var reporters = require('reporters');
var logCount = 0;
reporters.filterOrUpdate = function(messages) {
  return messages.filter(function(message) {
    logCount++;
    return (message.filePath.indexOf('/3rdParty/') === -1) && (logCount <= 100);
  });
};

output

A function (or array of functions) that can handle messages.

var reporters = require('reporters');
reporters.output = function(messages) {
  messages && messages.forEach(function(message) {
    console.log(message.description);
  })
};

There is a built-in list of output handlers. you can get it with reporters.getOutputs()

You can use one of the built-in output handlers with reporters.getOutput('name')(options):

reporters.output = [
   reporters.getOutput('vs-console')();
   reporters.getOutput('notify')();
];

report(messages)

This method will the handle the messages. report() will first use filterOrUpdate and then check if sourcemaps are available to update error locations. It will then send the results to the output handlers.

You can log messages in this way:

var reporters = require('reporters');
var message = {
  filePath: 'index.html',
  type: 'warning',
  description: 'HTML should be minified.'
}
reporters.report([message]);

If you write your own reporter you can manually call this method to handle messages in the same way:

var unsupportedModule = required('unsupportedModule');
var reporters = require('reporters');

gulp.src('scripts/**/*.js')
  .pipe(unsupportedModule({
    reporter: function (errors) {
      var messages = errors.map(function (error) {
        return {
          description: error.reason,
          sourceName: 'unsupportedModule'
        };
      });
      reporters.report(messages);
    }
  });

reporters's People

Contributors

jovdb avatar

Watchers

Ray Lugo, Jr. avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.