vfile-reporter
Advanced tools
Comparing version 1.5.0 to 2.0.0
@@ -1,5 +0,13 @@ | ||
<!--mdast setext--> | ||
<!--remark setext--> | ||
<!--lint disable no-multiple-toplevel-headings--> | ||
<!--lint disable no-multiple-toplevel-headings --> | ||
2.0.0 / 2016-06-23 | ||
================== | ||
* Add support for `defaultName` ([`fb461cf`](https://github.com/wooorm/vfile-reporter/commit/fb461cf)) | ||
* Add support for passing an error ([`a4c95be`](https://github.com/wooorm/vfile-reporter/commit/a4c95be)) | ||
* Fix mutation of files ([`ea22861`](https://github.com/wooorm/vfile-reporter/commit/ea22861)) | ||
* Fix ranges on files with file-paths added later ([`6359168`](https://github.com/wooorm/vfile-reporter/commit/6359168)) | ||
1.5.0 / 2015-11-21 | ||
@@ -6,0 +14,0 @@ ================== |
339
index.js
@@ -13,6 +13,5 @@ /** | ||
/* | ||
* Dependencies. | ||
*/ | ||
/* eslint-env commonjs */ | ||
/* Dependencies. */ | ||
var pluralize = require('plur'); | ||
@@ -26,16 +25,10 @@ var width = require('string-width'); | ||
/* | ||
* Map of no-warning messages, where `true` refers to | ||
* `compile: true`. | ||
*/ | ||
/* Map of no-warning messages, where `true` refers to | ||
* `compile: true`. */ | ||
var SUCCESS = { | ||
'true': chalk.yellow('written'), | ||
'false': 'no issues found' | ||
true: chalk.yellow('written'), | ||
false: 'no issues found' | ||
}; | ||
/* | ||
* List of probabbly lengths of messages. | ||
*/ | ||
/* List of probable lengths of messages. */ | ||
var POSITION_LENGTH = '00:0-00:0'.length; | ||
@@ -45,30 +38,6 @@ var LABEL_LENGTH = 'message'.length; | ||
/** | ||
* Reject messages without `fatal: true`. | ||
* | ||
* NOTE: Modifies the given files. | ||
* | ||
* @param {Array.<VFile>} files - List of files. | ||
*/ | ||
function removeNonFatalMessages(files) { | ||
files.forEach(function (file) { | ||
file.messages = file.messages.filter(function (message) { | ||
return message.fatal === true; | ||
}) | ||
}); | ||
} | ||
/* Default filename. */ | ||
var DEFAULT = '<stdin>'; | ||
/** | ||
* Reject files without messages. | ||
* | ||
* @param {Array.<VFile>} files - List of files. | ||
* @return {Array.<VFile>} - `files` without non-failed messages. | ||
*/ | ||
function removeNonFailedFiles(files) { | ||
return files.filter(function (file) { | ||
return Boolean(file.messages.length); | ||
}); | ||
} | ||
/** | ||
* Get the length of `value`, ignoring ANSI sequences. | ||
@@ -80,9 +49,9 @@ * | ||
function realLength(value) { | ||
var index = value.indexOf('\n'); | ||
var index = value.indexOf('\n'); | ||
if (index !== -1) { | ||
value = value.slice(0, index); | ||
} | ||
if (index !== -1) { | ||
value = value.slice(0, index); | ||
} | ||
return width(value); | ||
return width(value); | ||
} | ||
@@ -97,7 +66,7 @@ | ||
* @param {boolean?} [side] - Side to pad on. | ||
* @return {string} - Right-padded `value`. | ||
* @return {string} - padded `value`. | ||
*/ | ||
function pad(value, minimum, side) { | ||
var padding = repeat(' ', minimum - realLength(value)); | ||
return side ? padding + value : value + padding; | ||
var padding = repeat(' ', minimum - realLength(value)); | ||
return side ? padding + value : value + padding; | ||
} | ||
@@ -113,3 +82,3 @@ | ||
function padLeft(value, minimum) { | ||
return pad(value, minimum, true); | ||
return pad(value, minimum, true); | ||
} | ||
@@ -125,6 +94,16 @@ | ||
function padRight(value, minimum) { | ||
return pad(value, minimum, false); | ||
return pad(value, minimum, false); | ||
} | ||
/** | ||
* Stringify one position. | ||
* | ||
* @param {Position} position - Point. | ||
* @return {string} - Stringified point. | ||
*/ | ||
function point(position) { | ||
return [position.line || 1, position.column || 1].join(':'); | ||
} | ||
/** | ||
* @param {VFile|Array.<VFile>} files - One or more virtual | ||
@@ -143,153 +122,183 @@ * files. | ||
function reporter(files, options) { | ||
var total = 0; | ||
var errors = 0; | ||
var warnings = 0; | ||
var result = []; | ||
var listing = false; | ||
var summaryColor; | ||
var summary; | ||
var verbose; | ||
var settings = options || {}; | ||
var silent = settings.silent; | ||
var quiet = settings.quiet || settings.silent; | ||
var verbose = settings.verbose; | ||
var defaultName = settings.defaultName || DEFAULT; | ||
var fileCount = 0; | ||
var total = 0; | ||
var errors = 0; | ||
var warnings = 0; | ||
var result = []; | ||
var listing = false; | ||
var summaryColor; | ||
var summary; | ||
var line; | ||
var oneFile; | ||
if (!files) { | ||
return ''; | ||
} | ||
if (!files) { | ||
return ''; | ||
} | ||
if (!('length' in files)) { | ||
files = [files]; | ||
} | ||
if (files.stack) { | ||
return files.stack; | ||
} | ||
if (!options) { | ||
options = {}; | ||
} | ||
if (!('length' in files)) { | ||
oneFile = true; | ||
files = [files]; | ||
} | ||
verbose = options.verbose || false; | ||
files.forEach(function (file, position) { | ||
var destination = file.filePath(); | ||
var filePath = file.history[0] || destination; | ||
var stored = Boolean(file.stored); | ||
var moved = stored && destination !== filePath; | ||
var name = filePath || defaultName; | ||
var output = ''; | ||
var messages; | ||
var fileColor; | ||
if (options.silent) { | ||
removeNonFatalMessages(files); | ||
sort(file); | ||
messages = file.messages; | ||
if (silent) { | ||
messages = messages.filter(function (message) { | ||
return message.fatal === true; | ||
}); | ||
} | ||
if (options.silent || options.quiet) { | ||
files = removeNonFailedFiles(files); | ||
if (quiet && !messages.length) { | ||
return; | ||
} | ||
files.forEach(function (file, position) { | ||
var destination = file.filePath(); | ||
var filePath = file.history[0] || destination; | ||
var stored = Boolean(file.stored); | ||
var moved = stored && destination !== filePath; | ||
var name = filePath || '<stdin>'; | ||
var output = ''; | ||
var messages; | ||
var fileColor; | ||
fileCount++; | ||
total += messages.length; | ||
sort(file); | ||
messages = messages.map(function (message) { | ||
var color = 'yellow'; | ||
var pos = message.location; | ||
var label; | ||
var reason; | ||
var location; | ||
messages = file.messages; | ||
location = point(pos.start); | ||
total += messages.length; | ||
if (pos.end.line && pos.end.column) { | ||
location += '-' + point(pos.end); | ||
} | ||
messages = messages.map(function (message) { | ||
var color = 'yellow'; | ||
var location = message.name; | ||
var label; | ||
var reason; | ||
if (message.fatal) { | ||
color = fileColor = summaryColor = 'red'; | ||
label = 'error'; | ||
errors++; | ||
} else if (message.fatal === false) { | ||
label = 'warning'; | ||
warnings++; | ||
if (filePath) { | ||
location = location.slice(location.indexOf(':') + 1); | ||
} | ||
if (!summaryColor) { | ||
summaryColor = color; | ||
} | ||
if (message.fatal) { | ||
color = fileColor = summaryColor = 'red'; | ||
label = 'error'; | ||
errors++; | ||
} else if (message.fatal === false) { | ||
label = 'warning'; | ||
warnings++; | ||
if (!fileColor) { | ||
fileColor = color; | ||
} | ||
} else { | ||
label = 'message'; | ||
color = 'gray'; | ||
} | ||
if (!summaryColor) { | ||
summaryColor = color; | ||
} | ||
reason = message.stack || message.message; | ||
if (!fileColor) { | ||
fileColor = color; | ||
} | ||
} else { | ||
label = 'message'; | ||
color = 'gray'; | ||
} | ||
if (verbose && message.note) { | ||
reason += '\n' + message.note; | ||
} | ||
reason = message.stack || message.message; | ||
return [ | ||
'', | ||
padLeft(location, POSITION_LENGTH), | ||
padRight(chalk[color](label), LABEL_LENGTH), | ||
padRight(reason, MESSAGE_LENGTH), | ||
message.ruleId || '' | ||
]; | ||
}); | ||
if (verbose && message.note) { | ||
reason += '\n' + message.note; | ||
} | ||
if (listing || (messages.length && position !== 0)) { | ||
output += '\n'; | ||
} | ||
return [ | ||
'', | ||
padLeft(location, POSITION_LENGTH), | ||
padRight(chalk[color](label), LABEL_LENGTH), | ||
padRight(reason, MESSAGE_LENGTH), | ||
message.ruleId || '' | ||
]; | ||
}); | ||
output += chalk.underline[fileColor || 'green'](name); | ||
if (listing || (messages.length && position !== 0)) { | ||
output += '\n'; | ||
} | ||
if (moved) { | ||
output += ' > ' + destination; | ||
} | ||
output += chalk.underline[fileColor || 'green'](name); | ||
listing = Boolean(messages.length); | ||
if (moved) { | ||
output += ' > ' + destination; | ||
} | ||
if (listing) { | ||
output += '\n' + table(messages, { | ||
align: ['', 'l', 'l', 'l'], | ||
stringLength: realLength | ||
}); | ||
} else { | ||
output += ': ' + SUCCESS[stored]; | ||
} | ||
listing = Boolean(messages.length); | ||
result.push(output); | ||
}); | ||
if (!listing) { | ||
output += ': ' + SUCCESS[stored]; | ||
} else { | ||
output += '\n' + table(messages, { | ||
'align': ['', 'l', 'l', 'l'], | ||
'stringLength': realLength | ||
}); | ||
} | ||
/* Remove header, if possible. */ | ||
if (oneFile && fileCount && !settings.defaultName) { | ||
line = result[0]; | ||
result.push(output); | ||
}); | ||
if (chalk.stripColor(line).slice(0, DEFAULT.length) === DEFAULT) { | ||
if (listing) { | ||
line = line.slice(line.indexOf('\n') + 1); | ||
} else { | ||
line = line.slice(line.indexOf(': ') + 2); | ||
} | ||
if (errors || warnings) { | ||
summary = []; | ||
result[0] = line; | ||
} | ||
} | ||
if (errors) { | ||
summary.push([ | ||
symbols.error, | ||
errors, | ||
pluralize('error', errors) | ||
].join(' ')); | ||
} | ||
if (errors || warnings) { | ||
summary = []; | ||
if (warnings) { | ||
summary.push([ | ||
symbols.warning, | ||
warnings, | ||
pluralize('warning', warnings) | ||
].join(' ')); | ||
} | ||
if (errors) { | ||
summary.push([ | ||
symbols.error, | ||
errors, | ||
pluralize('error', errors) | ||
].join(' ')); | ||
} | ||
summary = summary.join(', '); | ||
if (warnings) { | ||
summary.push([ | ||
symbols.warning, | ||
warnings, | ||
pluralize('warning', warnings) | ||
].join(' ')); | ||
} | ||
if (errors && warnings) { | ||
summary = total + ' messages (' + summary + ')'; | ||
} | ||
summary = summary.join(', '); | ||
result.push('\n' + summary); | ||
if (errors && warnings) { | ||
summary = total + ' messages (' + summary + ')'; | ||
} | ||
return result.length ? result.join('\n') : ''; | ||
result.push('\n' + summary); | ||
} | ||
result = result.length ? result.join('\n') : ''; | ||
if (settings.color === false) { | ||
result = chalk.stripColor(result); | ||
} | ||
return result; | ||
} | ||
/* | ||
* Expose. | ||
*/ | ||
/* Expose. */ | ||
module.exports = reporter; |
{ | ||
"name": "vfile-reporter", | ||
"version": "1.5.0", | ||
"version": "2.0.0", | ||
"description": "Stylish reporter for virtual files", | ||
@@ -11,11 +11,16 @@ "license": "MIT", | ||
"lint", | ||
"validate", | ||
"format", | ||
"message", | ||
"warning", | ||
"error", | ||
"retext", | ||
"mdast" | ||
"error" | ||
], | ||
"repository": "wooorm/vfile-reporter", | ||
"files": [ | ||
"index.js" | ||
], | ||
"repository": "https://github.com/wooorm/vfile-reporter", | ||
"bugs": "https://github.com/wooorm/vfile-reporter/issues", | ||
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)", | ||
"contributors": [ | ||
"Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)" | ||
], | ||
"dependencies": { | ||
@@ -30,32 +35,47 @@ "chalk": "^1.1.0", | ||
}, | ||
"author": "Titus Wormer <tituswormer@gmail.com>", | ||
"files": [ | ||
"index.js" | ||
], | ||
"devDependencies": { | ||
"eslint": "^1.0.0", | ||
"esmangle": "^1.0.0", | ||
"istanbul": "^0.3.0", | ||
"jscs": "^2.0.0", | ||
"jscs-jsdoc": "^1.0.0", | ||
"mdast": "^1.0.0", | ||
"mdast-comment-config": "^1.0.0", | ||
"mdast-github": "^1.0.0", | ||
"mdast-lint": "^1.0.0", | ||
"mocha": "^2.0.0", | ||
"browserify": "^13.0.1", | ||
"esmangle": "^1.0.1", | ||
"istanbul": "^0.4.0", | ||
"remark-cli": "^1.0.0", | ||
"remark-comment-config": "^4.0.0", | ||
"remark-github": "^5.0.0", | ||
"remark-lint": "^4.0.0", | ||
"remark-usage": "^4.0.0", | ||
"remark-validate-links": "^4.0.0", | ||
"tape": "^4.0.0", | ||
"to-vfile": "^1.0.0", | ||
"vfile": "^1.0.0" | ||
"vfile": "^1.0.0", | ||
"xo": "^0.16.0" | ||
}, | ||
"scripts": { | ||
"test-api": "mocha --check-leaks test.js", | ||
"test-coverage": "istanbul cover _mocha -- test.js", | ||
"test-travis": "npm run test-coverage", | ||
"test": "npm run test-api", | ||
"lint-api": "eslint .", | ||
"lint-style": "jscs --reporter inline .", | ||
"lint": "npm run lint-api && npm run lint-style", | ||
"make": "npm run lint && npm run test-coverage", | ||
"build-md": "mdast . --quiet", | ||
"build": "npm run build-md" | ||
"build-md": "remark . --quiet --frail", | ||
"build-bundle": "browserify index.js --bare -s vfileReporter > vfile-reporter.js", | ||
"build-mangle": "esmangle vfile-reporter.js > vfile-reporter.min.js", | ||
"build": "npm run build-md && npm run build-bundle && npm run build-mangle", | ||
"lint": "xo", | ||
"test-api": "node test.js", | ||
"test-coverage": "istanbul cover test.js", | ||
"test": "npm run build && npm run lint && npm run test-coverage" | ||
}, | ||
"xo": { | ||
"space": true, | ||
"ignores": [ | ||
"vfile-reporter.js", | ||
"vfile-reporter.min.js" | ||
] | ||
}, | ||
"remarkConfig": { | ||
"output": true, | ||
"plugins": [ | ||
"comment-config", | ||
"lint", | ||
"github", | ||
"validate-links", | ||
"usage" | ||
], | ||
"settings": { | ||
"bullet": "*" | ||
} | ||
} | ||
} |
100
readme.md
@@ -1,9 +0,11 @@ | ||
# vfile-reporter [![Build Status](https://img.shields.io/travis/wooorm/vfile-reporter.svg)](https://travis-ci.org/wooorm/vfile-reporter) [![Coverage Status](https://img.shields.io/codecov/c/github/wooorm/vfile-reporter.svg)](https://codecov.io/github/wooorm/vfile-reporter) | ||
# vfile-reporter [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] | ||
Format [**VFile**](https://github.com/wooorm/vfile)s using a stylish reporter. | ||
<!--lint disable heading-increment list-item-spacing--> | ||
Format [**VFile**][vfile]s using a stylish reporter. | ||
Originally forked from ESLint’s stylish reporter, but with some coolness | ||
added. | ||
![Example screen shot of **vfile-reporter**](./screenshot.png) | ||
![Example screen shot of **vfile-reporter**][screenshot] | ||
@@ -14,10 +16,7 @@ ## Features | ||
— Not just a starting position, such as `3:2`, but `3:2-3:6`. | ||
* [x] Stack-traces | ||
— When something awful happens, you want to know **where** it occurred, | ||
stack-traces help answer that question. | ||
* [x] Successful files (configurable) | ||
— Sometimes you want to know if things went okay. | ||
* [x] And all of [**VFile**](https://github.com/wooorm/vfile)s awesomeness. | ||
@@ -27,27 +26,37 @@ | ||
[npm](https://docs.npmjs.com/cli/install): | ||
[npm][npm-install]: | ||
```bash | ||
npm install vfile-report | ||
npm install vfile-reporter | ||
``` | ||
**vfile-reporter** is also available as an AMD, CommonJS, and | ||
globals module, [uncompressed and compressed][releases]. | ||
## Usage | ||
```js | ||
Dependencies: | ||
```javascript | ||
var toVFile = require('to-vfile'); | ||
var reporter = require('vfile-reporter'); | ||
``` | ||
Files: | ||
```javascript | ||
var one = toVFile('test/fixture/1.js'); | ||
var two = toVFile('test/fixture/2.js'); | ||
``` | ||
/* | ||
* See VFile’s docs for more info on how to warn. | ||
*/ | ||
Trigger a warning: | ||
one.warn('Warning!', { | ||
'line': 2, | ||
'column': 4 | ||
}); | ||
```javascript | ||
one.warn('Warning!', {line: 2, column: 4}); | ||
``` | ||
console.log(reporter([one, two])); | ||
Report: | ||
```javascript | ||
var report = reporter([one, two], {color: false}); | ||
``` | ||
@@ -57,3 +66,3 @@ | ||
```text | ||
```txt | ||
test/fixture/1.js | ||
@@ -69,31 +78,58 @@ 2:4 warning Warning! | ||
### reporter(vfiles\[, options\]) | ||
### `reporter(files[, options])` | ||
Generate a stylish report from the given files. | ||
**Signatures** | ||
###### Parameters | ||
* `report = reporter(file[, options])` | ||
* `report = reporter(files[, options])` | ||
* `files` (`Error`, [`VFile`][vfile], or `Array.<VFile>`). | ||
* `options` (`object`, optional): | ||
**Parameters** | ||
* `options` (`Object`, optional) | ||
* `quiet` (`boolean`, default: `false`) | ||
— Do not output anything for a file which has no warnings or errors. | ||
The default behaviour is to show a success message. | ||
— Do not output anything for a file which has no warnings or | ||
errors. The default behaviour is to show a success message. | ||
* `silent` (`boolean`, default: `false`) | ||
— Do not output messages without `fatal` set to true. | ||
Also sets `quiet` to `true`. | ||
* `color` (`boolean`, default: `true`) | ||
— Whether to use colour. | ||
* `defaultName` (`string`, default: `'<stdin>'`) | ||
— Label to use for files without file-path. | ||
If one file and no `defaultName` is given, no name | ||
will show up in the report. | ||
**Returns**: `string`, a stylish report. | ||
###### Returns | ||
`string`, a stylish report. | ||
## License | ||
[MIT](LICENSE) © [Titus Wormer](http://wooorm.com) | ||
[MIT][license] © [Titus Wormer][author] | ||
Forked from [ESLint](https://github.com/eslint/eslint)’s stylish reporter | ||
Forked from [ESLint][]’s stylish reporter | ||
(originally created by Sindre Sorhus), which is Copyright (c) 2013 | ||
Nicholas C. Zakas, and licensed under MIT. | ||
<!-- Definitions --> | ||
[travis-badge]: https://img.shields.io/travis/wooorm/vfile-reporter.svg | ||
[travis]: https://travis-ci.org/wooorm/vfile-reporter | ||
[codecov-badge]: https://img.shields.io/codecov/c/github/wooorm/vfile-reporter.svg | ||
[codecov]: https://codecov.io/github/wooorm/vfile-reporter | ||
[npm-install]: https://docs.npmjs.com/cli/install | ||
[releases]: https://github.com/wooorm/retext-intensify/releases | ||
[license]: LICENSE | ||
[author]: http://wooorm.com | ||
[eslint]: https://github.com/eslint/eslint | ||
[vfile]: https://github.com/wooorm/vfile | ||
[screenshot]: ./screenshot.png |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
14564
245
132
13