├── .github └── workflows │ └── add-to-project.yaml ├── .npmignore ├── .travis.yml ├── LICENSE ├── README.md ├── bin └── cmd.js ├── img ├── after.png └── before.png ├── index.js └── package.json /.github/workflows/add-to-project.yaml: -------------------------------------------------------------------------------- 1 | on: 2 | pull_request: 3 | types: [opened] 4 | issues: 5 | types: [opened] 6 | 7 | jobs: 8 | add-to-project: 9 | uses: standard/.github/.github/workflows/add-to-project.yaml@master 10 | secrets: inherit 11 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .travis.yml 2 | img/ 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - lts/* 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Feross Aboukhadijeh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # snazzy [![travis][travis-image]][travis-url] [![npm][npm-image]][npm-url] [![downloads][downloads-image]][downloads-url] [![javascript style guide][standard-image]][standard-url] 2 | 3 | [travis-image]: https://img.shields.io/travis/feross/snazzy/master.svg 4 | [travis-url]: https://travis-ci.org/feross/snazzy 5 | [npm-image]: https://img.shields.io/npm/v/snazzy.svg 6 | [npm-url]: https://npmjs.org/package/snazzy 7 | [downloads-image]: https://img.shields.io/npm/dm/snazzy.svg 8 | [downloads-url]: https://npmjs.org/package/snazzy 9 | [standard-image]: https://img.shields.io/badge/code_style-standard-brightgreen.svg 10 | [standard-url]: https://standardjs.com 11 | 12 | ### Format [JavaScript Standard Style](https://github.com/feross/standard) as Stylish (i.e. snazzy) output 13 | 14 | Converts "compact" text from a linter to "stylish" (i.e. snazzy) output. 15 | 16 | ![after](img/after.png) 17 | 18 | Compared to before: 19 | 20 | ![before](img/before.png) 21 | 22 | ## install 23 | 24 | ``` 25 | npm install -g snazzy 26 | ``` 27 | 28 | ## usage 29 | 30 | Pipe "compact" text into the `snazzy` command to get back pretty results: 31 | 32 | ```bash 33 | $ standard --verbose | snazzy 34 | ``` 35 | 36 | ## note about version 7.0.0 37 | 38 | `standard` is no longer bundled with snazzy. You must install `standard` manually 39 | alongside `snazzy`. 40 | 41 | Run `npm install standard --save-dev` to get a copy of `standard`, then run 42 | `standard | snazzy` where you previously used to run `snazzy`. 43 | 44 | This way requires more steps, but it's better. The user now controls the exact 45 | version of `standard` that is used. And for users who were piping into `snazzy` all 46 | along, this means a quicker install since an extra copy of `standard` will not get 47 | installed. 48 | 49 | ## license 50 | 51 | MIT. Copyright (c) [Feross Aboukhadijeh](https://feross.org). 52 | -------------------------------------------------------------------------------- /bin/cmd.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const CompactToStylishStream = require('../') 4 | const minimist = require('minimist') 5 | 6 | const argv = minimist(process.argv.slice(2), { 7 | boolean: [ 8 | 'stdin' 9 | ] 10 | }) 11 | 12 | if (!process.stdin.isTTY || argv._[0] === '-' || argv.stdin) { 13 | const snazzy = new CompactToStylishStream() 14 | 15 | // Set the process exit code based on whether snazzy found errors 16 | process.on('exit', function (code) { 17 | if (code === 0 && snazzy.exitCode !== 0) { 18 | process.exitCode = snazzy.exitCode 19 | } 20 | }) 21 | 22 | process.stdin.pipe(snazzy).pipe(process.stdout) 23 | } else { 24 | console.error(` 25 | snazzy: 'standard' is no longer bundled with 'snazzy'. Install standard 26 | snazzy: ('npm install standard') then run 'standard | snazzy' instead. 27 | `) 28 | process.exitCode = 1 29 | } 30 | -------------------------------------------------------------------------------- /img/after.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/standard/snazzy/e5b7d4389a60cdb75df1a8bf97e24efa21dd4d65/img/after.png -------------------------------------------------------------------------------- /img/before.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/standard/snazzy/e5b7d4389a60cdb75df1a8bf97e24efa21dd4d65/img/before.png -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /*! snazzy. MIT License. Feross Aboukhadijeh */ 2 | const chalk = require('chalk') 3 | const standardJson = require('standard-json') 4 | const stream = require('readable-stream') 5 | const stripAnsi = require('strip-ansi') 6 | const table = require('text-table') 7 | 8 | class CompactToStylishStream extends stream.Transform { 9 | constructor (opts) { 10 | super(opts) 11 | 12 | this.exitCode = 0 13 | this._buffer = [] 14 | } 15 | 16 | _transform (chunk, encoding, cb) { 17 | this._buffer.push(chunk) 18 | cb(null) 19 | } 20 | 21 | _flush (cb) { 22 | const lines = Buffer.concat(this._buffer).toString() 23 | const jsonResults = standardJson(lines, { noisey: true }) 24 | const output = processResults(jsonResults) 25 | this.push(output) 26 | 27 | this.exitCode = output === '' ? 0 : 1 28 | cb(null) 29 | } 30 | } 31 | 32 | /** 33 | * Given a word and a count, append an s if count is not one. 34 | * @param {string} word A word in its singular form. 35 | * @param {int} count A number controlling whether word should be pluralized. 36 | * @returns {string} The original word with an s on the end if count is not one. 37 | */ 38 | function pluralize (word, count) { 39 | return (count === 1 ? word : word + 's') 40 | } 41 | 42 | function processResults (results) { 43 | let output = '\n' 44 | let total = 0 45 | 46 | results.forEach(function (result) { 47 | const messages = result.messages 48 | 49 | if (messages.length === 0) { 50 | return 51 | } 52 | 53 | total += messages.length 54 | output += chalk.underline(result.filePath) + '\n' 55 | 56 | output += table( 57 | messages.map(function (message) { 58 | const messageType = chalk.red('error') 59 | 60 | return [ 61 | '', 62 | message.line || 0, 63 | message.column || 0, 64 | messageType, 65 | message.message.replace(/\.$/, ''), 66 | chalk.dim(message.ruleId || '') 67 | ] 68 | }), 69 | { 70 | align: ['', 'r', 'l'], 71 | stringLength: function (str) { 72 | return stripAnsi(str).length 73 | } 74 | } 75 | ).split('\n').map(function (el) { 76 | return el.replace(/(\d+)\s+(\d+)/, function (m, p1, p2) { 77 | return chalk.dim(p1 + ':' + p2) 78 | }) 79 | }).join('\n') + '\n\n' 80 | }) 81 | 82 | if (total > 0) { 83 | output += chalk.red.bold([ 84 | '\u2716 ', total, pluralize(' problem', total), '\n' 85 | ].join('')) 86 | } 87 | 88 | return total > 0 ? output : '' 89 | } 90 | 91 | module.exports = CompactToStylishStream 92 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "snazzy", 3 | "description": "Format JavaScript Standard Style as Stylish (i.e. snazzy) output", 4 | "version": "9.0.0", 5 | "author": { 6 | "name": "Feross Aboukhadijeh", 7 | "email": "feross@feross.org", 8 | "url": "https://feross.org" 9 | }, 10 | "bin": { 11 | "snazzy": "./bin/cmd.js" 12 | }, 13 | "bugs": { 14 | "url": "https://github.com/feross/snazzy/issues" 15 | }, 16 | "dependencies": { 17 | "chalk": "^4.1.0", 18 | "inherits": "^2.0.4", 19 | "minimist": "^1.2.5", 20 | "readable-stream": "^3.6.0", 21 | "standard-json": "^1.1.0", 22 | "strip-ansi": "^6.0.0", 23 | "text-table": "^0.2.0" 24 | }, 25 | "devDependencies": { 26 | "standard": "*" 27 | }, 28 | "homepage": "https://github.com/feross/snazzy", 29 | "keywords": [ 30 | "pretty", 31 | "pretty output", 32 | "snazzy standard", 33 | "standard", 34 | "standard pretty", 35 | "stylish", 36 | "stylish for standard", 37 | "stylish formatter", 38 | "stylish reporter", 39 | "stylish standard" 40 | ], 41 | "license": "MIT", 42 | "main": "index.js", 43 | "repository": { 44 | "type": "git", 45 | "url": "git://github.com/feross/snazzy.git" 46 | }, 47 | "scripts": { 48 | "test": "standard --verbose | ./bin/cmd.js" 49 | }, 50 | "funding": [ 51 | { 52 | "type": "github", 53 | "url": "https://github.com/sponsors/feross" 54 | }, 55 | { 56 | "type": "patreon", 57 | "url": "https://www.patreon.com/feross" 58 | }, 59 | { 60 | "type": "consulting", 61 | "url": "https://feross.org/support" 62 | } 63 | ] 64 | } 65 | --------------------------------------------------------------------------------