Skip to content

Commit

Permalink
BREAKING: convert to ES class
Browse files Browse the repository at this point in the history
  • Loading branch information
feross committed Oct 27, 2020
1 parent 7fb2496 commit 9a0638d
Showing 1 changed file with 30 additions and 36 deletions.
66 changes: 30 additions & 36 deletions index.js
@@ -1,37 +1,31 @@
module.exports = CompactToStylishStream

var chalk = require('chalk')
var inherits = require('inherits')
var standardJson = require('standard-json')
var stream = require('readable-stream')
var stripAnsi = require('strip-ansi')
var table = require('text-table')

inherits(CompactToStylishStream, stream.Transform)

function CompactToStylishStream (opts) {
if (!(this instanceof CompactToStylishStream)) {
return new CompactToStylishStream(opts)
const chalk = require('chalk')
const standardJson = require('standard-json')
const stream = require('readable-stream')
const stripAnsi = require('strip-ansi')
const table = require('text-table')

class CompactToStylishStream extends stream.Transform {
constructor (opts) {
super(opts)

this.exitCode = 0
this._buffer = []
}
stream.Transform.call(this, opts)

this.exitCode = 0
this._buffer = []
}

CompactToStylishStream.prototype._transform = function (chunk, encoding, cb) {
this._buffer.push(chunk)
cb(null)
}
_transform (chunk, encoding, cb) {
this._buffer.push(chunk)
cb(null)
}

CompactToStylishStream.prototype._flush = function (cb) {
var lines = Buffer.concat(this._buffer).toString()
var jsonResults = standardJson(lines, { noisey: true })
var output = processResults(jsonResults)
this.push(output)
_flush (cb) {
const lines = Buffer.concat(this._buffer).toString()
const jsonResults = standardJson(lines, { noisey: true })
const output = processResults(jsonResults)
this.push(output)

this.exitCode = output === '' ? 0 : 1
cb(null)
this.exitCode = output === '' ? 0 : 1
cb(null)
}
}

/**
Expand All @@ -45,11 +39,11 @@ function pluralize (word, count) {
}

function processResults (results) {
var output = '\n'
var total = 0
let output = '\n'
let total = 0

results.forEach(function (result) {
var messages = result.messages
const messages = result.messages

if (messages.length === 0) {
return
Expand All @@ -60,9 +54,7 @@ function processResults (results) {

output += table(
messages.map(function (message) {
var messageType

messageType = chalk.red('error')
const messageType = chalk.red('error')

return [
'',
Expand Down Expand Up @@ -94,3 +86,5 @@ function processResults (results) {

return total > 0 ? output : ''
}

module.exports = CompactToStylishStream

0 comments on commit 9a0638d

Please sign in to comment.