VFile Message Statistics Utility

3.0.0 · active · verified Sun Apr 19

vfile-statistics is a lightweight utility within the unified ecosystem designed to categorize and count messages associated with `vfile` instances. It provides statistics such as the total number of messages, as well as counts for fatal errors, warnings, and informational messages. The current stable version is 3.0.0, which notably requires Node.js 16 or higher and is an ESM-only package. This library follows the release cadence of the broader unified collective, tying major version bumps to Node.js LTS updates and significant changes in its peer dependencies like `vfile`. Its key differentiator is its focused simplicity, serving as a composable building block for tools processing virtual files, rather than a standalone, opinionated linter or parser.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import `statistics` and `VFile`, add different message types to a vfile, and then compute and log the message statistics.

import { VFile } from 'vfile'
import { statistics } from 'vfile-statistics'

// Create a new VFile instance
const file = new VFile({path: '~/example.md', value: '# Hello'}) 

// Add various types of messages to the file
file.message('This observation could be improved', { ruleId: 'style-guide' })
file.message('Another styling suggestion', { line: 1, column: 3 })

// Simulate a fatal error that might be caught or thrown
try {
  file.fail('Critical parsing error found', { ruleId: 'parser-error', fatal: true })
} catch (error) {
  // In a real application, you might handle the error here
  console.error('Caught a vfile.fail error:', error.message)
}

file.info('Metadata: author is John Doe', { ruleId: 'meta-data' })

// Get and log the statistics
const stats = statistics(file)
console.log('File statistics:', stats)

/* Expected Output:
File statistics: { fatal: 1, nonfatal: 3, warn: 2, info: 1, total: 4 }
*/

view raw JSON →