vsource

Add messages to a vfile bound to a plugin source

Usage no npm install needed!

<script type="module">
  import vsource from 'https://cdn.skypack.dev/vsource';
</script>

README

vsource

Add messages to a vfile bound to a plugin source.

npm status node Test JavaScript Style Guide

Usage

const vsource = require('vsource')
const vfile = require('vfile')

const file = vfile({ path: 'package.json' })
const s = vsource('my-lint-plugin', file)

// Add error message to file
s.fail('Name must be lowercase', pos, 'lowercase-name')

Which is just a convenient shortcut for:

file.fail('Name must be lowercase', pos, 'my-lint-plugin:lowercase-name')

In addition, fail() can be called multiple times to collect more than one error, unlike VFile#fail() which immediately terminates the process. I'm taking a slightly different approach to linting (than remark-lint et al): both error and warning messages are lint failures, but warnings can be ignored by the user. This behavior is closer to the standard linter. While remark-lint normally only produces warning messages, reserving error messages for unexpected exceptions.

API

s = vsource(source[, file])

If a file argument is provided, it does not have to be passed into the below methods.

message = s.fail([file, ]reason, position, ruleId)

Add error message to file, similar to VFile#fail(). Sets message.fatal to true.

message = s.warn([file, ]reason, position, ruleId)

Add warning message to file, same as VFile#message(). Sets message.fatal to false.

message = s.info([file, ]reason, position, ruleId)

Add info message to file, same as VFile#info(). Sets message.fatal to null.

Install

With npm do:

npm install vsource

License

MIT © Vincent Weevers