npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

reporters

v0.0.4

Published

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

Downloads

232

Readme

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);
    }
  });