git.iko.soy/typeable/remark-validate-links
on main help sign in
48 lines 1.0 kB history raw
1'use strict'
3var xtend = require('xtend')
4var check = require('./check')
5var find = require('./find')
6var constants = require('./constants')
8module.exports = validateLinks
10cliCompleter.pluginId = constants.sourceId
12function validateLinks(options, fileSet) {
13 var settings = options || {}
15 // Attach a `completer`.
16 if (fileSet) {
17 fileSet.use(cliCompleter)
18 }
20 return transformer
22 // Find references and landmarks.
23 function transformer(tree, file, next) {
24 find.run(xtend(settings, {tree: tree, file: file, fileSet: fileSet}), done)
26 function done(err) {
27 if (err) {
28 next(err)
29 } else if (fileSet) {
30 next()
31 } else {
32 checkAll([file], next)
33 }
34 }
35 }
38// Completer for the CLI (multiple files, supports parsing more files).
39function cliCompleter(set, next) {
40 checkAll(set.valueOf(), next)
43function checkAll(files, next) {
44 // Check all references and landmarks.
45 check.run({files: files}, function (err) {
46 next(err)
47 })