vfile-reporter
Advanced tools
Comparing version 6.0.2 to 7.0.0
174
index.js
@@ -1,16 +0,47 @@ | ||
'use strict' | ||
/** | ||
* @typedef {import('vfile').VFile} VFile | ||
* @typedef {import('vfile-message').VFileMessage} VFileMessage | ||
* @typedef {import('vfile-statistics').Statistics} Statistics | ||
* | ||
* @typedef Options | ||
* @property {boolean} [color] | ||
* @property {boolean} [silent=false] | ||
* @property {boolean} [quiet=false] | ||
* @property {boolean} [verbose=false] | ||
* @property {string} [defaultName='<stdin>'] | ||
* | ||
* @typedef _Row | ||
* @property {string} place | ||
* @property {string} label | ||
* @property {string} reason | ||
* @property {string} ruleId | ||
* @property {string} source | ||
* | ||
* @typedef _FileRow | ||
* @property {'file'} type | ||
* @property {VFile} file | ||
* @property {Statistics} stats | ||
* | ||
* @typedef {{[x: string]: number}} _Sizes | ||
* | ||
* @typedef _Info | ||
* @property {Array.<_FileRow|_Row>} rows | ||
* @property {Statistics} stats | ||
* @property {_Sizes} sizes | ||
*/ | ||
var supported = require('supports-color').stderr.hasBasic | ||
var width = require('string-width') | ||
var stringify = require('unist-util-stringify-position') | ||
var repeat = require('repeat-string') | ||
var statistics = require('vfile-statistics') | ||
var sort = require('vfile-sort') | ||
import supportsColor from 'supports-color' | ||
import width from 'string-width' | ||
import repeat from 'repeat-string' | ||
import {stringifyPosition} from 'unist-util-stringify-position' | ||
import {statistics} from 'vfile-statistics' | ||
import {sort} from 'vfile-sort' | ||
module.exports = reporter | ||
var own = {}.hasOwnProperty | ||
var push = [].push | ||
// @ts-ignore Types are incorrect. | ||
var supported = supportsColor.stderr.hasBasic | ||
// `log-symbols` without chalk: | ||
/* istanbul ignore next - Windows. */ | ||
// `log-symbols` without chalk, ignored for Windows: | ||
/* c8 ignore next 4 */ | ||
var chars = | ||
@@ -21,12 +52,13 @@ process.platform === 'win32' | ||
var labels = { | ||
true: 'error', | ||
false: 'warning', | ||
null: 'info', | ||
undefined: 'info' | ||
} | ||
var labels = {true: 'error', false: 'warning', null: 'info', undefined: 'info'} | ||
// Report a file’s messages. | ||
function reporter(files, options) { | ||
var settings = options || {} | ||
/** | ||
* Report a file’s messages. | ||
* | ||
* @param {Error|VFile|Array.<VFile>} [files] | ||
* @param {Options} [options] | ||
* @returns {string} | ||
*/ | ||
export function reporter(files, options = {}) { | ||
/** @type {boolean} */ | ||
var one | ||
@@ -44,3 +76,3 @@ | ||
// One file. | ||
if (!('length' in files)) { | ||
if (!Array.isArray(files)) { | ||
one = true | ||
@@ -50,19 +82,34 @@ files = [files] | ||
return format(transform(files, settings), one, settings) | ||
return format(transform(files, options), one, options) | ||
} | ||
/** | ||
* @param {Array.<VFile>} files | ||
* @param {Options} options | ||
* @returns {_Info} | ||
*/ | ||
function transform(files, options) { | ||
var index = -1 | ||
/** @type {Array.<_FileRow|_Row>} */ | ||
var rows = [] | ||
/** @type {Array.<VFileMessage>} */ | ||
var all = [] | ||
/** @type {number} */ | ||
var offset | ||
/** @type {_Sizes} */ | ||
var sizes = {} | ||
/** @type {Array.<VFileMessage>} */ | ||
var messages | ||
var offset | ||
/** @type {VFileMessage} */ | ||
var message | ||
/** @type {_Row} */ | ||
var row | ||
/** @type {Array.<_Row>} */ | ||
var messageRows | ||
var row | ||
/** @type {string} */ | ||
var key | ||
while (++index < files.length) { | ||
messages = sort({messages: files[index].messages.concat()}).messages | ||
// @ts-ignore it works fine. | ||
messages = sort({messages: [...files[index].messages]}).messages | ||
messageRows = [] | ||
@@ -78,6 +125,6 @@ offset = -1 | ||
row = { | ||
location: stringify( | ||
message.location.end.line && message.location.end.column | ||
? message.location | ||
: message.location.start | ||
place: stringifyPosition( | ||
message.position.end.line && message.position.end.column | ||
? message.position | ||
: message.position.start | ||
), | ||
@@ -93,3 +140,5 @@ label: labels[message.fatal], | ||
for (key in row) { | ||
sizes[key] = Math.max(size(row[key]), sizes[key] || 0) | ||
if (own.call(row, key)) { | ||
sizes[key] = Math.max(size(row[key]), sizes[key] || 0) | ||
} | ||
} | ||
@@ -101,20 +150,38 @@ | ||
if ((!options.quiet && !options.silent) || messageRows.length) { | ||
rows.push({type: 'file', file: files[index], stats: statistics(messages)}) | ||
push.apply(rows, messageRows) | ||
if ((!options.quiet && !options.silent) || messageRows.length > 0) { | ||
rows.push( | ||
{type: 'file', file: files[index], stats: statistics(messages)}, | ||
...messageRows | ||
) | ||
} | ||
} | ||
return {rows: rows, stats: statistics(all), sizes: sizes} | ||
return {rows, stats: statistics(all), sizes} | ||
} | ||
/** | ||
* @param {_Info} map | ||
* @param {boolean} one | ||
* @param {Options} options | ||
*/ | ||
function format(map, one, options) { | ||
var enabled = options.color == null ? supported : options.color | ||
/** @type {boolean} */ | ||
var enabled = | ||
options.color === undefined || options.color === null | ||
? supported | ||
: options.color | ||
/** @type {Array.<string>} */ | ||
var lines = [] | ||
var index = -1 | ||
/** @type {Statistics} */ | ||
var stats | ||
/** @type {_FileRow|_Row} */ | ||
var row | ||
/** @type {string} */ | ||
var line | ||
/** @type {string} */ | ||
var reason | ||
/** @type {string} */ | ||
var rest | ||
/** @type {RegExpMatchArray} */ | ||
var match | ||
@@ -125,3 +192,3 @@ | ||
if (row.type === 'file') { | ||
if ('type' in row) { | ||
stats = row.stats | ||
@@ -134,10 +201,10 @@ line = row.file.history[0] || options.defaultName || '<stdin>' | ||
: (enabled | ||
? '\x1b[4m' /* Underline. */ + | ||
? '\u001B[4m' /* Underline. */ + | ||
(stats.fatal | ||
? '\x1b[31m' /* Red. */ | ||
? '\u001B[31m' /* Red. */ | ||
: stats.total | ||
? '\x1b[33m' /* Yellow. */ | ||
: '\x1b[32m') /* Green. */ + | ||
? '\u001B[33m' /* Yellow. */ | ||
: '\u001B[32m') /* Green. */ + | ||
line + | ||
'\x1b[39m\x1b[24m' | ||
'\u001B[39m\u001B[24m' | ||
: line) + | ||
@@ -153,3 +220,3 @@ (row.file.stored && row.file.path !== row.file.history[0] | ||
? enabled | ||
? '\x1b[33mwritten\x1b[39m' /* Yellow. */ | ||
? '\u001B[33mwritten\u001B[39m' /* Yellow. */ | ||
: 'written' | ||
@@ -160,3 +227,3 @@ : 'no issues found') | ||
if (line) { | ||
if (index && map.rows[index - 1].type !== 'file') { | ||
if (index && !('type' in map.rows[index - 1])) { | ||
lines.push('') | ||
@@ -181,11 +248,11 @@ } | ||
' ' + | ||
repeat(' ', map.sizes.location - size(row.location)) + | ||
row.location + | ||
repeat(' ', map.sizes.place - size(row.place)) + | ||
row.place + | ||
' ' + | ||
(enabled | ||
? (row.label === 'error' | ||
? '\x1b[31m' /* Red. */ | ||
: '\x1b[33m') /* Yellow. */ + | ||
? '\u001B[31m' /* Red. */ | ||
: '\u001B[33m') /* Yellow. */ + | ||
row.label + | ||
'\x1b[39m' | ||
'\u001B[39m' | ||
: row.label) + | ||
@@ -214,3 +281,3 @@ repeat(' ', map.sizes.label - size(row.label)) + | ||
(enabled | ||
? '\x1b[31m' /* Red. */ + chars.error + '\x1b[39m' | ||
? '\u001B[31m' /* Red. */ + chars.error + '\u001B[39m' | ||
: chars.error) + | ||
@@ -227,3 +294,3 @@ ' ' + | ||
(enabled | ||
? '\x1b[33m' /* Yellow. */ + chars.warning + '\x1b[39m' | ||
? '\u001B[33m' /* Yellow. */ + chars.warning + '\u001B[39m' | ||
: chars.warning) + | ||
@@ -246,3 +313,8 @@ ' ' + | ||
// Get the length of `value`, ignoring ANSI sequences. | ||
/** | ||
* Get the length of `value`, ignoring ANSI sequences. | ||
* | ||
* @param {string} value | ||
* @returns {number} | ||
*/ | ||
function size(value) { | ||
@@ -249,0 +321,0 @@ var match = /\r?\n|\r/.exec(value) |
{ | ||
"name": "vfile-reporter", | ||
"version": "6.0.2", | ||
"version": "7.0.0", | ||
"description": "vfile utility to create a report for a file", | ||
@@ -32,46 +32,44 @@ "license": "MIT", | ||
], | ||
"sideEffects": false, | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.d.ts", | ||
"index.js" | ||
], | ||
"dependencies": { | ||
"repeat-string": "^1.5.0", | ||
"string-width": "^4.0.0", | ||
"supports-color": "^6.0.0", | ||
"unist-util-stringify-position": "^2.0.0", | ||
"vfile-sort": "^2.1.2", | ||
"vfile-statistics": "^1.1.0" | ||
"@types/repeat-string": "^1.0.0", | ||
"@types/supports-color": "^8.0.0", | ||
"repeat-string": "^1.0.0", | ||
"string-width": "^5.0.0", | ||
"supports-color": "^9.0.0", | ||
"unist-util-stringify-position": "^3.0.0", | ||
"vfile-sort": "^3.0.0", | ||
"vfile-statistics": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.0.0", | ||
"@babel/preset-env": "^7.0.0", | ||
"babelify": "^10.0.0", | ||
"browserify": "^17.0.0", | ||
"@types/tape": "^4.0.0", | ||
"c8": "^7.0.0", | ||
"cross-env": "^7.0.0", | ||
"figures": "^3.0.0", | ||
"nyc": "^15.0.0", | ||
"prettier": "^2.0.0", | ||
"remark-cli": "^9.0.0", | ||
"remark-preset-wooorm": "^8.0.0", | ||
"strip-ansi": "^6.0.0", | ||
"rimraf": "^3.0.0", | ||
"strip-ansi": "^7.0.0", | ||
"tape": "^5.0.0", | ||
"tinyify": "^3.0.0", | ||
"vfile": "^4.0.0", | ||
"xo": "^0.35.0" | ||
"type-coverage": "^2.0.0", | ||
"typescript": "^4.0.0", | ||
"vfile": "^5.0.0", | ||
"xo": "^0.39.0" | ||
}, | ||
"scripts": { | ||
"prepack": "npm run build && npm run format", | ||
"build": "rimraf \"*.d.ts\" && tsc && type-coverage", | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"build-bundle": "browserify . --bare -s vfileReporter -g [ babelify --presets [ \"@babel/preset-env\" ] ] -o vfile-reporter.js", | ||
"build-mangle": "browserify . --bare -s vfileReporter -g [ babelify --presets [ \"@babel/preset-env\" ] ] -o vfile-reporter.min.js -p tinyify", | ||
"build": "npm run build-bundle && npm run build-mangle", | ||
"test-api": "cross-env FORCE_COLOR=\"true\" node test", | ||
"test-coverage": "cross-env FORCE_COLOR=\"true\" nyc --reporter lcov tape test.js", | ||
"test": "npm run format && npm run build && npm run test-coverage" | ||
"test-api": "cross-env FORCE_COLOR=\"true\" node test.js", | ||
"test-coverage": "cross-env FORCE_COLOR=\"true\" c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js", | ||
"test": "npm run build && npm run format && npm run test-coverage" | ||
}, | ||
"browserslist": "> 2.5%, node 6", | ||
"nyc": { | ||
"check-coverage": true, | ||
"lines": 100, | ||
"functions": 100, | ||
"branches": 100 | ||
}, | ||
"prettier": { | ||
@@ -87,16 +85,8 @@ "tabWidth": 2, | ||
"prettier": true, | ||
"esnext": false, | ||
"rules": { | ||
"complexity": "off", | ||
"eqeqeq": "off", | ||
"guard-for-in": "off", | ||
"no-eq-null": "off", | ||
"unicorn/escape-case": "off", | ||
"unicorn/explicit-length-check": "off", | ||
"unicorn/no-hex-escape": "off", | ||
"unicorn/prefer-optional-catch-binding": "off" | ||
}, | ||
"ignores": [ | ||
"vfile-reporter.js" | ||
] | ||
"max-depth": "off", | ||
"no-var": "off", | ||
"prefer-arrow-callback": "off" | ||
} | ||
}, | ||
@@ -107,3 +97,9 @@ "remarkConfig": { | ||
] | ||
}, | ||
"typeCoverage": { | ||
"atLeast": 100, | ||
"detail": true, | ||
"strict": true, | ||
"ignoreCatch": true | ||
} | ||
} |
@@ -23,2 +23,5 @@ # vfile-reporter | ||
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c): | ||
Node 12+ is needed to use it and it must be `import`ed instead of `require`d. | ||
[npm][]: | ||
@@ -59,2 +62,5 @@ | ||
This package exports the following identifiers: `reporter`. | ||
There is no default export. | ||
### `reporter(files[, options])` | ||
@@ -61,0 +67,0 @@ |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
16629
14
5
314
176
Yes
8
+ Added@types/repeat-string@^1.0.0
+ Added@types/supports-color@^8.0.0
+ Added@types/repeat-string@1.6.5(transitive)
+ Added@types/supports-color@8.1.3(transitive)
+ Addedansi-regex@6.1.0(transitive)
+ Addedeastasianwidth@0.2.0(transitive)
+ Addedemoji-regex@9.2.2(transitive)
+ Addedis-buffer@2.0.5(transitive)
+ Addedstring-width@5.1.2(transitive)
+ Addedstrip-ansi@7.1.0(transitive)
+ Addedsupports-color@9.4.0(transitive)
+ Addedunist-util-stringify-position@3.0.3(transitive)
+ Addedvfile@5.3.7(transitive)
+ Addedvfile-message@3.1.4(transitive)
+ Addedvfile-sort@3.0.1(transitive)
+ Addedvfile-statistics@2.0.1(transitive)
- Removedansi-regex@5.0.1(transitive)
- Removedemoji-regex@8.0.0(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedis-fullwidth-code-point@3.0.0(transitive)
- Removedstring-width@4.2.3(transitive)
- Removedstrip-ansi@6.0.1(transitive)
- Removedsupports-color@6.1.0(transitive)
- Removedunist-util-stringify-position@2.0.3(transitive)
- Removedvfile-sort@2.2.2(transitive)
- Removedvfile-statistics@1.1.4(transitive)
Updatedrepeat-string@^1.0.0
Updatedstring-width@^5.0.0
Updatedsupports-color@^9.0.0
Updatedvfile-sort@^3.0.0
Updatedvfile-statistics@^2.0.0