Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: vfile/vfile-reporter
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a893c994f6e2092c4867bd3940e092eccce99386
Choose a base ref
...
head repository: vfile/vfile-reporter
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 36b98284e20615e9aaa862be10d105175cfa64bb
Choose a head ref
  • 17 commits
  • 9 files changed
  • 2 contributors

Commits on Mar 2, 2022

  1. Unverified

    This user has not yet uploaded their public signing key.
    Copy the full SHA
    78eb0d6 View commit details

Commits on Mar 25, 2022

  1. Update dev-dependencies

    wooorm committed Mar 25, 2022
    Copy the full SHA
    c4a3d10 View commit details
  2. Add improved docs

    wooorm committed Mar 25, 2022
    Copy the full SHA
    cdec694 View commit details
  3. Copy the full SHA
    fc0232f View commit details
  4. Add note on figures

    wooorm committed Mar 25, 2022
    Copy the full SHA
    2618f3f View commit details
  5. 7.0.4

    wooorm committed Mar 25, 2022
    Copy the full SHA
    e66798e View commit details

Commits on Jun 11, 2022

  1. Update dev-dependencies

    wooorm committed Jun 11, 2022
    Copy the full SHA
    e835acf View commit details
  2. Copy the full SHA
    07992e1 View commit details

Commits on Feb 4, 2023

  1. Update dev-dependencies

    wooorm committed Feb 4, 2023
    Copy the full SHA
    6e359a4 View commit details
  2. Remove dev-dependency

    wooorm committed Feb 4, 2023
    Copy the full SHA
    cf69df7 View commit details
  3. Update Actions

    wooorm committed Feb 4, 2023
    Copy the full SHA
    bf01ee3 View commit details
  4. Update tsconfig.json

    wooorm committed Feb 4, 2023
    Copy the full SHA
    6bbf985 View commit details
  5. Refactor code-style

    *   Add more docs to JSDoc
    *   Add support for `null` in input of API types
    wooorm committed Feb 4, 2023
    Copy the full SHA
    446e58b View commit details
  6. Use Node test runner

    wooorm committed Feb 4, 2023
    Copy the full SHA
    922b40a View commit details
  7. Copy the full SHA
    3ed70ba View commit details
  8. Add improved docs

    wooorm committed Feb 4, 2023
    Copy the full SHA
    06ce625 View commit details
  9. 7.0.5

    wooorm committed Feb 4, 2023
    Copy the full SHA
    36b9828 View commit details
Showing with 289 additions and 172 deletions.
  1. +4 −4 .github/workflows/main.yml
  2. +1 −0 .npmrc
  3. +74 −30 lib/index.js
  4. +1 −0 lib/platform.browser.js
  5. +3 −0 lib/platform.js
  6. +12 −16 package.json
  7. +113 −49 readme.md
  8. +72 −65 test.js
  9. +9 −8 tsconfig.json
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -7,18 +7,18 @@ jobs:
name: '${{matrix.node}} on ${{matrix.os}}'
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- uses: dcodeIO/setup-node-nvm@master
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{matrix.node}}
- run: npm install
- run: npm test
- uses: codecov/codecov-action@v1
- uses: codecov/codecov-action@v3
strategy:
matrix:
os:
- ubuntu-latest
- windows-latest
node:
- lts/erbium
- lts/gallium
- node
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
package-lock=false
ignore-scripts=true
104 changes: 74 additions & 30 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -2,48 +2,79 @@
* @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
* Configuration (optional).
* @property {boolean | null | undefined} [color]
* Use ANSI colors in report.
* The default behavior in Node.js is the check if color is supported.
* @property {boolean | null | undefined} [verbose=false]
* Show message `note`s.
* Notes are optional, additional, long descriptions.
* @property {boolean | null | undefined} [quiet=false]
* Do not show files without messages.
* @property {boolean | null | undefined} [silent=false]
* Show errors only, this hides info and warning messages, and sets
* `quiet: true`.
* @property {string | null | undefined} [defaultName='<stdin>']
* Label to use for files without file path.
* If one file and no `defaultName` is given, no name will show up in the
* report.
*/

/**
* @typedef MessageRow
* Message.
* @property {string} place
* Serialized positional info.
* @property {string} label
* Kind of message.
* @property {string} reason
* Reason.
* @property {string} ruleId
* Rule.
* @property {string} source
* Source.
*
* @typedef {keyof MessageRow} MessageColumn
*
* @typedef FileRow
* File header row.
* @property {'file'} type
* Kind.
* @property {VFile} file
* Virtual file.
* @property {Statistics} stats
* Statistics.
*
* @typedef {{[x: string]: number}} Sizes
* @typedef {Record<MessageColumn, number>} Sizes
* Sizes for message columns.
*
* @typedef Info
* @property {Array<FileRow|Row>} rows
* Result.
* @property {Array<FileRow | MessageRow>} rows
* Rows.
* @property {Statistics} stats
* Total statistics.
* @property {Sizes} sizes
* Sizes for message columns.
*/

import width from 'string-width'
import {stringifyPosition} from 'unist-util-stringify-position'
import {statistics} from 'vfile-statistics'
import {sort} from 'vfile-sort'
import {color} from './color.js'
import {platform} from './platform.js'

const own = {}.hasOwnProperty

// `log-symbols` without chalk, ignored for Windows:
/* c8 ignore next 4 */
const chars =
process.platform === 'win32'
? {error: '×', warning: '‼'}
: {error: '✖', warning: '⚠'}
platform === 'win32' ? {error: '×', warning: '‼'} : {error: '✖', warning: '⚠'}

const labels = {
true: 'error',
@@ -53,16 +84,16 @@ const labels = {
}

/**
* Report a file’s messages.
* Create a report from an error, one file, or multiple files.
*
* @param {Error|VFile|Array<VFile>} [files]
* @param {Options} [options]
* @param {Error | VFile | Array<VFile> | null | undefined} [files]
* Files or error to report.
* @param {Options | null | undefined} [options]
* Configuration.
* @returns {string}
* Report.
*/
export function reporter(files, options = {}) {
/** @type {boolean|undefined} */
let one

export function reporter(files, options) {
if (!files) {
return ''
}
@@ -72,33 +103,39 @@ export function reporter(files, options = {}) {
return String(files.stack || files)
}

const options_ = options || {}

// One file.
if (!Array.isArray(files)) {
one = true
files = [files]
if (Array.isArray(files)) {
return format(transform(files, options_), false, options_)
}

return format(transform(files, options), one, options)
return format(transform([files], options_), true, options_)
}

/**
* Parse a list of messages.
*
* @param {Array<VFile>} files
* List of files.
* @param {Options} options
* Options.
* @returns {Info}
* Rows.
*/
function transform(files, options) {
/** @type {Array<FileRow|Row>} */
/** @type {Array<FileRow | MessageRow>} */
const rows = []
/** @type {Array<VFileMessage>} */
const all = []
/** @type {Sizes} */
const sizes = {}
const sizes = {place: 0, label: 0, reason: 0, ruleId: 0, source: 0}
let index = -1

while (++index < files.length) {
// @ts-expect-error it works fine.
const messages = sort({messages: [...files[index].messages]}).messages
/** @type {Array<Row>} */
/** @type {Array<MessageRow>} */
const messageRows = []
let offset = -1

@@ -124,7 +161,7 @@ function transform(files, options) {
source: message.source || ''
}

/** @type {keyof row} */
/** @type {MessageColumn} */
let key

for (key in row) {
@@ -151,8 +188,13 @@ function transform(files, options) {

/**
* @param {Info} map
* @param {boolean|undefined} one
* Rows.
* @param {boolean} one
* Whether the input was explicitly one file (not an array).
* @param {Options} options
* Configuration.
* @returns {string}
* Report.
*/
// eslint-disable-next-line complexity
function format(map, one, options) {
@@ -285,10 +327,12 @@ function format(map, one, options) {
}

/**
* Get the length of `value`, ignoring ANSI sequences.
* Get the length of the first line of `value`, ignoring ANSI sequences.
*
* @param {string} value
* Message.
* @returns {number}
* Width.
*/
function size(value) {
const match = /\r?\n|\r/.exec(value)
1 change: 1 addition & 0 deletions lib/platform.browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const platform = 'darwin'
3 changes: 3 additions & 0 deletions lib/platform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import process from 'node:process'

export const platform = process.platform
28 changes: 12 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vfile-reporter",
"version": "7.0.3",
"version": "7.0.5",
"description": "vfile utility to create a report for a file",
"license": "MIT",
"keywords": [
@@ -33,7 +33,8 @@
"type": "module",
"main": "index.js",
"browser": {
"./lib/color.js": "./lib/color.browser.js"
"./lib/color.js": "./lib/color.browser.js",
"./lib/platform.js": "./lib/platform.browser.js"
},
"types": "index.d.ts",
"files": [
@@ -46,31 +47,29 @@
"string-width": "^5.0.0",
"supports-color": "^9.0.0",
"unist-util-stringify-position": "^3.0.0",
"vfile": "^5.0.0",
"vfile-message": "^3.0.0",
"vfile-sort": "^3.0.0",
"vfile-statistics": "^2.0.0"
},
"devDependencies": {
"@types/tape": "^4.0.0",
"@types/node": "^18.0.0",
"c8": "^7.0.0",
"cross-env": "^7.0.0",
"figures": "^3.0.0",
"prettier": "^2.0.0",
"remark-cli": "^10.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"rimraf": "^3.0.0",
"strip-ansi": "^7.0.0",
"tape": "^5.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"vfile": "^5.0.0",
"xo": "^0.47.0"
"xo": "^0.53.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
"build": "rimraf \"lib/**/*.d.ts\" \"*.d.ts\" && tsc && type-coverage",
"build": "tsc --build --clean && tsc --build && type-coverage",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"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-api": "cross-env FORCE_COLOR=\"true\" node --conditions development test.js",
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
@@ -82,10 +81,7 @@
"trailingComma": "none"
},
"xo": {
"prettier": true,
"rules": {
"node/prefer-global/process": "off"
}
"prettier": true
},
"remarkConfig": {
"plugins": [
Loading