vfile-reporter-json
Advanced tools
Comparing version 2.0.2 to 3.0.0
86
index.js
@@ -1,26 +0,57 @@ | ||
'use strict' | ||
/** | ||
* @typedef {import('vfile').VFile} VFile | ||
* @typedef {import('vfile-message').VFileMessage} VFileMessage | ||
* | ||
* @typedef Options | ||
* @property {number|string|boolean} [pretty=0] | ||
* @property {boolean} [quiet=false] | ||
* @property {boolean} [silent=false] | ||
* | ||
* @typedef _JsonMessage | ||
* @property {string} reason | ||
* @property {number} line | ||
* @property {number} column | ||
* @property {VFileMessage['position']} position | ||
* @property {string} ruleId | ||
* @property {string} source | ||
* @property {boolean} fatal | ||
* @property {string} stack | ||
* | ||
* @typedef _JsonFile | ||
* @property {string} path | ||
* @property {string} cwd | ||
* @property {Array.<string>} history | ||
* @property {Array.<_JsonMessage>} messages | ||
*/ | ||
module.exports = reporter | ||
/** | ||
* @param {Array.<VFile>|VFile} files | ||
* @param {Options} options | ||
* @returns {string} | ||
*/ | ||
export function reporterJson(files, options = {}) { | ||
var pretty = options.pretty || 0 | ||
var data = filesToJson(Array.isArray(files) ? files : [files], options) | ||
function reporter(files, options) { | ||
var settings = options || {} | ||
var pretty = settings.pretty || 0 | ||
var data = filesToJson('length' in files ? files : [files], settings) | ||
return JSON.stringify(data, null, pretty === true ? 2 : pretty) | ||
} | ||
/** | ||
* @param {Array.<VFile>} files | ||
* @param {Options} options | ||
* @returns {Array.<_JsonFile>} | ||
*/ | ||
function filesToJson(files, options) { | ||
var index = -1 | ||
/** @type {Array.<_JsonFile>} */ | ||
var result = [] | ||
/** @type {_JsonFile} */ | ||
var file | ||
while (++index < files.length) { | ||
file = files[index] | ||
file = { | ||
path: file.path, | ||
cwd: file.cwd, | ||
history: file.history, | ||
messages: messagesToJson(file.messages, options) | ||
path: files[index].path, | ||
cwd: files[index].cwd, | ||
history: files[index].history, | ||
messages: messagesToJson(files[index].messages, options) | ||
} | ||
@@ -36,5 +67,12 @@ | ||
/** | ||
* @param {Array.<VFileMessage>} messages | ||
* @param {Options} options | ||
* @returns {Array.<_JsonMessage>} | ||
*/ | ||
function messagesToJson(messages, options) { | ||
var index = -1 | ||
/** @type {Array.<_JsonMessage>} */ | ||
var result = [] | ||
/** @type {VFileMessage} */ | ||
var message | ||
@@ -45,15 +83,13 @@ | ||
message = { | ||
reason: message.reason, | ||
line: message.line, | ||
column: message.column, | ||
location: message.location, | ||
ruleId: message.ruleId || null, | ||
source: message.source || null, | ||
fatal: message.fatal, | ||
stack: message.stack || null | ||
} | ||
if (!options.silent || message.fatal) { | ||
result.push(message) | ||
result.push({ | ||
reason: message.reason, | ||
line: message.line, | ||
column: message.column, | ||
position: message.position, | ||
ruleId: message.ruleId || null, | ||
source: message.source || null, | ||
fatal: message.fatal, | ||
stack: message.stack || null | ||
}) | ||
} | ||
@@ -60,0 +96,0 @@ } |
{ | ||
"name": "vfile-reporter-json", | ||
"version": "2.0.2", | ||
"version": "3.0.0", | ||
"description": "vfile utility to create a JSON report for a file", | ||
@@ -30,32 +30,34 @@ "license": "MIT", | ||
], | ||
"sideEffects": false, | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.d.ts", | ||
"index.js" | ||
], | ||
"dependencies": {}, | ||
"dependencies": { | ||
"vfile": "^5.0.0", | ||
"vfile-message": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"browserify": "^17.0.0", | ||
"nyc": "^15.0.0", | ||
"@types/tape": "^4.0.0", | ||
"c8": "^7.0.0", | ||
"prettier": "^2.0.0", | ||
"remark-cli": "^9.0.0", | ||
"remark-preset-wooorm": "^8.0.0", | ||
"rimraf": "^3.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", | ||
"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 . -s vfileReporterJson -o vfile-reporter-json.js", | ||
"build-mangle": "browserify . -s vfileReporterJson -o vfile-reporter-json.min.js -p tinyify", | ||
"build": "npm run build-bundle && npm run build-mangle", | ||
"test-api": "node test", | ||
"test-coverage": "nyc --reporter lcov tape test.js", | ||
"test": "npm run format && npm run build && npm run test-coverage" | ||
"test-api": "node test.js", | ||
"test-coverage": "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" | ||
}, | ||
"nyc": { | ||
"check-coverage": true, | ||
"lines": 100, | ||
"functions": 100, | ||
"branches": 100 | ||
}, | ||
"prettier": { | ||
@@ -71,9 +73,6 @@ "tabWidth": 2, | ||
"prettier": true, | ||
"esnext": false, | ||
"rules": { | ||
"unicorn/prefer-optional-catch-binding": "off" | ||
}, | ||
"ignores": [ | ||
"vfile-reporter-json.js" | ||
] | ||
"no-var": "off", | ||
"prefer-arrow-callback": "off" | ||
} | ||
}, | ||
@@ -84,3 +83,8 @@ "remarkConfig": { | ||
] | ||
}, | ||
"typeCoverage": { | ||
"atLeast": 100, | ||
"detail": true, | ||
"strict": true | ||
} | ||
} |
@@ -14,2 +14,5 @@ # vfile-reporter-json | ||
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][]: | ||
@@ -24,11 +27,11 @@ | ||
```js | ||
var vfile = require('vfile') | ||
var reporter = require('vfile-reporter-json') | ||
import {VFile} from 'vfile' | ||
import {reporterJson} from 'vfile-reporter-json' | ||
var one = vfile({path: 'test/fixture/1.js'}) | ||
var two = vfile({path: 'test/fixture/2.js'}) | ||
var one = new VFile({path: 'test/fixture/1.js'}) | ||
var two = new VFile({path: 'test/fixture/2.js'}) | ||
one.message('Warning!', {line: 2, column: 4}) | ||
console.log(reporter([one, two])) | ||
console.log(reporterJson([one, two])) | ||
``` | ||
@@ -39,3 +42,3 @@ | ||
```json | ||
[{"path":"test/fixture/1.js","cwd":"/Users/tilde/projects/oss/vfile-reporter-json","history":["test/fixture/1.js"],"messages":[{"reason":"Warning!","line":2,"column":4,"location":{"start":{"line":2,"column":4},"end":{"line":null,"column":null}},"ruleId":null,"source":null,"fatal":false,"stack":null}]},{"path":"test/fixture/2.js","cwd":"/Users/tilde/projects/oss/vfile-reporter-json","history":["test/fixture/2.js"],"messages":[]}] | ||
[{"path":"test/fixture/1.js","cwd":"/Users/tilde/projects/oss/vfile-reporter-json","history":["test/fixture/1.js"],"messages":[{"reason":"Warning!","line":2,"column":4,"position":{"start":{"line":2,"column":4},"end":{"line":null,"column":null}},"ruleId":null,"source":null,"fatal":false,"stack":null}]},{"path":"test/fixture/2.js","cwd":"/Users/tilde/projects/oss/vfile-reporter-json","history":["test/fixture/2.js"],"messages":[]}] | ||
``` | ||
@@ -45,2 +48,5 @@ | ||
This package exports the following identifiers: `reporterJson`. | ||
There is no default export. | ||
### `reporter(files[, options])` | ||
@@ -47,0 +53,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
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
10524
5
144
125
Yes
2
10
+ Addedvfile@^5.0.0
+ Addedvfile-message@^3.0.0
+ Added@types/unist@2.0.11(transitive)
+ Addedis-buffer@2.0.5(transitive)
+ Addedunist-util-stringify-position@3.0.3(transitive)
+ Addedvfile@5.3.7(transitive)
+ Addedvfile-message@3.1.4(transitive)