https://github.com/vweevers/vsource
Add messages to a vfile bound to a plugin source.
https://github.com/vweevers/vsource
javascript lint nodejs npm-package vfile
Last synced: about 1 month ago
JSON representation
Add messages to a vfile bound to a plugin source.
- Host: GitHub
- URL: https://github.com/vweevers/vsource
- Owner: vweevers
- License: mit
- Created: 2020-12-06T21:59:46.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2025-12-01T19:36:25.000Z (6 months ago)
- Last Synced: 2025-12-04T09:47:00.062Z (6 months ago)
- Topics: javascript, lint, nodejs, npm-package, vfile
- Language: JavaScript
- Homepage:
- Size: 12.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# vsource
**Add [messages](https://github.com/vfile/vfile-message) to a [vfile](https://github.com/vfile/vfile) bound to a plugin source.**
[](https://www.npmjs.org/package/vsource)
[](https://www.npmjs.org/package/vsource)

[](https://standardjs.com)
## Usage
```js
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:
```js
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()`](https://github.com/vfile/vfile#vfilefailreason-position-origin) which immediately terminates the process. I'm taking a slightly different approach to linting (than [`remark-lint`](https://github.com/remarkjs/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`](https://github.com/standard/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`](https://github.com/vfile/vfile-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](https://npmjs.org) do:
```
npm install vsource
```
## License
[MIT](LICENSE) © Vincent Weevers