vfile-reporter-json
Advanced tools
Comparing version 3.1.0 to 3.2.0
@@ -6,5 +6,11 @@ /** | ||
* @typedef Options | ||
* Configuration (optional). | ||
* @property {number|string|boolean} [pretty=0] | ||
* Value of `space` of `JSON.stringify(x, null, space)`. | ||
* @property {boolean} [quiet=false] | ||
* Do not show files without messages. | ||
* @property {boolean} [silent=false] | ||
* Show errors only. | ||
* This does not show info and warning messages. | ||
* Also sets `quiet` to `true`. | ||
* | ||
@@ -20,2 +26,6 @@ * @typedef _JsonMessage | ||
* @property {string} stack | ||
* @property {string} actual | ||
* @property {string|Array<string>} expected | ||
* @property {string} url | ||
* @property {string} note | ||
* | ||
@@ -25,9 +35,14 @@ * @typedef _JsonFile | ||
* @property {string} cwd | ||
* @property {Array.<string>} history | ||
* @property {Array.<_JsonMessage>} messages | ||
* @property {Array<string>} history | ||
* @property {Array<_JsonMessage>} messages | ||
*/ | ||
/** | ||
* @param {Array.<VFile>|VFile} files | ||
* Create a report from one file or multiple files. | ||
* | ||
* @param {Array<VFile>|VFile} files | ||
* File(s) to report. | ||
* @param {Options} options | ||
* Configuration (optional). | ||
* @returns {string} | ||
* Report (serialized JSON). | ||
*/ | ||
@@ -41,5 +56,19 @@ export function reporterJson( | ||
export type VFileMessage = import('vfile-message').VFileMessage | ||
/** | ||
* Configuration (optional). | ||
*/ | ||
export type Options = { | ||
/** | ||
* Value of `space` of `JSON.stringify(x, null, space)`. | ||
*/ | ||
pretty?: number | string | boolean | ||
/** | ||
* Do not show files without messages. | ||
*/ | ||
quiet?: boolean | ||
/** | ||
* Show errors only. | ||
* This does not show info and warning messages. | ||
* Also sets `quiet` to `true`. | ||
*/ | ||
silent?: boolean | ||
@@ -56,2 +85,6 @@ } | ||
stack: string | ||
actual: string | ||
expected: string | Array<string> | ||
url: string | ||
note: string | ||
} | ||
@@ -58,0 +91,0 @@ export type _JsonFile = { |
60
index.js
@@ -6,5 +6,11 @@ /** | ||
* @typedef Options | ||
* Configuration (optional). | ||
* @property {number|string|boolean} [pretty=0] | ||
* Value of `space` of `JSON.stringify(x, null, space)`. | ||
* @property {boolean} [quiet=false] | ||
* Do not show files without messages. | ||
* @property {boolean} [silent=false] | ||
* Show errors only. | ||
* This does not show info and warning messages. | ||
* Also sets `quiet` to `true`. | ||
* | ||
@@ -20,2 +26,6 @@ * @typedef _JsonMessage | ||
* @property {string} stack | ||
* @property {string} actual | ||
* @property {string|Array<string>} expected | ||
* @property {string} url | ||
* @property {string} note | ||
* | ||
@@ -25,14 +35,19 @@ * @typedef _JsonFile | ||
* @property {string} cwd | ||
* @property {Array.<string>} history | ||
* @property {Array.<_JsonMessage>} messages | ||
* @property {Array<string>} history | ||
* @property {Array<_JsonMessage>} messages | ||
*/ | ||
/** | ||
* @param {Array.<VFile>|VFile} files | ||
* Create a report from one file or multiple files. | ||
* | ||
* @param {Array<VFile>|VFile} files | ||
* File(s) to report. | ||
* @param {Options} options | ||
* Configuration (optional). | ||
* @returns {string} | ||
* Report (serialized JSON). | ||
*/ | ||
export function reporterJson(files, options = {}) { | ||
var pretty = options.pretty || 0 | ||
var data = filesToJson(Array.isArray(files) ? files : [files], options) | ||
const pretty = options.pretty || 0 | ||
const data = filesToJson(Array.isArray(files) ? files : [files], options) | ||
@@ -43,15 +58,14 @@ return JSON.stringify(data, null, pretty === true ? 2 : pretty) | ||
/** | ||
* @param {Array.<VFile>} files | ||
* @param {Array<VFile>} files | ||
* @param {Options} options | ||
* @returns {Array.<_JsonFile>} | ||
* @returns {Array<_JsonFile>} | ||
*/ | ||
function filesToJson(files, options) { | ||
var index = -1 | ||
/** @type {Array.<_JsonFile>} */ | ||
var result = [] | ||
/** @type {_JsonFile} */ | ||
var file | ||
let index = -1 | ||
/** @type {Array<_JsonFile>} */ | ||
const result = [] | ||
while (++index < files.length) { | ||
file = { | ||
/** @type {_JsonFile} */ | ||
const file = { | ||
path: files[index].path, | ||
@@ -72,15 +86,13 @@ cwd: files[index].cwd, | ||
/** | ||
* @param {Array.<VFileMessage>} messages | ||
* @param {Array<VFileMessage>} messages | ||
* @param {Options} options | ||
* @returns {Array.<_JsonMessage>} | ||
* @returns {Array<_JsonMessage>} | ||
*/ | ||
function messagesToJson(messages, options) { | ||
var index = -1 | ||
/** @type {Array.<_JsonMessage>} */ | ||
var result = [] | ||
/** @type {VFileMessage} */ | ||
var message | ||
let index = -1 | ||
/** @type {Array<_JsonMessage>} */ | ||
const result = [] | ||
while (++index < messages.length) { | ||
message = messages[index] | ||
const message = messages[index] | ||
@@ -96,3 +108,7 @@ if (!options.silent || message.fatal) { | ||
fatal: message.fatal, | ||
stack: message.stack || null | ||
stack: message.stack || null, | ||
actual: message.actual || undefined, | ||
expected: message.expected || undefined, | ||
url: message.url || undefined, | ||
note: message.note || undefined | ||
}) | ||
@@ -99,0 +115,0 @@ } |
{ | ||
"name": "vfile-reporter-json", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"description": "vfile utility to create a JSON report for a file", | ||
@@ -46,4 +46,4 @@ "license": "MIT", | ||
"prettier": "^2.0.0", | ||
"remark-cli": "^9.0.0", | ||
"remark-preset-wooorm": "^8.0.0", | ||
"remark-cli": "^11.0.0", | ||
"remark-preset-wooorm": "^9.0.0", | ||
"rimraf": "^3.0.0", | ||
@@ -53,3 +53,3 @@ "tape": "^5.0.0", | ||
"typescript": "^4.0.0", | ||
"xo": "^0.39.0" | ||
"xo": "^0.52.0" | ||
}, | ||
@@ -73,7 +73,3 @@ "scripts": { | ||
"xo": { | ||
"prettier": true, | ||
"rules": { | ||
"no-var": "off", | ||
"prefer-arrow-callback": "off" | ||
} | ||
"prettier": true | ||
}, | ||
@@ -80,0 +76,0 @@ "remarkConfig": { |
@@ -10,11 +10,32 @@ # vfile-reporter-json | ||
Format [`vfile`][vfile]s as **stringified** JSON. | ||
[vfile][] utility to create a report in machine readable JSON. | ||
## Contents | ||
* [What is this?](#what-is-this) | ||
* [When should I use this?](#when-should-i-use-this) | ||
* [Install](#install) | ||
* [Use](#use) | ||
* [API](#api) | ||
* [`reporter(files[, options])`](#reporterfiles-options) | ||
* [Types](#types) | ||
* [Compatibility](#compatibility) | ||
* [Contribute](#contribute) | ||
* [License](#license) | ||
## What is this? | ||
This package is like [`vfile-reporter`][vfile-reporter] but it outputs machine | ||
readable JSON. | ||
## When should I use this? | ||
You can use this when you need to serialize lint results for machines, use | ||
`vfile-reporter` itself for humans. | ||
## Install | ||
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. | ||
This package is [ESM only][esm]. | ||
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]: | ||
[npm][]: | ||
```sh | ||
@@ -24,2 +45,16 @@ npm install vfile-reporter-json | ||
In Deno with [`esm.sh`][esmsh]: | ||
```js | ||
import {reporterJson} from 'https://esm.sh/vfile-reporter-json@3' | ||
``` | ||
In browsers with [`esm.sh`][esmsh]: | ||
```html | ||
<script type="module"> | ||
import {reporterJson} from 'https://esm.sh/vfile-reporter-json@3?bundle' | ||
</script> | ||
``` | ||
## Use | ||
@@ -31,4 +66,4 @@ | ||
var one = new VFile({path: 'test/fixture/1.js'}) | ||
var two = new VFile({path: 'test/fixture/2.js'}) | ||
const one = new VFile({path: 'test/fixture/1.js'}) | ||
const two = new VFile({path: 'test/fixture/2.js'}) | ||
@@ -48,3 +83,3 @@ one.message('Warning!', {line: 2, column: 4}) | ||
This package exports the following identifiers: `reporterJson`. | ||
This package exports the identifier `reporterJson`. | ||
That identifier is also the default export. | ||
@@ -74,2 +109,14 @@ | ||
## Types | ||
This package is fully typed with [TypeScript][]. | ||
It exports the additional type `Options`. | ||
## Compatibility | ||
Projects maintained by the unified collective are compatible with all maintained | ||
versions of Node.js. | ||
As of now, that is Node.js 12.20+, 14.14+, 16.0+, and 18.0+. | ||
Our projects sometimes work with older versions, but this is not guaranteed. | ||
## Contribute | ||
@@ -115,9 +162,15 @@ | ||
[contributing]: https://github.com/vfile/.github/blob/HEAD/contributing.md | ||
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c | ||
[support]: https://github.com/vfile/.github/blob/HEAD/support.md | ||
[esmsh]: https://esm.sh | ||
[typescript]: https://www.typescriptlang.org | ||
[contributing]: https://github.com/vfile/.github/blob/main/contributing.md | ||
[support]: https://github.com/vfile/.github/blob/main/support.md | ||
[health]: https://github.com/vfile/.github | ||
[coc]: https://github.com/vfile/.github/blob/HEAD/code-of-conduct.md | ||
[coc]: https://github.com/vfile/.github/blob/main/code-of-conduct.md | ||
@@ -130,2 +183,4 @@ [license]: license | ||
[vfile-reporter]: https://github.com/vfile/vfile-reporter | ||
[json-stringify]: https://developer.mozilla.org/JavaScript/Reference/Global_Objects/JSON/stringify |
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
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
13364
195
180