Format JavaScript Standard Style as Stylish (i.e. snazzy) output
npx @tessl/cli install tessl/npm-snazzy@9.0.0Snazzy is a CLI tool and Node.js module that transforms compact text output from JavaScript linters (specifically JavaScript Standard Style) into stylish, human-readable format with colored output and formatted tables. It functions as a stream processor that accepts linter output via stdin and outputs beautifully formatted results with syntax highlighting, proper alignment, and clear error reporting.
npm install -g snazzy (for CLI usage) or npm install snazzy (for programmatic usage)const CompactToStylishStream = require("snazzy");For TypeScript usage:
import * as CompactToStylishStream from "snazzy";
// OR
import CompactToStylishStream = require("snazzy");Transform JavaScript Standard Style output to stylish format:
# Basic pipe usage
standard | snazzy
# Explicit stdin usage
snazzy --stdin
# Using file input
cat linter-output.txt | snazzyconst CompactToStylishStream = require("snazzy");
// Create a transform stream
const snazzy = new CompactToStylishStream();
// Pipe compact linter output through snazzy
process.stdin.pipe(snazzy).pipe(process.stdout);
// Check exit code after processing
process.on('exit', (code) => {
if (code === 0 && snazzy.exitCode !== 0) {
process.exitCode = snazzy.exitCode;
}
});Snazzy is built around several key components:
CompactToStylishStream class that extends Node.js Transform stream for processing linter outputbin/cmd.js that handles command-line usage and argument parsingCore functionality for transforming compact linter output to stylish format.
/**
* Transform stream that converts compact linter output to stylish format
* Extends Node.js readable-stream.Transform with buffering and formatting capabilities
* @param {Object} opts - Options object passed to Transform constructor (optional)
* Accepts all standard Node.js Transform stream options including:
* - objectMode: boolean - Whether to operate in object mode
* - highWaterMark: number - Buffer size for the stream
* - encoding: string - Default encoding for string data
*/
class CompactToStylishStream extends stream.Transform {
constructor(opts);
/** Exit code based on presence of errors (0 = no errors, 1 = errors found) */
exitCode: number;
}The CompactToStylishStream class is the main export and extends Node.js readable-stream.Transform. It implements the standard Transform stream interface:
_transform()_flush()exitCode property based on linting resultsThe class buffers all input, processes it through the standard-json parser, and outputs formatted results in a single flush operation.
Usage Example:
const CompactToStylishStream = require("snazzy");
const fs = require("fs");
// Transform a file containing compact linter output
const snazzy = new CompactToStylishStream();
fs.createReadStream("compact-output.txt")
.pipe(snazzy)
.pipe(process.stdout);
// Check for errors after processing
snazzy.on('finish', () => {
console.log(`Processing completed with exit code: ${snazzy.exitCode}`);
});CLI functionality for processing linter output from the command line.
# Command line usage patterns
snazzy [options]
# Options:
--stdin # Explicitly read from stdin (optional, auto-detected)
# Input methods:
standard | snazzy # Pipe from standard or other linters
snazzy < output.txt # Redirect file input
echo "output" | snazzy # Pipe from command
snazzy --stdin # Explicit stdin flagThe CLI automatically detects whether input is coming from stdin (pipe/redirect) or if it's being run interactively. When run without piped input, it displays a helpful error message directing users to install and use the standard linter.
Error Handling:
The formatted output includes:
Input Format: Compact text format from JavaScript Standard Style linter Output Format: Stylish formatted output with:
/**
* Main transform stream class for converting linter output
* Extends Node.js readable-stream.Transform with buffering and formatting capabilities
*/
class CompactToStylishStream extends stream.Transform {
/**
* @param {Object} opts - Options object passed to Transform constructor (optional)
* Accepts all standard Node.js Transform stream options including:
* - objectMode: boolean - Whether to operate in object mode
* - highWaterMark: number - Buffer size for the stream
* - encoding: string - Default encoding for string data
*/
constructor(opts);
/**
* Exit code indicating presence of linting errors
* Set after processing completes in _flush() method
* @type {number} 0 for success, 1 for errors found
*/
exitCode: number;
}Snazzy relies on these external packages:
Snazzy handles various scenarios gracefully:
{
"scripts": {
"lint": "standard --verbose | snazzy",
"lint-fix": "standard --fix --verbose | snazzy"
}
}#!/bin/bash
# CI linting with pretty output
npm run lint || {
echo "Linting failed. See errors above."
exit 1
}const CompactToStylishStream = require("snazzy");
const { spawn } = require("child_process");
// Custom linter integration
const linter = spawn("your-linter", ["--format=compact"]);
const formatter = new CompactToStylishStream();
linter.stdout.pipe(formatter).pipe(process.stdout);
linter.on('close', (code) => {
process.exitCode = code || formatter.exitCode;
});