Code Monkey home page Code Monkey logo

vfile-reporter-json's Introduction

vfile-reporter-json

Build Coverage Downloads Size Sponsors Backers Chat

vfile utility to create a report in machine readable JSON.

Contents

What is this?

This package is like 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. In Node.js (version 16+), install with npm:

npm install vfile-reporter-json

In Deno with esm.sh:

import {reporterJson} from 'https://esm.sh/vfile-reporter-json@4'

In browsers with esm.sh:

<script type="module">
  import {reporterJson} from 'https://esm.sh/vfile-reporter-json@4?bundle'
</script>

Use

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:

[{"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":[]}]

API

This package exports the identifier reporterJson. That identifier is also the default export.

reporterJson(files[, options])

Create a serialized JSON report from one file or multiple files.

Parameters
  • files (Array<VFile> or VFile) — file or files to report
  • options (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 get Array<JsonFile>.

JsonFile

JSON file (TypeScript type).

Fields
  • cwd (string) — base of path
  • history (Array<string>) — list of filepaths the file moved between; the first is the original path and the last is the current path
  • messages (Array<JsonMessage>) — list of filepaths the file moved between; the first is the original path and the last is the current path
  • path (string) — full path (example: '~/index.min.js')

JsonMessage

JSON message (TypeScript type).

Fields
  • ancestors (Array<Node> or undefined) — stack of ancestor nodes surrounding the message
  • column (number or undefined) — starting column of message
  • fatal (boolean or undefined) — state of problem; true: error, file not usable; false: warning, change may be needed; undefined: change likely not needed
  • line (number or undefined) — starting line of message
  • place (Point, Position, or undefined) — place of message
  • reason (string) — reason for message, should use markdown
  • ruleId (string | null) — category of message (example: 'my-rule')
  • source (string | null) — namespace of message (example: 'my-package')
  • actual (string | null | undefined) — specify the source value that’s being reported, which is deemed incorrect
  • expected (Array<string> | null | undefined) — suggest acceptable values that can be used instead of actual
  • note (string | null | undefined) — long form description of the message, should use markdown
  • url (string | null | undefined) — link to docs for the message; this must be an absolute URL that can be passed as x to new URL(x)

Options

Configuration (TypeScript type).

Fields
  • pretty (boolean, number, or string, default: 0) — value of space of JSON.stringify(x, undefined, space)
  • quiet (boolean, default: false) — do not show files without messages
  • silent (boolean, default: false) — show errors only; this does not show info and warning messages; also sets quiet to true

Types

This package is fully typed with TypeScript. It exports the additional types JsonFile, JsonMessage, and Options.

Compatibility

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.

Contribute

See contributing.md in vfile/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer

vfile-reporter-json's People

Contributors

christianmurphy avatar greenkeeperio-bot avatar wooorm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

vfile-reporter-json's Issues

Publish to npm

It doesn't look like this package has been published to npm! Install fails and it doesn't show up in search results... You maintain lots of modules, maybe you forgot to hit npm publish on this one 😉

npm install vfile-reporter-json
npm ERR! Darwin 16.4.0
npm ERR! argv "/Users/sam/.nvm/versions/node/v7.9.0/bin/node" "/Users/sam/.nvm/versions/node/v7.9.0/bin/npm" "install" "vfile-reporter-json"
npm ERR! node v7.9.0
npm ERR! npm  v4.2.0
npm ERR! code E404

npm ERR! 404 Registry returned 404 for GET on https://registry.npmjs.com/vfile-reporter-json
npm ERR! 404 
npm ERR! 404  'vfile-reporter-json' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404 
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

Include well-known fields such as "actual" and "url" field in JSON reporter output

Initial checklist

Problem

Currently the reporter can output VFileMessage objects in JSON format. However, this does not include some of the well known fields, such as "actual" and "url" fields.

ref: https://github.com/vfile/vfile-message#well-known-fields

Solution

Where the additional well known fields exist can these be reported as well.

Alternatives

Create a fork of this repository to add in the additional fields in the output

Error: Could not find reporter `vfile-reporter-json`

Initial checklist

Affected packages and versions

I want to use remark-cli version 9.0.0 with vfile-reporter-json.

Link to runnable example

https://github.com/dev-yakuza/vfile-error

Steps to reproduce

git clone https://github.com/dev-yakuza/vfile-error.git
npm install
npm start

You can get an error like the below.

> remark --report vfile-reporter-json --no-color --no-stdout ./success

Error: Could not find reporter `vfile-reporter-json`
    at log (/vfile/node_modules/unified-args/node_modules/unified-engine/lib/file-set-pipeline/log.js:16:12)
    at wrapped (/vfile/node_modules/unified-args/node_modules/trough/wrap.js:25:19)
    at next (/vfile/node_modules/unified-args/node_modules/trough/index.js:57:24)
    at FileSet.done (/vfile/node_modules/unified-args/node_modules/trough/wrap.js:55:16)
    at FileSet.emit (events.js:400:28)
    at FileSet.one (/vfile/node_modules/unified-args/node_modules/unified-engine/lib/file-set.js:108:10)
    at FileSet.emit (events.js:400:28)
    at done (/vfile/node_modules/unified-args/node_modules/unified-engine/lib/file-set-pipeline/transform.js:54:15)
    at next (/vfile/node_modules/unified-args/node_modules/trough/index.js:59:14)
    at done (/vfile/node_modules/unified-args/node_modules/trough/wrap.js:55:16)

If I use the remark-cli version 10.0.0, the problem is gone.

Expected behavior

I just want to get the result like the below.

[{"path":"success/docs/gfm.md","cwd":"/vfile","history":["success/docs/gfm.md"],"messages":[]},{"path":"success/docs/zzz.markdown","cwd":"/vfile","history":["success/docs/zzz.markdown"],"messages":[]},{"path":"success/readme.md","cwd":"/vfile","history":["success/readme.md"],"messages":[]}]

Actual behavior

remark --report vfile-reporter-json --no-color --no-stdout ./success

Error: Could not find reporter vfile-reporter-json
at log (/vfile/node_modules/unified-args/node_modules/unified-engine/lib/file-set-pipeline/log.js:16:12)
at wrapped (/vfile/node_modules/unified-args/node_modules/trough/wrap.js:25:19)
at next (/vfile/node_modules/unified-args/node_modules/trough/index.js:57:24)
at FileSet.done (/vfile/node_modules/unified-args/node_modules/trough/wrap.js:55:16)
at FileSet.emit (events.js:400:28)
at FileSet.one (/vfile/node_modules/unified-args/node_modules/unified-engine/lib/file-set.js:108:10)
at FileSet.emit (events.js:400:28)
at done (/vfile/node_modules/unified-args/node_modules/unified-engine/lib/file-set-pipeline/transform.js:54:15)
at next (/vfile/node_modules/unified-args/node_modules/trough/index.js:59:14)
at done (/vfile/node_modules/unified-args/node_modules/trough/wrap.js:55:16)

Runtime

Node v14

Package manager

npm v7

OS

macOS

Build and bundle tools

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.