vfile utility to create a JSON report for a file
npm install vfile-reporter-json[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
[![Sponsors][sponsors-badge]][collective]
[![Backers][backers-badge]][collective]
[![Chat][chat-badge]][chat]
[vfile][] utility to create a report in machine readable JSON.
* What is this?
* When should I use this?
* Install
* Use
* API
* [reporterJson(files[, options])](#reporterjsonfiles-options)
* JsonFile
* JsonMessage
* Options
* Types
* Compatibility
* Contribute
* License
This package is like [vfile-reporter][vfile-reporter] but it outputs machine
readable JSON.
You can use this when you need to serialize lint results for machines, usevfile-reporter itself for humans.
This package is [ESM only][esm].
In Node.js (version 16+), install with [npm][]:
``sh`
npm install vfile-reporter-json
In Deno with [esm.sh][esmsh]:
`js`
import {reporterJson} from 'https://esm.sh/vfile-reporter-json@4'
In browsers with [esm.sh][esmsh]:
`html`
`js
import {VFile} from 'vfile'
import {reporterJson} from 'vfile-reporter-json'
const one = new VFile({path: 'test/fixture/1.js'})
const two = new VFile({path: 'test/fixture/2.js'})
one.message('Warning!', {line: 2, column: 4})
console.log(reporterJson([one, two]))
`
Yields:
`json`
[{"path":"test/fixture/1.js","cwd":"/Users/tilde/Projects/oss/vfile-reporter-json","history":["test/fixture/1.js"],"messages":[{"column":4,"fatal":false,"line":2,"place":{"line":2,"column":4},"reason":"Warning!"}]},{"path":"test/fixture/2.js","cwd":"/Users/tilde/Projects/oss/vfile-reporter-json","history":["test/fixture/2.js"],"messages":[]}]
This package exports the identifier [reporterJson][api-reporter-json].
That identifier is also the default export.
Create a serialized JSON report from one file or multiple files.
###### Parameters
* files ([Array][vfile] or VFile)options
— file or files to report
* ([Options][api-options], default: {})
— configuration
###### Returns
Report as serialized JSON (string).
Reporters must return strings, which is why serialized JSON is exposed.
You can parse the result with JSON.parse, in which case you will getArray
[][api-json-file].
JSON file (TypeScript type).
###### Fields
* cwd (string)path
— base of history
* (Array)messages
— list of filepaths the file moved between; the first is the original path
and the last is the current path
* ([Array][api-json-message])path
— list of filepaths the file moved between; the first is the original path
and the last is the current path
* (string)'~/index.min.js'
— full path (example: )
JSON message (TypeScript type).
###### Fields
* ancestors ([Array][unist-node] or undefined)column
— stack of ancestor nodes surrounding the message
* (number or undefined)fatal
— starting column of message
* (boolean or undefined)true
— state of problem; : error, file not usable; false: warning,undefined
change may be needed; : change likely not neededline
* (number or undefined)place
— starting line of message
* ([Point][unist-point], [Position][unist-position], orundefined
)reason
— place of message
* (string)ruleId
— reason for message, should use markdown
* (string | null)'my-rule'
— category of message (example: )source
* (string | null)'my-package'
— namespace of message (example: )actual
* (string | null | undefined)expected
— specify the source value that’s being reported, which is deemed incorrect
* (Array)actual
— suggest acceptable values that can be used instead of note
* (string | null | undefined)url
— long form description of the message, should use markdown
* (string | null | undefined)x
— link to docs for the message; this must be an absolute URL that can be
passed as to new URL(x)
Configuration (TypeScript type).
###### Fields
* pretty (boolean, number, or string, default: 0)space
— value of ofJSON.stringify(x, undefined, space)
[][json-stringify]quiet
* (boolean, default: false)silent
— do not show files without messages
* (boolean, default: false)quiet
— show errors only; this does not show info and warning messages; also sets
to true
This package is fully typed with [TypeScript][].
It exports the additional types [JsonFile][api-json-file],JsonMessage
[][api-json-message], and [Options][api-options].
Projects maintained by the unified collective are compatible with maintained
versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line, vfile-reporter-json@^4,
compatible with Node.js 16.
See [contributing.md][contributing] in [vfile/.github][health] for ways tosupport.md`][support] for ways to get help.
get started.
See [
This project has a [code of conduct][coc].
By interacting with this repository, organization, or community you agree to
abide by its terms.
[MIT][license] © [Titus Wormer][author]
[build-badge]: https://github.com/vfile/vfile-reporter-json/workflows/main/badge.svg
[build]: https://github.com/vfile/vfile-reporter-json/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/vfile/vfile-reporter-json.svg
[coverage]: https://codecov.io/github/vfile/vfile-reporter-json
[downloads-badge]: https://img.shields.io/npm/dm/vfile-reporter-json.svg
[downloads]: https://www.npmjs.com/package/vfile-reporter-json
[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=vfile-reporter-json
[size]: https://bundlejs.com/?q=vfile-reporter-json
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[collective]: https://opencollective.com/unified
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/vfile/vfile/discussions
[npm]: https://docs.npmjs.com/cli/install
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[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/main/code-of-conduct.md
[license]: license
[author]: https://wooorm.com
[unist-node]: https://github.com/syntax-tree/unist#node
[unist-point]: https://github.com/syntax-tree/unist#point
[unist-position]: https://github.com/syntax-tree/unist#position
[vfile]: https://github.com/vfile/vfile
[vfile-reporter]: https://github.com/vfile/vfile-reporter
[json-stringify]: https://developer.mozilla.org/JavaScript/Reference/Global_Objects/JSON/stringify
[api-reporter-json]: #reporterjsonfiles-options
[api-json-file]: #jsonfile
[api-json-message]: #jsonmessage
[api-options]: #options