git.iko.soy/typeable/remark-validate-links
on main help sign in
43 files changed+2264−945
since splitsnapshots
unifiedsplit
.prettierignore+2 .travis.yml+2−2 index.js+1−419 lib/check/check-files.browser.js+7 lib/check/check-files.js+42 lib/check/index.js+13 lib/check/merge-landmarks.js+29 lib/check/merge-references.js+42 lib/check/validate.js+108 lib/constants.js+8 lib/find/config.js+54 lib/find/find-repo.browser.js+7 lib/find/find-repo.js+76 lib/find/find.js+296 lib/find/index.js+8 lib/index.js+48 package.json+47−28 readme.md+140−52 test/fixtures/bitbucket.md+9−5 test/fixtures/case-insensitive-headings.md+9 test/fixtures/empty.md+1 test/fixtures/examples/bitbucket.md+5−5 test/fixtures/examples/github.md+5−5 test/fixtures/examples/gitlab.md+5−5 test/fixtures/examples/weird#character/readme.md+1 test/fixtures/examples/weird#characters.md+1 test/fixtures/external.md+11 test/fixtures/file-as-folder.md+1 test/fixtures/folder-without-readme/example.md+1 test/fixtures/folder.md+23 test/fixtures/folder/example.md+1 test/fixtures/folder/readme.asc+9 test/fixtures/folder/readme.markdown+5 test/fixtures/folder/readme.md+1 test/fixtures/github.md+13−5 test/fixtures/gitlab.md+9−5 test/fixtures/images.md+4−4 test/fixtures/line-links.md+2−2 test/fixtures/query-params.md+9 test/fixtures/self-hosted.md+5 test/fixtures/small.md+5 test/fixtures/weird-characters.md+17 test/index.js+1182−408
.prettierignore+2
@@ -1 +1,3 @@
11coverage/
2+*.json
3+*.md
.travis.yml+2−2
@@ -1,5 +1,5 @@
11language: node_js
22node_js:
3−- lts/boron
4−- node
3+ - lts/dubnium
4+ - node
55after_success: bash <(curl -s https://codecov.io/bash)
index.js+1−419
@@ -1,421 +1,3 @@
11'use strict'
22
3−var url = require('url')
4−var propose = require('propose')
5−var visit = require('unist-util-visit')
6−var definitions = require('mdast-util-definitions')
7−var toString = require('mdast-util-to-string')
8−var hostedGitInfo = require('hosted-git-info')
9−var urljoin = require('urljoin')
10−var slugs = require('github-slugger')()
11−var xtend = require('xtend/mutable.js')
12−
13−// Optional Node dependencies.
14−var fs
15−var path
16−
17−try {
18− fs = require('fs')
19− path = require('path')
20−} catch (error) {}
21−
22−module.exports = validateLinks
23−
24−var referenceId = 'remarkValidateLinksReferences'
25−var landmarkId = 'remarkValidateLinksLandmarks'
26−var sourceId = 'remark-validate-links'
27−var headingRuleId = 'missing-heading'
28−var headingInFileRuleId = 'missing-heading-in-file'
29−var fileRuleId = 'missing-file'
30−
31−cliCompleter.pluginId = sourceId
32−
33−var parse = url.parse
34−
35−var viewPaths = {
36− github: 'blob',
37− gitlab: 'blob',
38− bitbucket: 'src'
39−}
40−
41−var headingPrefixes = {
42− github: '#',
43− gitlab: '#',
44− bitbucket: '#markdown-header-'
45−}
46−
47−var lineLinks = {
48− github: true,
49− gitlab: true
50−}
51−
52−var lineExpression = /^#?l\d/i
53−
54−function validateLinks(options, fileSet) {
55− var repo = (options || {}).repository
56− var info
57− var pack
58−
59− // Try to get the repo from `package.json` when not given.
60− if (!repo && fs && fileSet) {
61− try {
62− pack = fileSet.files[0].cwd
63− pack = JSON.parse(fs.readFileSync(path.resolve(pack, 'package.json')))
64− } catch (error) {
65− pack = {}
66− }
67−
68− repo = pack.repository ? pack.repository.url || pack.repository : ''
69− }
70−
71− if (repo) {
72− info = hostedGitInfo.fromUrl(repo)
73−
74− if (!info) {
75− throw new Error(
76− 'remark-validate-links cannot parse `repository` (`' + repo + '`)'
77− )
78− } else if (info.domain === 'gist.github.com') {
79− throw new Error(
80− 'remark-validate-links does not support gist repositories'
81− )
82− }
83− }
84−
85− // Attach a plugin that adds our transformer after it.
86− this.use(subplugin)
87−
88− // Attach a `completer`.
89− if (fileSet) {
90− fileSet.use(cliCompleter)
91− } else {
92− this.use(apiCompleter)
93− }
94−
95− function subplugin() {
96− // Expose transformer.
97− return transformerFactory(fileSet, info)
98− }
99−}
100−
101−// Completer for the API (one file, only headings are checked).
102−function apiCompleter() {
103− return apiTransform
104−}
105−
106−function apiTransform(tree, file) {
107− checkFactory(file.data[landmarkId])(file)
108−}
109−
110−// Completer for the CLI (multiple files, and support to add more).
111−function cliCompleter(set, done) {
112− var exposed = {}
113−
114− set.valueOf().forEach(expose)
115− set.valueOf().forEach(checkFactory(exposed))
116−
117− done()
118−
119− function expose(file) {
120− var landmarks = file.data[landmarkId]
121−
122− if (landmarks) {
123− xtend(exposed, landmarks)
124− }
125− }
126−}
127−
128−function checkFactory(exposed) {
129− return check
130− function check(file) {
131− /* istanbul ignore else - stdin */
132− if (file.path) {
133− validate(exposed, file)
134− }
135− }
136−}
137−
138−// Factory to create a transformer based on the given info and set.
139−function transformerFactory(fileSet, info) {
140− return transformer
141−
142− // Transformer. Adds references files to the set.
143− function transformer(ast, file) {
144− var filePath = file.path
145− var space = file.data
146− var links = []
147− var landmarks = {}
148− var references
149− var current
150− var link
151− var pathname
152−
153− /* istanbul ignore if - stdin */
154− if (!filePath) {
155− return
156− }
157−
158− references = gatherReferences(file, ast, info, fileSet)
159− current = getPathname(filePath)
160−
161− for (link in references) {
162− pathname = getPathname(link)
163−
164− if (
165− fileSet &&
166− pathname !== current &&
167− getHash(link) &&
168− links.indexOf(pathname) === -1
169− ) {
170− links.push(pathname)
171− fileSet.add(pathname)
172− }
173− }
174−
175− landmarks[filePath] = true
176−
177− slugs.reset()
178−
179− visit(ast, mark)
180−
181− space[referenceId] = references
182− space[landmarkId] = landmarks
183−
184− function mark(node) {
185− var data = node.data || {}
186− var props = data.hProperties || {}
187− var id = props.name || props.id || data.id
188−
189− if (!id && node.type === 'heading') {
190− id = slugs.slug(toString(node))
191− }
192−
193− if (id) {
194− landmarks[filePath + '#' + id] = true
195− }
196− }
197− }
198−}
199−
200−// Check if `file` references headings or files not in `exposed`.
201−function validate(exposed, file) {
202− var references = file.data[referenceId]
203− var filePath = file.path
204− var reference
205− var nodes
206− var real
207− var hash
208− var pathname
209− var warning
210− var suggestion
211− var ruleId
212−
213− for (reference in references) {
214− nodes = references[reference]
215− real = exposed[reference]
216− hash = getHash(reference)
217−
218− // Check if files without `hash` can be linked to. Because there’s no need
219− // to inspect those files for headings they are not added to remark. This
220− // is especially useful because they might be non-markdown files. Here we
221− // check if they exist.
222− if ((real === undefined || real === null) && !hash && fs) {
223− real = fs.existsSync(path.join(file.cwd, decodeURI(reference)))
224− references[reference] = real
225− }
226−
227− if (!real) {
228− if (hash) {
229− pathname = getPathname(reference)
230− warning = 'Link to unknown heading'
231− ruleId = headingRuleId
232−
233− if (pathname !== filePath) {
234− warning += ' in `' + pathname + '`'
235− ruleId = headingInFileRuleId
236− }
237−
238− warning += ': `' + hash + '`'
239− } else {
240− warning = 'Link to unknown file: `' + decodeURI(reference) + '`'
241− ruleId = fileRuleId
242− }
243−
244− suggestion = getClosest(reference, exposed)
245−
246− if (suggestion) {
247− warning += '. Did you mean `' + suggestion + '`'
248− }
249−
250− warnAll(file, nodes, warning, ruleId)
251− }
252− }
253−}
254−
255−// Gather references: a map of file-paths references to be one or more nodes.
256−function gatherReferences(file, tree, info, fileSet) {
257− var cache = {}
258− var getDefinition = definitions(tree)
259− var prefix = ''
260− var headingPrefix = '#'
261− var lines
262−
263− if (info && info.type in viewPaths) {
264− prefix = '/' + info.path() + '/' + viewPaths[info.type] + '/'
265− }
266−
267− if (info && info.type in headingPrefixes) {
268− headingPrefix = headingPrefixes[info.type]
269− }
270−
271− lines = info && info.type in lineLinks ? lineLinks[info.type] : false
272−
273− visit(tree, ['link', 'image', 'linkReference', 'imageReference'], onresource)
274−
275− return cache
276−
277− // Handle resources.
278− function onresource(node) {
279− var link = node.url
280− var definition
281− var index
282− var uri
283− var pathname
284− var hash
285−
286− // Handle references.
287− if (node.identifier) {
288− definition = getDefinition(node.identifier)
289− link = definition && definition.url
290− }
291−
292− // Ignore definitions without url.
293− if (!link) {
294− return
295− }
296−
297− uri = parse(link)
298−
299− if (!fileSet && (uri.hostname || uri.pathname)) {
300− return
301− }
302−
303− if (!uri.hostname) {
304− if (lines && lineExpression.test(uri.hash)) {
305− uri.hash = ''
306− }
307−
308− // Handle hashes, or relative files.
309− if (!uri.pathname && uri.hash) {
310− link = file.path + uri.hash
311− uri = parse(link)
312− } else {
313− link = urljoin(file.dirname, link)
314−
315− if (uri.hash) {
316− link += uri.hash
317− }
318−
319− uri = parse(link)
320− }
321− }
322−
323− // Handle full links.
324− if (uri.hostname) {
325− if (!prefix || !fileSet) {
326− return
327− }
328−
329− if (
330− uri.hostname !== info.domain ||
331− uri.pathname.slice(0, prefix.length) !== prefix
332− ) {
333− return
334− }
335−
336− link = uri.pathname.slice(prefix.length) + (uri.hash || '')
337−
338− // Things get interesting here: branches: `foo/bar/baz` could be `baz` on
339− // the `foo/bar` branch, or, `baz` in the `bar` directory on the `foo`
340− // branch.
341− // Currently, we’re ignoring this and just not supporting branches.
342− link = link.slice(link.indexOf('/') + 1)
343− }
344−
345− // Handle file links, or combinations of files and hashes.
346− index = link.indexOf(headingPrefix)
347−
348− if (index === -1) {
349− pathname = link
350− hash = null
351− } else {
352− pathname = link.slice(0, index)
353− hash = link.slice(index + headingPrefix.length)
354−
355− if (lines && lineExpression.test(hash)) {
356− hash = null
357− }
358− }
359−
360− if (!cache[pathname]) {
361− cache[pathname] = []
362− }
363−
364− cache[pathname].push(node)
365−
366− if (hash) {
367− link = pathname + '#' + hash
368−
369− if (!cache[link]) {
370− cache[link] = []
371− }
372−
373− cache[link].push(node)
374− }
375− }
376−}
377−
378−// Utility to warn `reason` for each node in `nodes` on `file`.
379−function warnAll(file, nodes, reason, ruleId) {
380− nodes.forEach(one)
381−
382− function one(node) {
383− file.message(reason, node, [sourceId, ruleId].join(':'))
384− }
385−}
386−
387−// Suggest a possible similar reference.
388−function getClosest(pathname, references) {
389− var hash = getHash(pathname)
390− var base = getPathname(pathname)
391− var dictionary = []
392− var reference
393− var subhash
394− var subbase
395−
396− for (reference in references) {
397− subbase = getPathname(reference)
398− subhash = getHash(reference)
399−
400− if (getPathname(reference) === base) {
401− if (subhash && hash) {
402− dictionary.push(subhash)
403− }
404− } else if (!subhash && !hash) {
405− dictionary.push(subbase)
406− }
407− }
408−
409− return propose(hash ? hash : base, dictionary, {threshold: 0.7})
410−}
411−
412−// Get the `hash` of `uri`, if applicable.
413−function getHash(uri) {
414− var hash = parse(uri).hash
415− return hash ? hash.slice(1) : null
416−}
417−
418−// Get the `pathname` of `uri`, if applicable.
419−function getPathname(uri) {
420− return parse(uri).pathname
421−}
3+module.exports = require('./lib')
lib/check/check-files.browser.jsnew file+7
@@ -0,0 +1,7 @@
1+'use strict'
2+
3+module.exports = checkIfReferencedFilesExist
4+
5+function checkIfReferencedFilesExist(ctx, next) {
6+ next()
7+}
lib/check/check-files.jsnew file+42
@@ -0,0 +1,42 @@
1+'use strict'
2+
3+var fs = require('fs')
4+
5+module.exports = checkIfReferencedFilesExist
6+
7+function checkIfReferencedFilesExist(ctx, next) {
8+ var landmarks = ctx.landmarks
9+ var references = ctx.references
10+ var filePaths = []
11+ var filePath
12+ var actual = 0
13+ var expected
14+
15+ for (filePath in references) {
16+ if (landmarks[filePath] === undefined) {
17+ filePaths.push(filePath)
18+ }
19+ }
20+
21+ expected = filePaths.length
22+
23+ if (expected === 0) {
24+ next()
25+ } else {
26+ filePaths.forEach(checkIfExists)
27+ }
28+
29+ function checkIfExists(filePath) {
30+ fs.access(filePath, fs.F_OK, onaccess)
31+
32+ function onaccess(err) {
33+ var noEntry = err && (err.code === 'ENOENT' || err.code === 'ENOTDIR')
34+
35+ landmarks[filePath] = {'': !noEntry}
36+
37+ if (++actual === expected) {
38+ next()
39+ }
40+ }
41+ }
42+}
lib/check/index.jsnew file+13
@@ -0,0 +1,13 @@
1+'use strict'
2+
3+var trough = require('trough')
4+var mergeLandmarks = require('./merge-landmarks')
5+var mergeReferences = require('./merge-references')
6+var checkIfReferencedFilesExist = require('./check-files')
7+var validate = require('./validate')
8+
9+module.exports = trough()
10+ .use(mergeLandmarks)
11+ .use(mergeReferences)
12+ .use(checkIfReferencedFilesExist)
13+ .use(validate)
lib/check/merge-landmarks.jsnew file+29
@@ -0,0 +1,29 @@
1+'use strict'
2+
3+var xtend = require('xtend')
4+var constants = require('../constants')
5+
6+module.exports = mergeLandmarks
7+
8+function mergeLandmarks(ctx) {
9+ var result = {}
10+ var files = ctx.files
11+ var length = files.length
12+ var index = -1
13+ var file
14+ var landmarks
15+ var landmark
16+
17+ while (++index < length) {
18+ file = files[index]
19+ landmarks = file.data[constants.landmarkId]
20+
21+ if (landmarks) {
22+ for (landmark in landmarks) {
23+ result[landmark] = xtend(result[landmark] || {}, landmarks[landmark])
24+ }
25+ }
26+ }
27+
28+ ctx.landmarks = result
29+}
lib/check/merge-references.jsnew file+42
@@ -0,0 +1,42 @@
1+'use strict'
2+
3+var constants = require('../constants')
4+
5+module.exports = mergeReferences
6+
7+function mergeReferences(ctx) {
8+ var result = {}
9+ var files = ctx.files
10+ var length = files.length
11+ var index = -1
12+ var file
13+ var references
14+ var reference
15+ var all
16+ var internal
17+ var hash
18+
19+ while (++index < length) {
20+ file = files[index]
21+ references = file.data[constants.referenceId]
22+
23+ if (!references) {
24+ continue
25+ }
26+
27+ for (reference in references) {
28+ internal = references[reference]
29+ all = result[reference] || (result[reference] = {})
30+
31+ for (hash in internal) {
32+ ;(all[hash] || (all[hash] = [])).push({
33+ file: file,
34+ reference: {filePath: reference, hash: hash},
35+ nodes: internal[hash]
36+ })
37+ }
38+ }
39+ }
40+
41+ ctx.references = result
42+}
lib/check/validate.jsnew file+108
@@ -0,0 +1,108 @@
1+'use strict'
2+
3+var path = require('path')
4+var propose = require('propose')
5+var constants = require('../constants')
6+
7+module.exports = validate
8+
9+function validate(ctx) {
10+ var landmarks = ctx.landmarks
11+ var references = ctx.references
12+ var missing = []
13+ var reference
14+ var hash
15+ var refs
16+ var lands
17+ var length
18+ var index
19+
20+ for (reference in references) {
21+ refs = references[reference]
22+ /* istanbul ignore next - `else` could happen in browser. */
23+ lands = landmarks[reference] || {}
24+
25+ for (hash in refs) {
26+ if (!lands[hash]) {
27+ missing = missing.concat(refs[hash])
28+ }
29+ }
30+ }
31+
32+ length = missing.length
33+ index = -1
34+
35+ while (++index < length) {
36+ reference = missing[index]
37+ warn(ctx, reference.reference, reference.file, reference.nodes)
38+ }
39+}
40+
41+function warn(ctx, info, file, nodes) {
42+ var landmarks = ctx.landmarks
43+ var absolute = file.path ? path.resolve(file.cwd, file.path) : ''
44+ var base = absolute ? path.dirname(absolute) : null
45+ var filePath = base ? path.relative(base, info.filePath) : info.filePath
46+ var hash = info.hash
47+ var dictionary = []
48+ var subhash
49+ var landmark
50+ var relativeLandmark
51+ var reason
52+ var ruleId
53+ var origin
54+ var suggestion
55+
56+ if (hash) {
57+ reason = 'Link to unknown heading'
58+ ruleId = constants.headingRuleId
59+
60+ if (base && path.join(base, filePath) !== absolute) {
61+ reason += ' in `' + filePath + '`'
62+ ruleId = constants.headingInFileRuleId
63+ }
64+
65+ reason += ': `' + hash + '`'
66+ } else {
67+ reason = 'Link to unknown file: `' + filePath + '`'
68+ ruleId = constants.fileRuleId
69+ }
70+
71+ origin = [constants.sourceId, ruleId].join(':')
72+
73+ for (landmark in landmarks) {
74+ // Only suggest if file exists.
75+ if (!landmarks[landmark] || !landmarks[landmark]['']) {
76+ continue
77+ }
78+
79+ relativeLandmark = base ? path.relative(base, landmark) : landmark
80+
81+ if (!hash) {
82+ dictionary.push(relativeLandmark)
83+ continue
84+ }
85+
86+ if (relativeLandmark !== filePath) {
87+ continue
88+ }
89+
90+ for (subhash in landmarks[landmark]) {
91+ if (subhash !== '') {
92+ dictionary.push(subhash)
93+ }
94+ }
95+ }
96+
97+ suggestion = propose(hash ? hash : filePath, dictionary, {threshold: 0.7})
98+
99+ if (suggestion) {
100+ reason += '. Did you mean `' + suggestion + '`'
101+ }
102+
103+ nodes.forEach(one)
104+
105+ function one(node) {
106+ file.message(reason, node, origin)
107+ }
108+}
lib/constants.jsnew file+8
@@ -0,0 +1,8 @@
1+'use strict'
2+
3+exports.sourceId = 'remark-validate-links'
4+exports.headingRuleId = 'missing-heading'
5+exports.headingInFileRuleId = 'missing-heading-in-file'
6+exports.fileRuleId = 'missing-file'
7+exports.landmarkId = 'remarkValidateLinksLandmarks'
8+exports.referenceId = 'remarkValidateLinksReferences'
lib/find/config.jsnew file+54
@@ -0,0 +1,54 @@
1+'use strict'
2+
3+var hostedGitInfo = require('hosted-git-info')
4+
5+module.exports = config
6+
7+var viewPaths = {github: 'blob', gitlab: 'blob', bitbucket: 'src'}
8+var headingPrefixes = {github: '#', gitlab: '#', bitbucket: '#markdown-header-'}
9+var topAnchors = {github: '#readme', gitlab: '#readme'}
10+var lineLinks = {github: true, gitlab: true}
11+
12+function config(ctx) {
13+ var repo = ctx.repository
14+ var urlConfig = ctx.urlConfig
15+ var info = {}
16+
17+ if (urlConfig) {
18+ return
19+ }
20+
21+ urlConfig = {
22+ prefix: '',
23+ headingPrefix: '#',
24+ lines: false,
25+ hostname: null,
26+ topAnchor: null
27+ }
28+
29+ if (repo) {
30+ info = hostedGitInfo.fromUrl(repo)
31+ }
32+
33+ if (info) {
34+ if (info.type in viewPaths) {
35+ urlConfig.prefix = '/' + info.path() + '/' + viewPaths[info.type] + '/'
36+ }
37+
38+ if (info.type in headingPrefixes) {
39+ urlConfig.headingPrefix = headingPrefixes[info.type]
40+ }
41+
42+ if (info.type in lineLinks) {
43+ urlConfig.lines = lineLinks[info.type]
44+ }
45+
46+ if (info.type in topAnchors) {
47+ urlConfig.topAnchor = topAnchors[info.type]
48+ }
49+
50+ urlConfig.hostname = info.domain
51+ }
52+
53+ ctx.urlConfig = urlConfig
54+}
lib/find/find-repo.browser.jsnew file+7
@@ -0,0 +1,7 @@
1+'use strict'
2+
3+module.exports = findRepo
4+
5+function findRepo(ctx, next) {
6+ next()
7+}
lib/find/find-repo.jsnew file+76
@@ -0,0 +1,76 @@
1+'use strict'
2+
3+var path = require('path')
4+var exec = require('child_process').exec
5+
6+module.exports = findRepo
7+
8+function findRepo(ctx, next) {
9+ var repo = ctx.repository
10+ var file = ctx.file
11+ var base = file.cwd
12+ var actual = 0
13+ var expected = 0
14+
15+ if (file.path) {
16+ base = path.dirname(path.resolve(base, file.path))
17+ }
18+
19+ if (repo === null || repo === undefined) {
20+ expected++
21+ exec('git remote -v', {cwd: base}, onremote)
22+ }
23+
24+ if (ctx.root === null || ctx.root === undefined) {
25+ if (repo === null || repo === undefined) {
26+ expected++
27+ exec('git rev-parse --show-cdup', {cwd: base}, oncdup)
28+ } else {
29+ ctx.root = ctx.file.cwd
30+ }
31+ } else {
32+ ctx.root = path.resolve(file.cwd, ctx.root)
33+ }
34+
35+ if (actual === expected) {
36+ next()
37+ }
38+
39+ function onremote(err, stdout) {
40+ var remote
41+
42+ if (err) {
43+ expected = Infinity
44+ return next(err)
45+ }
46+
47+ remote = stdout.match(/origin\t(.+?) \(fetch\)/)
48+ ctx.repository = remote ? remote[1] : null
49+
50+ if (!ctx.repository) {
51+ expected = Infinity
52+ return next(new Error('Could not find remote origin'))
53+ }
54+
55+ if (++actual === expected) {
56+ expected = Infinity
57+ next()
58+ }
59+ }
60+
61+ function oncdup(err, stdout) {
62+ var out
63+
64+ if (err) {
65+ expected = Infinity
66+ return next(err)
67+ }
68+
69+ out = stdout.trim()
70+ ctx.root = out ? path.join(base, out) : base
71+
72+ if (++actual === expected) {
73+ next()
74+ }
75+ }
76+}
lib/find/find.jsnew file+296
@@ -0,0 +1,296 @@
1+'use strict'
2+
3+var fs = require('fs')
4+var path = require('path')
5+var URL = require('url').URL // Node 8 support
6+var vfile = require('to-vfile')
7+var visit = require('unist-util-visit')
8+var toString = require('mdast-util-to-string')
9+var xtend = require('xtend')
10+var slugs = require('github-slugger')()
11+var constants = require('../constants')
12+
13+module.exports = find
14+
15+var slash = '/'
16+var numberSign = '#'
17+var questionMark = '?'
18+
19+var https = 'https:'
20+var http = 'http:'
21+var slashes = '//'
22+
23+var lineExpression = /^#l\d/i
24+
25+// List from: https://github.com/github/markup#markups
26+var readmeExtensions = ['.markdown', '.mdown', '.mkdn', '.md']
27+var readmeBasename = /^readme$/i
28+
29+function find(ctx, next) {
30+ var file = ctx.file
31+ var fileSet = ctx.fileSet
32+ var absolute = file.path ? path.resolve(file.cwd, file.path) : ''
33+ var space = file.data
34+ var references = {}
35+ var landmarks = {}
36+ var actual = 0
37+ var expected = 0
38+ var statted = []
39+ var added = []
40+ var config = xtend(ctx.urlConfig, {
41+ path: absolute,
42+ base: absolute ? path.dirname(absolute) : file.cwd,
43+ root: ctx.root
44+ })
45+
46+ space[constants.referenceId] = references
47+ space[constants.landmarkId] = landmarks
48+
49+ addLandmarks(absolute, '')
50+
51+ slugs.reset()
52+
53+ visit(ctx.tree, mark)
54+
55+ if (expected === 0) {
56+ next()
57+ }
58+
59+ function mark(node) {
60+ var data = node.data || {}
61+ var props = data.hProperties || {}
62+ var id = props.name || props.id || data.id
63+ var info = node.url ? urlToPath(node.url, config) : null
64+ var fp
65+ var hash
66+
67+ if (!id && node.type === 'heading') {
68+ id = slugs.slug(toString(node))
69+ }
70+
71+ if (id) {
72+ addLandmarks(absolute, id)
73+ }
74+
75+ if (info) {
76+ fp = info.filePath
77+ hash = info.hash
78+
79+ addReference(fp, '', node)
80+
81+ if (hash) {
82+ if (fileSet || fp === absolute) {
83+ addReference(fp, hash, node)
84+ }
85+
86+ if (fileSet && fp && statted.indexOf(fp) === -1) {
87+ addFile(fp)
88+ }
89+ }
90+ }
91+ }
92+
93+ function addLandmarks(filePath, hash) {
94+ addLandmark(filePath, hash)
95+
96+ // Note: this may add marks too many anchors as defined.
97+ // For example, if there is both a `readme.md` and a `readme.markdown` in a
98+ // folder, both their landmarks will be defined for their parent folder.
99+ // To solve this, we could check whichever sorts first, and ignore the
100+ // others.
101+ // This is an unlikely scenario though, and adds a lot of complexity, so
102+ // we’re ignoring it.
103+ if (readme(filePath)) {
104+ addLandmark(path.dirname(filePath), hash)
105+ }
106+ }
107+
108+ function addLandmark(filePath, hash) {
109+ var marks = landmarks[filePath] || (landmarks[filePath] = {})
110+
111+ marks[hash] = true
112+ }
113+
114+ function addReference(filePath, hash, node) {
115+ var refs = references[filePath] || (references[filePath] = {})
116+ var hashes = refs[hash] || (refs[hash] = [])
117+
118+ hashes.push(node)
119+ }
120+
121+ function addFile(fileOrFolderPath) {
122+ expected++
123+
124+ statted.push(fileOrFolderPath)
125+
126+ fs.stat(fileOrFolderPath, onstat)
127+
128+ function onstat(_, stats) {
129+ if (stats && stats.isDirectory()) {
130+ fs.readdir(fileOrFolderPath, onreaddir)
131+ } else {
132+ done(fileOrFolderPath)
133+ }
134+ }
135+
136+ function onreaddir(_, entries) {
137+ /* istanbul ignore next - unlikely that it is an unreadable directory. */
138+ var files = (entries || []).sort()
139+ var length = files.length
140+ var index = -1
141+ var entry
142+ var file
143+ var filePath
144+
145+ while (++index < length) {
146+ entry = entries[index]
147+
148+ if (readme(entry)) {
149+ file = entry
150+ break
151+ }
152+ }
153+
154+ // If there is no readme that we can parse, add the directory.
155+ filePath = fileOrFolderPath
156+
157+ // To do: test for no readme in directory.
158+
159+ if (file) {
160+ filePath = path.join(fileOrFolderPath, file)
161+ statted.push(filePath)
162+ }
163+
164+ done(filePath)
165+ }
166+
167+ function done(filePath) {
168+ if (added.indexOf(filePath) === -1) {
169+ added.push(filePath)
170+
171+ fileSet.add(
172+ vfile({cwd: file.cwd, path: path.relative(file.cwd, filePath)})
173+ )
174+ }
175+
176+ actual++
177+
178+ if (actual === expected) {
179+ next()
180+ }
181+ }
182+ }
183+}
184+
185+function urlToPath(value, config) {
186+ var url
187+ var questionMarkIndex
188+ var numberSignIndex
189+
190+ // Absolute paths: `/wooorm/test/blob/main/directory/example.md`.
191+ if (value.charAt(0) === slash) {
192+ if (!config.hostname) {
193+ return
194+ }
195+
196+ // Create a URL.
197+ value = https + slashes + config.hostname + value
198+ }
199+
200+ try {
201+ url = new URL(value)
202+ } catch (_) {}
203+
204+ // URLs: `https://github.com/wooorm/test/blob/main/directory/example.md`.
205+ if (url) {
206+ // Exit if we don’t have hosted Git info or this is not a URL to the repo.
207+ if (
208+ !config.prefix ||
209+ !config.hostname ||
210+ (url.protocol !== https && url.protocol !== http) ||
211+ url.hostname !== config.hostname ||
212+ url.pathname.slice(0, config.prefix.length) !== config.prefix
213+ ) {
214+ return
215+ }
216+
217+ value = url.pathname.slice(config.prefix.length)
218+
219+ // Things get interesting here: branches: `foo/bar/baz` could be `baz` on
220+ // the `foo/bar` branch, or, `baz` in the `bar` directory on the `foo`
221+ // branch.
222+ // Currently, we’re ignoring this and just not supporting branches.
223+ value = value.split(slash).slice(1).join(slash)
224+
225+ return normalize(path.resolve(config.root, value + url.hash), config)
226+ }
227+
228+ // Remove the search: `?foo=bar`.
229+ // But don’t remove stuff if it’s in the hash: `readme.md#heading?`.
230+ numberSignIndex = value.indexOf(numberSign)
231+ questionMarkIndex = value.indexOf(questionMark)
232+
233+ if (
234+ questionMarkIndex !== -1 &&
235+ (numberSignIndex === -1 || numberSignIndex > questionMarkIndex)
236+ ) {
237+ value =
238+ value.slice(0, questionMarkIndex) +
239+ (numberSignIndex === -1 ? '' : value.slice(numberSignIndex))
240+ }
241+
242+ // Local: `#heading`.
243+ if (value.charAt(0) === numberSign) {
244+ value = config.path ? config.path + value : value
245+ }
246+ // Anything else, such as `readme.md`.
247+ else {
248+ value = config.path ? path.resolve(config.base, value) : ''
249+ }
250+
251+ return normalize(value, config)
252+}
253+
254+function normalize(url, config) {
255+ var numberSignIndex = url.indexOf(numberSign)
256+ var lines = config.lines
257+ var prefix = config.headingPrefix
258+ var topAnchor = config.topAnchor
259+ var filePath
260+ var hash
261+
262+ if (numberSignIndex === -1) {
263+ filePath = url
264+ } else {
265+ filePath = url.slice(0, numberSignIndex)
266+ hash = url.slice(numberSignIndex).toLowerCase()
267+
268+ // Ignore the hash if it references the top anchor of the environment
269+ if (topAnchor && hash === topAnchor) {
270+ hash = undefined
271+ }
272+ // Ignore the hash if it references lines in a file or doesn’t start
273+ // with a heading prefix.
274+ else if (
275+ (lines && lineExpression.test(hash)) ||
276+ hash.slice(0, prefix.length) !== prefix
277+ ) {
278+ hash = undefined
279+ }
280+ // Use the hash if it starts with a heading prefix.
281+ else {
282+ hash = hash.slice(prefix.length)
283+ }
284+ }
285+
286+ return {filePath: decodeURIComponent(filePath), hash: hash}
287+}
288+
289+function readme(filePath) {
290+ var ext = path.extname(filePath)
291+
292+ return (
293+ readmeExtensions.indexOf(ext) !== -1 &&
294+ readmeBasename.test(path.basename(filePath, ext))
295+ )
296+}
lib/find/index.jsnew file+8
@@ -0,0 +1,8 @@
1+'use strict'
2+
3+var trough = require('trough')
4+var findRepo = require('./find-repo')
5+var config = require('./config')
6+var find = require('./find')
7+
8+module.exports = trough().use(findRepo).use(config).use(find)
lib/index.jsnew file+48
@@ -0,0 +1,48 @@
1+'use strict'
2+
3+var xtend = require('xtend')
4+var check = require('./check')
5+var find = require('./find')
6+var constants = require('./constants')
7+
8+module.exports = validateLinks
9+
10+cliCompleter.pluginId = constants.sourceId
11+
12+function validateLinks(options, fileSet) {
13+ var settings = options || {}
14+
15+ // Attach a `completer`.
16+ if (fileSet) {
17+ fileSet.use(cliCompleter)
18+ }
19+
20+ return transformer
21+
22+ // Find references and landmarks.
23+ function transformer(tree, file, next) {
24+ find.run(xtend(settings, {tree: tree, file: file, fileSet: fileSet}), done)
25+
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+ }
36+}
37+
38+// Completer for the CLI (multiple files, supports parsing more files).
39+function cliCompleter(set, next) {
40+ checkAll(set.valueOf(), next)
41+}
42+
43+function checkAll(files, next) {
44+ // Check all references and landmarks.
45+ check.run({files: files}, function (err) {
46+ next(err)
47+ })
48+}
package.json+47−28
@@ -1,49 +1,69 @@
11{
22 "name": "remark-validate-links",
3− "version": "8.0.0",
4− "description": "Validate links to headings and files in markdown",
3+ "version": "10.0.2",
4+ "description": "remark plugin to validate links to headings and files",
55 "license": "MIT",
66 "keywords": [
7+ "unified",
8+ "remark",
9+ "remark-plugin",
10+ "plugin",
11+ "mdast",
12+ "markdown",
713 "validate",
814 "link",
915 "reference",
1016 "file",
11− "heading",
12− "remark"
17+ "heading"
1318 ],
1419 "repository": "remarkjs/remark-validate-links",
1520 "bugs": "https://github.com/remarkjs/remark-validate-links/issues",
21+ "funding": {
22+ "type": "opencollective",
23+ "url": "https://opencollective.com/unified"
24+ },
1625 "author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
1726 "contributors": [
18− "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
27+ "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
28+ "Diogo Nunes <dialex.nunes@gmail.com>",
29+ "Jonathan Haines <jonno.haines@gmail.com>",
30+ "Merlijn Vos <merlijn@soverin.net>",
31+ "Andrew Petro <andrew.w.petro@gmail.com>",
32+ "wangshijun <wangshijun2010@gmail.com>",
33+ "Anton Rybochkin <anton.rybochkin@axibase.com>"
1934 ],
35+ "browser": {
36+ "./lib/check/check-files.js": "./lib/check/check-files.browser.js",
37+ "./lib/find/find-repo.js": "./lib/find/find-repo.browser.js"
38+ },
2039 "files": [
40+ "lib/",
2141 "index.js"
2242 ],
2343 "dependencies": {
24− "github-slugger": "^1.2.0",
25− "hosted-git-info": "^2.5.0",
26− "mdast-util-definitions": "^1.0.0",
27− "mdast-util-to-string": "^1.0.4",
44+ "github-slugger": "^1.0.0",
45+ "hosted-git-info": "^3.0.0",
46+ "mdast-util-to-string": "^1.0.0",
2847 "propose": "0.0.5",
29− "unist-util-visit": "^1.0.0",
30− "urljoin": "^0.1.5",
31− "xtend": "^4.0.1"
48+ "to-vfile": "^6.0.0",
49+ "trough": "^1.0.0",
50+ "unist-util-visit": "^2.0.0",
51+ "xtend": "^4.0.0"
3252 },
3353 "devDependencies": {
34− "execa": "^1.0.0",
35− "nyc": "^13.0.0",
36− "remark": "^10.0.0",
37− "remark-cli": "^6.0.0",
38− "remark-preset-wooorm": "^4.0.0",
39− "strip-ansi": "^5.0.0",
40− "tape": "^4.0.0",
41− "to-vfile": "^5.0.0",
42− "vfile-sort": "^2.1.3",
43− "xo": "^0.23.0"
54+ "nyc": "^15.0.0",
55+ "prettier": "^2.0.0",
56+ "remark": "^12.0.0",
57+ "remark-cli": "^8.0.0",
58+ "remark-preset-wooorm": "^7.0.0",
59+ "rimraf": "^3.0.0",
60+ "strip-ansi": "^6.0.0",
61+ "tape": "^5.0.0",
62+ "vfile-sort": "^2.0.0",
63+ "xo": "^0.32.0"
4464 },
4565 "scripts": {
46− "format": "remark *.md -qfo && prettier --write \"**/*.js\" && xo --fix",
66+ "format": "remark . -qfo --ignore-pattern test/ && prettier . --write && xo --fix",
4767 "test-api": "node test",
4868 "test-coverage": "nyc --reporter lcov tape test/index.js",
4969 "test": "npm run format && npm run test-coverage"
@@ -66,11 +86,10 @@
6686 "prettier": true,
6787 "esnext": false,
6888 "rules": {
69− "no-eq-null": "off",
70− "eqeqeq": "off",
71− "guard-for-in": "off",
72− "max-lines": "off",
73− "complexity": "off"
89+ "unicorn/prefer-optional-catch-binding": "off",
90+ "unicorn/no-fn-reference-in-iterator": "off",
91+ "unicorn/prefer-includes": "off",
92+ "guard-for-in": "off"
7493 }
7594 },
7695 "remarkConfig": {
readme.md+140−52
@@ -3,46 +3,52 @@
33[![Build][build-badge]][build]
44[![Coverage][coverage-badge]][coverage]
55[![Downloads][downloads-badge]][downloads]
6−[![Chat][chat-badge]][chat]
6+[![Size][size-badge]][size]
77[![Sponsors][sponsors-badge]][collective]
88[![Backers][backers-badge]][collective]
9+[![Chat][chat-badge]][chat]
910
10−[**remark**][remark] plugin to validate that Markdown links and images
11−reference existing local files and headings.
12−It does not check external URLs (see [`remark-lint-no-dead-urls`][no-dead-urls]
13−for that).
11+[**remark**][remark] plugin to validate that Markdown links and images reference
12+existing local files and headings.
1413
1514For example, this document does not have a heading named `Hello`.
16−So if we link to that (`[welcome](#hello)`), this plugin will warn
17−about it.
15+So if we’d link to it (`[welcome](#hello)`), we’d get a warning.
16+
17+In addition, when there’s a link to a heading in another document
18+(`examples/foo.md#hello`), if that file exists but the heading does not, or if
19+that file does not exist, we’d also get a warning.
1820
19−In addition, when I link to a heading in another document
20−(`examples/foo.md#hello`), if this file exists but the heading does not,
21−or if the file does not exist, this plugin will also warn.
21+Linking to other files, such as `license` or `index.js` (when they exist) is
22+fine.
2223
23−Linking to other files, such as `license` or `index.js` (when they exist)
24−is fine.
24+This plugin does not check external URLs (see
25+[`remark-lint-no-dead-urls`][no-dead-urls]) or undefined references
26+(see [`remark-lint-no-undefined-references`][no-undef-refs]).
2527
26−## Table of Contents
28+## Contents
2729
28−* [Installation](#installation)
29−* [Command line](#command-line)
30−* [Programmatic](#programmatic)
30+* [Install](#install)
31+* [Use](#use)
32+ * [CLI](#cli)
33+ * [API](#api)
3134* [Configuration](#configuration)
3235* [Integration](#integration)
36+* [Security](#security)
3337* [Related](#related)
3438* [Contribute](#contribute)
3539* [License](#license)
3640
37−## Installation
41+## Install
3842
3943[npm][]:
4044
41−```bash
45+```sh
4246npm install remark-validate-links
4347```
4448
45−## Command line
49+## Use
50+
51+### CLI
4652
4753Use `remark-validate-links` together with [**remark**][remark]:
4854
@@ -59,7 +65,7 @@ Read more [whoops, this does not exist](#world).
5965
6066This doesn’t exist either [whoops!](readme.md#foo).
6167
62−But this does exist: [LICENSE](LICENSE).
68+But this does exist: [license](license).
6369
6470So does this: [README](readme.md#installation).
6571```
@@ -76,28 +82,41 @@ readme.md: no issues found
7682⚠ 2 warnings
7783```
7884
79−## Programmatic
85+> Note: passing a file over stdin(4) may not work as expected, because it is not
86+> known where the file originates from.
87+
88+### API
8089
81−> Note: The API only checks links to headings. Other URLs are not checked.
90+> Note: The API checks links to headings and files.
91+> It does not check headings in other files.
92+> In a browser, only local links to headings are checked.
8293
8394Say we have the following file, `example.md`:
8495
8596```markdown
8697# Alpha
8798
88−This [exists](#alpha). This [exists][alpha] too.
99+Links are checked:
100+
101+This [exists](#alpha).
89102This [one does not](#does-not).
90103
91104# Bravo
92105
93−This is [not checked](readme.md#bravo).
106+Headings in `readme.md` are [checked](readme.md#nosuchheading).
107+And [missing files are reported](missing-example.js).
108+
109+Definitions are also checked:
94110
95111[alpha]: #alpha
112+[charlie]: #charlie
113+
114+References w/o definitions are not checked: [delta]
96115```
97116
98117And our script, `example.js`, looks as follows:
99118
100−```javascript
119+```js
101120var vfile = require('to-vfile')
102121var report = require('vfile-reporter')
103122var remark = require('remark')
@@ -105,7 +124,7 @@ var links = require('remark-validate-links')
105124
106125remark()
107126 .use(links)
108− .process(vfile.readSync('example.md'), function(err, file) {
127+ .process(vfile.readSync('example.md'), function (err, file) {
109128 console.error(report(err || file))
110129 })
111130```
@@ -114,26 +133,41 @@ Now, running `node example` yields:
114133
115134```markdown
116135example.md
117− 4:6-4:31 warning Link to unknown heading: `does-not` remark-validate-links remark-validate-links
136+ 6:6-6:31 warning Link to unknown heading: `does-not` missing-heading remark-validate-links
137+ 11:5-11:53 warning Link to unknown file: `missing-example.js` missing-file remark-validate-links
138+ 16:1-16:20 warning Link to unknown heading: `charlie` missing-heading remark-validate-links
118139
119−⚠ 1 warning
140+⚠ 3 warnings
120141```
121142
122−## Configuration
143+(Note that `readme.md#nosuchheading` is not warned about, because the API
144+does not check headings in other Markdown files).
123145
124−You can pass a `repository`, containing anything `package.json`s
125−[`repository`][package-repository] can handle. If this is omitted,
126−`remark-validate-links` will try the `package.json` in your current working
127−directory.
146+## Configuration
128147
129−```bash
148+Typically, you don’t need to configure `remark-validate-links`, as it detects
149+local Git repositories.
150+If one is detected that references a known Git host (GitHub, GitLab,
151+or Bitbucket), some extra links can be checked.
152+If one is detected that does not reference a known Git host, local links still
153+work as expected.
154+If you’re not in a Git repository, you must pass `repository: false` explicitly.
155+
156+You can pass a `repository` (`string?`, `false`).
157+If `repository` is nullish, the Git origin remote is detected.
158+If the repository resolves to something [npm understands][package-repository]
159+as a Git host such as GitHub, GitLab, or Bitbucket, full URLs to that host
160+(say, `https://github.com/remarkjs/remark-validate-links/readme.md#install`)
161+can also be checked.
162+
163+```sh
130164remark --use 'validate-links=repository:"foo/bar"' example.md
131165```
132166
133−When a repository is given or detected (supporting GitHub, GitLab, and
134−Bitbucket), links to the files are normalized to the file-system.
135−For example, `https://github.com/foo/bar/blob/master/example.md` becomes
136−`example.md`.
167+For this to work, a `root` (`string?`) is also used, referencing the local Git
168+root directory (the place where `.git` is).
169+If both `root` and `repository` are nullish, the Git root is detected.
170+If `root` is not given but `repository` is, [`file.cwd`][cwd] is used.
137171
138172You can define this repository in [configuration files][cli] too.
139173An example `.remarkrc` file could look as follows:
@@ -151,6 +185,35 @@ An example `.remarkrc` file could look as follows:
151185}
152186```
153187
188+If you’re self-hosting a Git server, you can provide URL information directly,
189+as `urlConfig` (`Object`).
190+
191+For this repository, `urlConfig` looks as follows:
192+
193+```js
194+{
195+ // Domain of URLs:
196+ hostname: 'github.com',
197+ // Path prefix before files:
198+ prefix: '/remarkjs/remark-validate-links/blob/',
199+ // Prefix of headings:
200+ headingPrefix: '#',
201+ // Whether lines in files can be linked:
202+ lines: true
203+}
204+```
205+
206+If this project were hosted on Bitbucket, it would be:
207+
208+```js
209+{
210+ hostname: 'bitbucket.org',
211+ prefix: '/remarkjs/remark-validate-links/src/',
212+ headingPrefix: '#markdown-header-',
213+ lines: false
214+}
215+```
216+
154217## Integration
155218
156219`remark-validate-links` can detect anchors on nodes through several properties
@@ -163,6 +226,15 @@ on nodes:
163226* `node.data.id` — Used, in the future, by other tools to signal
164227 unique identifiers on nodes
165228
229+## Security
230+
231+`remark-validate-links`, in Node, accesses the file system based on user
232+content, and this may be dangerous.
233+In Node `git remote` and `git rev-parse` also runs for processed files.
234+
235+The tree is not modified, so there are no openings for
236+[cross-site scripting (XSS)][xss] attacks.
237+
166238## Related
167239
168240* [`remark-lint`][remark-lint] — Markdown code style linter
@@ -170,11 +242,13 @@ on nodes:
170242
171243## Contribute
172244
173−See [`contributing.md` in `remarkjs/remark`][contributing] for ways to get
174−started.
245+See [`contributing.md`][contributing] in [`remarkjs/.github`][health] for ways
246+to get started.
247+See [`support.md`][support] for ways to get help.
175248
176−This organisation has a [Code of Conduct][coc]. By interacting with this
177−repository, organisation, or community you agree to abide by its terms.
249+This project has a [code of conduct][coc].
250+By interacting with this repository, organization, or community you agree to
251+abide by its terms.
178252
179253## License
180254
@@ -182,7 +256,7 @@ repository, organisation, or community you agree to abide by its terms.
182256
183257<!-- Definitions -->
184258
185−[build-badge]: https://img.shields.io/travis/remarkjs/remark-validate-links.svg
259+[build-badge]: https://img.shields.io/travis/remarkjs/remark-validate-links/main.svg
186260
187261[build]: https://travis-ci.org/remarkjs/remark-validate-links
188262
@@ -194,9 +268,9 @@ repository, organisation, or community you agree to abide by its terms.
194268
195269[downloads]: https://www.npmjs.com/package/remark-validate-links
196270
197−[chat-badge]: https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg
271+[size-badge]: https://img.shields.io/bundlephobia/minzip/remark-validate-links.svg
198272
199−[chat]: https://spectrum.chat/unified/remark
273+[size]: https://bundlephobia.com/result?p=remark-validate-links
200274
201275[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
202276
@@ -204,24 +278,38 @@ repository, organisation, or community you agree to abide by its terms.
204278
205279[collective]: https://opencollective.com/unified
206280
207−[license]: license
281+[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
208282
209−[author]: https://wooorm.com
283+[chat]: https://github.com/remarkjs/remark/discussions
210284
211285[npm]: https://docs.npmjs.com/cli/install
212286
287+[health]: https://github.com/remarkjs/.github
288+
289+[contributing]: https://github.com/remarkjs/.github/blob/HEAD/contributing.md
290+
291+[support]: https://github.com/remarkjs/.github/blob/HEAD/support.md
292+
293+[coc]: https://github.com/remarkjs/.github/blob/HEAD/code-of-conduct.md
294+
295+[license]: license
296+
297+[author]: https://wooorm.com
298+
213299[remark]: https://github.com/remarkjs/remark
214300
301+[cli]: https://github.com/remarkjs/remark/tree/HEAD/packages/remark-cli#readme
302+
215303[remark-lint]: https://github.com/remarkjs/remark-lint
216304
305+[remark-html]: https://github.com/remarkjs/remark-html
306+
217307[no-dead-urls]: https://github.com/davidtheclark/remark-lint-no-dead-urls
218308
219−[remark-html]: https://github.com/remarkjs/remark-html
309+[no-undef-refs]: https://github.com/remarkjs/remark-lint/tree/master/packages/remark-lint-no-undefined-references
220310
221311[package-repository]: https://docs.npmjs.com/files/package.json#repository
222312
223−[cli]: https://github.com/remarkjs/remark/tree/master/packages/remark-cli#readme
224−
225−[contributing]: https://github.com/remarkjs/remark/blob/master/contributing.md
313+[cwd]: https://github.com/vfile/vfile#vfilecwd
226314
227−[coc]: https://github.com/remarkjs/remark/blob/master/code-of-conduct.md
315+[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
test/fixtures/bitbucket.md+9−5
@@ -4,9 +4,11 @@ This is a valid relative heading [link](#markdown-header-hello).
44
55This is an invalid relative heading [link](#markdown-header-world).
66
7+This is an ignored hash [link](#world).
8+
79## Files
810
9−This is a valid relative file [link](https://bitbucket.org/wooorm/test/src/master/examples/bitbucket.md).
11+This is a valid relative file [link](https://bitbucket.org/wooorm/test/src/main/examples/bitbucket.md).
1012
1113So is this [link](https://bitbucket.org/wooorm/test/src/foo-bar/examples/bitbucket.md).
1214
@@ -16,7 +18,7 @@ And this [link](examples/bitbucket.md).
1618
1719This is a valid external [file](../index.js).
1820
19−This is an invalid relative file [link](https://bitbucket.org/wooorm/test/src/master/examples/world.md).
21+This is an invalid relative file [link](https://bitbucket.org/wooorm/test/src/main/examples/world.md).
2022
2123So is this [link](https://bitbucket.org/wooorm/test/src/foo-bar/examples/world.md).
2224
@@ -30,7 +32,7 @@ Valid: [a](./examples/bitbucket.md#markdown-header-hello).
3032
3133Valid: [b](examples/bitbucket.md#markdown-header-hello).
3234
33−Valid: [c](https://bitbucket.org/wooorm/test/src/master/examples/bitbucket.md#markdown-header-hello).
35+Valid: [c](https://bitbucket.org/wooorm/test/src/main/examples/bitbucket.md#markdown-header-hello).
3436
3537Valid: [d](https://bitbucket.org/wooorm/test/src/foo-bar/examples/bitbucket.md#markdown-header-hello).
3638
@@ -38,7 +40,7 @@ Invalid: [e](./examples/bitbucket.md#markdown-header-world).
3840
3941Invalid: [f](examples/bitbucket.md#markdown-header-world).
4042
41−Invalid: [g](https://bitbucket.org/wooorm/test/src/master/examples/bitbucket.md#markdown-header-world).
43+Invalid: [g](https://bitbucket.org/wooorm/test/src/main/examples/bitbucket.md#markdown-header-world).
4244
4345Invalid: [h](https://bitbucket.org/wooorm/test/src/foo-bar/examples/bitbucket.md#markdown-header-world).
4446
@@ -46,10 +48,12 @@ Invalid: [i](./examples/world.md#markdown-header-hello).
4648
4749Invalid: [j](examples/world.md#markdown-header-hello).
4850
49−Invalid: [k](https://bitbucket.org/wooorm/test/src/master/examples/world.md#markdown-header-hello).
51+Invalid: [k](https://bitbucket.org/wooorm/test/src/main/examples/world.md#markdown-header-hello).
5052
5153Invalid: [l](https://bitbucket.org/wooorm/test/src/foo-bar/examples/world.md#markdown-header-hello).
5254
55+This is an ignored hash [j](https://bitbucket.org/wooorm/test/src/foo-bar/examples/bitbucket.md#world).
56+
5357## External
5458
5559These are all invalid, because they do not link to Bitbucket.
test/fixtures/case-insensitive-headings.mdnew file+9
@@ -0,0 +1,9 @@
1+# Hello
2+
3+This is fine: [link](#HELLO).
4+
5+This isn’t: [link](#WORLD).
6+
7+Also fine: [link](examples/github.md#HELLO).
8+
9+Also not fine: [link](examples/github.md#WORLD).
test/fixtures/empty.mdnew file+1
@@ -0,0 +1 @@
1+No links!
test/fixtures/examples/bitbucket.md+5−5
@@ -6,13 +6,13 @@ This is an invalid relative heading [link](#markdown-header-world).
66
77## Files
88
9−This is a valid relative file [link](https://bitbucket.org/wooorm/test/src/master/bitbucket.md).
9+This is a valid relative file [link](https://bitbucket.org/wooorm/test/src/main/bitbucket.md).
1010
1111So is this [link](https://bitbucket.org/wooorm/test/src/foo-bar/bitbucket.md).
1212
1313And this [link](../bitbucket.md).
1414
15−This is an invalid relative file [link](https://bitbucket.org/wooorm/test/src/master/world.md).
15+This is an invalid relative file [link](https://bitbucket.org/wooorm/test/src/main/world.md).
1616
1717So is this [link](https://bitbucket.org/wooorm/test/src/foo-bar/world.md).
1818
@@ -22,18 +22,18 @@ And this [link](../world.md).
2222
2323Valid: [a](../bitbucket.md#markdown-header-hello).
2424
25−Valid: [b](https://bitbucket.org/wooorm/test/src/master/bitbucket.md#markdown-header-hello).
25+Valid: [b](https://bitbucket.org/wooorm/test/src/main/bitbucket.md#markdown-header-hello).
2626
2727Valid: [c](https://bitbucket.org/wooorm/test/src/foo-bar/bitbucket.md#markdown-header-hello).
2828
2929Invalid: [d](../bitbucket.md#markdown-header-world).
3030
31−Invalid: [e](https://bitbucket.org/wooorm/test/src/master/bitbucket.md#markdown-header-world).
31+Invalid: [e](https://bitbucket.org/wooorm/test/src/main/bitbucket.md#markdown-header-world).
3232
3333Invalid: [f](https://bitbucket.org/wooorm/test/src/foo-bar/bitbucket.md#markdown-header-world).
3434
3535Invalid: [g](../world.md#markdown-header-hello).
3636
37−Invalid: [h](https://bitbucket.org/wooorm/test/src/master/world.md#markdown-header-hello).
37+Invalid: [h](https://bitbucket.org/wooorm/test/src/main/world.md#markdown-header-hello).
3838
3939Invalid: [i](https://bitbucket.org/wooorm/test/src/foo-bar/world.md#markdown-header-hello).
test/fixtures/examples/github.md+5−5
@@ -6,13 +6,13 @@ This is an invalid relative heading [link](#world).
66
77## Files
88
9−This is a valid relative file [link](https://github.com/wooorm/test/blob/master/github.md).
9+This is a valid relative file [link](https://github.com/wooorm/test/blob/main/github.md).
1010
1111So is this [link](https://github.com/wooorm/test/blob/foo-bar/github.md).
1212
1313And this [link](../github.md).
1414
15−This is an invalid relative file [link](https://github.com/wooorm/test/blob/master/world.md).
15+This is an invalid relative file [link](https://github.com/wooorm/test/blob/main/world.md).
1616
1717So is this [link](https://github.com/wooorm/test/blob/foo-bar/world.md).
1818
@@ -22,18 +22,18 @@ And this [link](../world.md).
2222
2323Valid: [a](../github.md#hello).
2424
25−Valid: [b](https://github.com/wooorm/test/blob/master/github.md#hello).
25+Valid: [b](https://github.com/wooorm/test/blob/main/github.md#hello).
2626
2727Valid: [c](https://github.com/wooorm/test/blob/foo-bar/github.md#hello).
2828
2929Invalid: [d](../github.md#world).
3030
31−Invalid: [e](https://github.com/wooorm/test/blob/master/github.md#world).
31+Invalid: [e](https://github.com/wooorm/test/blob/main/github.md#world).
3232
3333Invalid: [f](https://github.com/wooorm/test/blob/foo-bar/github.md#world).
3434
3535Invalid: [g](../world.md#hello).
3636
37−Invalid: [h](https://github.com/wooorm/test/blob/master/world.md#hello).
37+Invalid: [h](https://github.com/wooorm/test/blob/main/world.md#hello).
3838
3939Invalid: [i](https://github.com/wooorm/test/blob/foo-bar/world.md#hello).
test/fixtures/examples/gitlab.md+5−5
@@ -6,13 +6,13 @@ This is an invalid relative heading [link](#world).
66
77## Files
88
9−This is a valid relative file [link](https://gitlab.com/wooorm/test/blob/master/gitlab.md).
9+This is a valid relative file [link](https://gitlab.com/wooorm/test/blob/main/gitlab.md).
1010
1111So is this [link](https://gitlab.com/wooorm/test/blob/foo-bar/gitlab.md).
1212
1313And this [link](../gitlab.md).
1414
15−This is an invalid relative file [link](https://gitlab.com/wooorm/test/blob/master/world.md).
15+This is an invalid relative file [link](https://gitlab.com/wooorm/test/blob/main/world.md).
1616
1717So is this [link](https://gitlab.com/wooorm/test/blob/foo-bar/world.md).
1818
@@ -22,18 +22,18 @@ And this [link](../world.md).
2222
2323Valid: [a](../gitlab.md#hello).
2424
25−Valid: [b](https://gitlab.com/wooorm/test/blob/master/gitlab.md#hello).
25+Valid: [b](https://gitlab.com/wooorm/test/blob/main/gitlab.md#hello).
2626
2727Valid: [c](https://gitlab.com/wooorm/test/blob/foo-bar/gitlab.md#hello).
2828
2929Invalid: [d](../gitlab.md#world).
3030
31−Invalid: [e](https://gitlab.com/wooorm/test/blob/master/gitlab.md#world).
31+Invalid: [e](https://gitlab.com/wooorm/test/blob/main/gitlab.md#world).
3232
3333Invalid: [f](https://gitlab.com/wooorm/test/blob/foo-bar/gitlab.md#world).
3434
3535Invalid: [g](../world.md#hello).
3636
37−Invalid: [h](https://gitlab.com/wooorm/test/blob/master/world.md#hello).
37+Invalid: [h](https://gitlab.com/wooorm/test/blob/main/world.md#hello).
3838
3939Invalid: [i](https://gitlab.com/wooorm/test/blob/foo-bar/world.md#hello).
test/fixtures/examples/weird#character/readme.mdnew file+1
@@ -0,0 +1 @@
1+# Hello
test/fixtures/examples/weird#characters.mdnew file+1
@@ -0,0 +1 @@
1+# Hello
test/fixtures/external.mdnew file+11
@@ -0,0 +1,11 @@
1+# Links to external websites
2+
3+Link to [another website](https://mochajs.org)
4+
5+Link to [another website with an anchor](https://mochajs.org/#exclusive-tests)
6+
7+Link to [GitHub](https://experiments.github.com)
8+
9+Link to [`github.com`](https://github.com/pulls)
10+
11+Link to [a repo on GitHub](https://github.com/foo/bar)
test/fixtures/file-as-folder.mdnew file+1
@@ -0,0 +1 @@
1+[](file-as-folder.md/other)
test/fixtures/folder-without-readme/example.mdnew file+1
@@ -0,0 +1 @@
1+This file isn’t used when linking to the folder: it has to be a `readme`.
test/fixtures/folder.mdnew file+23
@@ -0,0 +1,23 @@
1+Here we link to a folder:
2+
3+Explicit:
4+
5+[OK](./folder/readme.markdown#this)
6+
7+[OK](./folder/readme.markdown#that)
8+
9+[NOK](./folder/readme.markdown#missing)
10+
11+Implicit:
12+
13+[OK](./folder#this)
14+
15+[OK](./folder#that)
16+
17+[NOK](./folder#missing)
18+
19+Other:
20+
21+[NOK](./missing#missing)
22+
23+[NOK](./folder-without-readme#missing)
test/fixtures/folder/example.mdnew file+1
@@ -0,0 +1 @@
1+This file isn’t used when linking to the folder: it has to be a `readme`.
test/fixtures/folder/readme.ascnew file+9
@@ -0,0 +1,9 @@
1+readme
2+------
3+
4+While GitHub would pick up on this readme for the folder,
5+`remark-validate-links` is for Markdown, so we ignore AsciiDoc.
6+
7+== This
8+
9+== That
test/fixtures/folder/readme.markdownnew file+5
@@ -0,0 +1,5 @@
1+# readme
2+
3+## This
4+
5+## That
test/fixtures/folder/readme.mdnew file+1
@@ -0,0 +1 @@
1+This one isn’t used (`readme.markdown` sorts before `readme.md`).
test/fixtures/github.md+13−5
@@ -6,7 +6,9 @@ This is an invalid relative heading [link](#world).
66
77## Files
88
9−This is a valid relative file [link](https://github.com/wooorm/test/blob/master/examples/github.md).
9+This is a valid relative file [link](https://github.com/wooorm/test/blob/main/examples/github.md).
10+
11+This is a valid absolute file [link](/wooorm/test/blob/main/examples/github.md).
1012
1113So is this [link](https://github.com/wooorm/test/blob/foo-bar/examples/github.md).
1214
@@ -16,7 +18,9 @@ And this [link](examples/github.md).
1618
1719This is a valid external [file](../index.js).
1820
19−This is an invalid relative file [link](https://github.com/wooorm/test/blob/master/examples/world.md).
21+This is an invalid relative file [link](https://github.com/wooorm/test/blob/main/examples/world.md).
22+
23+This is an invalid absolute file [link](/wooorm/test/blob/main/examples/world.md).
2024
2125So is this [link](https://github.com/wooorm/test/blob/foo-bar/examples/world.md).
2226
@@ -30,7 +34,7 @@ Valid: [a](./examples/github.md#hello).
3034
3135Valid: [b](examples/github.md#hello).
3236
33−Valid: [c](https://github.com/wooorm/test/blob/master/examples/github.md#hello).
37+Valid: [c](https://github.com/wooorm/test/blob/main/examples/github.md#hello).
3438
3539Valid: [d](https://github.com/wooorm/test/blob/foo-bar/examples/github.md#hello).
3640
@@ -38,7 +42,7 @@ Invalid: [e](./examples/github.md#world).
3842
3943Invalid: [f](examples/github.md#world).
4044
41−Invalid: [g](https://github.com/wooorm/test/blob/master/examples/github.md#world).
45+Invalid: [g](https://github.com/wooorm/test/blob/main/examples/github.md#world).
4246
4347Invalid: [h](https://github.com/wooorm/test/blob/foo-bar/examples/github.md#world).
4448
@@ -46,7 +50,7 @@ Invalid: [i](./examples/world.md#hello).
4650
4751Invalid: [j](examples/world.md#hello).
4852
49−Invalid: [k](https://github.com/wooorm/test/blob/master/examples/world.md#hello).
53+Invalid: [k](https://github.com/wooorm/test/blob/main/examples/world.md#hello).
5054
5155Invalid: [l](https://github.com/wooorm/test/blob/foo-bar/examples/world.md#hello).
5256
@@ -61,3 +65,7 @@ Valid: [b](http://example.com).
6165Valid: [b](http://example.com/foo/bar/baz).
6266
6367Valid: [b](http://bitbucket.com/wooorm/test/blob/foo-bar/examples/world.md#hello).
68+
69+## Top Anchor
70+
71+This links to the start of the document [link](#readme).
test/fixtures/gitlab.md+9−5
@@ -6,7 +6,7 @@ This is an invalid relative heading [link](#world).
66
77## Files
88
9−This is a valid relative file [link](https://gitlab.com/wooorm/test/blob/master/examples/gitlab.md).
9+This is a valid relative file [link](https://gitlab.com/wooorm/test/blob/main/examples/gitlab.md).
1010
1111So is this [link](https://gitlab.com/wooorm/test/blob/foo-bar/examples/gitlab.md).
1212
@@ -16,7 +16,7 @@ And this [link](examples/gitlab.md).
1616
1717This is a valid external [file](../index.js).
1818
19−This is an invalid relative file [link](https://gitlab.com/wooorm/test/blob/master/examples/world.md).
19+This is an invalid relative file [link](https://gitlab.com/wooorm/test/blob/main/examples/world.md).
2020
2121So is this [link](https://gitlab.com/wooorm/test/blob/foo-bar/examples/world.md).
2222
@@ -30,7 +30,7 @@ Valid: [a](./examples/gitlab.md#hello).
3030
3131Valid: [b](examples/gitlab.md#hello).
3232
33−Valid: [c](https://gitlab.com/wooorm/test/blob/master/examples/gitlab.md#hello).
33+Valid: [c](https://gitlab.com/wooorm/test/blob/main/examples/gitlab.md#hello).
3434
3535Valid: [d](https://gitlab.com/wooorm/test/blob/foo-bar/examples/gitlab.md#hello).
3636
@@ -38,7 +38,7 @@ Invalid: [e](./examples/gitlab.md#world).
3838
3939Invalid: [f](examples/gitlab.md#world).
4040
41−Invalid: [g](https://gitlab.com/wooorm/test/blob/master/examples/gitlab.md#world).
41+Invalid: [g](https://gitlab.com/wooorm/test/blob/main/examples/gitlab.md#world).
4242
4343Invalid: [h](https://gitlab.com/wooorm/test/blob/foo-bar/examples/gitlab.md#world).
4444
@@ -46,7 +46,7 @@ Invalid: [i](./examples/world.md#hello).
4646
4747Invalid: [j](examples/world.md#hello).
4848
49−Invalid: [k](https://gitlab.com/wooorm/test/blob/master/examples/world.md#hello).
49+Invalid: [k](https://gitlab.com/wooorm/test/blob/main/examples/world.md#hello).
5050
5151Invalid: [l](https://gitlab.com/wooorm/test/blob/foo-bar/examples/world.md#hello).
5252
@@ -61,3 +61,7 @@ Valid: [b](http://example.com).
6161Valid: [b](http://example.com/foo/bar/baz).
6262
6363Valid: [b](http://bitbucket.com/wooorm/test/blob/foo-bar/examples/world.md#hello).
64+
65+## Top Anchor
66+
67+This links to the start of the document [link](#readme).
test/fixtures/images.md+4−4
@@ -6,7 +6,7 @@ Relative ![image](./examples/image.jpg)
66
77No `./` in ![image](examples/image.jpg)
88
9−Absolute ![image](https://github.com/wooorm/test/blob/master/examples/image.jpg)
9+Absolute ![image](https://github.com/wooorm/test/blob/main/examples/image.jpg)
1010
1111Relative ![image reference][rel]
1212
@@ -20,7 +20,7 @@ Relative ![missing image](./examples/missing.jpg)
2020
2121No `./` in ![image](examples/missing.jpg)
2222
23−Absolute ![missing image](https://github.com/wooorm/test/blob/master/examples/missing.jpg)
23+Absolute ![missing image](https://github.com/wooorm/test/blob/main/examples/missing.jpg)
2424
2525Relative ![missing image reference][rel-missing]
2626
@@ -30,10 +30,10 @@ Absolute ![missing image reference][abs-missing]
3030
3131[rel]: ./examples/image.jpg
3232
33−[abs]: https://github.com/wooorm/test/blob/master/examples/image.jpg
33+[abs]: https://github.com/wooorm/test/blob/main/examples/image.jpg
3434
3535[rel-missing]: ./examples/missing.jpg
3636
37−[abs-missing]: https://github.com/wooorm/test/blob/master/examples/missing.jpg
37+[abs-missing]: https://github.com/wooorm/test/blob/main/examples/missing.jpg
3838
3939[rel-whitespace]: "./examples/image with space.jpg"
test/fixtures/line-links.md+2−2
@@ -4,6 +4,6 @@ Link to [a line](./examples/example.js#L1)
44
55Link to [a line in a missing file](./examples/missing.js#L1)
66
7−[a](https://github.com/wooorm/test/blob/master/examples/example.js#L1).
7+[a](https://github.com/wooorm/test/blob/main/examples/example.js#L1).
88
9−[b](https://github.com/wooorm/test/blob/master/examples/missing.js#L1).
9+[b](https://github.com/wooorm/test/blob/main/examples/missing.js#L1).
test/fixtures/query-params.mdnew file+9
@@ -0,0 +1,9 @@
1+# Query params
2+
3+Link to relative heading ![link](?foo=bar#query-params)
4+
5+Link to an ![image](./examples/image.jpg?foo=bar)
6+
7+And a file [link](./examples/github.md?foo=bar).
8+
9+Question mark in hash (invalid) [link](#query-params?).
test/fixtures/self-hosted.mdnew file+5
@@ -0,0 +1,5 @@
1+# Hello
2+
3+[Fine](https://gitlab.acme.com/acme/project/blob/main/self-hosted.md#hello);
4+
5+[Not fine](https://gitlab.acme.com/acme/project/blob/main/self-hosted.md#world);
test/fixtures/small.mdnew file+5
@@ -0,0 +1,5 @@
1+# Hello
2+
3+This is fine: [link](#hello).
4+
5+This isn’t: [link](#world).
test/fixtures/weird-characters.mdnew file+17
@@ -0,0 +1,17 @@
1+# File names and paths with weird characters
2+
3+OK: Link to [a weird character in a file name](./examples/weird%23characters.md)
4+
5+OK: Link to [a weird character in a file path](./examples/weird%23character/readme.md)
6+
7+OK: Link to [a heading with a weird character in a file name](./examples/weird%23characters.md#hello)
8+
9+OK: Link to [a heading with a weird character in a file path](./examples/weird%23character/readme.md#hello)
10+
11+Not OK: Link to [a weird character in a file name](./examples/missing%23characters.md)
12+
13+Not OK: Link to [a weird character in a file path](./examples/missing%23character/readme.md)
14+
15+Not OK: Link to [a missing heading with a weird character in a file name](./examples/weird%23characters.md#world)
16+
17+Not OK: Link to [a missing heading with a weird character in a file path](./examples/weird%23character/readme.md#world)
test/index.js+1182−408
@@ -2,526 +2,1300 @@
22
33var fs = require('fs')
44var path = require('path')
5+var childProcess = require('child_process')
56var test = require('tape')
6−var execa = require('execa')
77var vfile = require('to-vfile')
88var remark = require('remark')
99var strip = require('strip-ansi')
10+var rimraf = require('rimraf')
1011var sort = require('./sort')
1112var links = require('..')
1213
1314process.chdir(path.resolve(process.cwd(), 'test', 'fixtures'))
1415
15−test.onFinish(function() {
16+test.onFinish(function () {
1617 process.chdir(path.resolve(process.cwd(), '..', '..'))
1718})
1819
1920var bin = path.join('..', '..', 'node_modules', '.bin', 'remark')
2021
21−test('remark-validate-links', function(t) {
22− t.test('should work on the API', function(st) {
22+test('remark-validate-links', function (t) {
23+ t.test('should work on the API', function (st) {
2324 st.plan(1)
2425
2526 remark()
2627 .use(links)
2728 .use(sort)
28− .process(vfile.readSync('github.md'), function(err, file) {
29+ .process(vfile.readSync('github.md'), function (err, file) {
2930 st.deepEqual(
3031 [err].concat(file.messages.map(String)),
31− [null, 'github.md:5:37-5:51: Link to unknown heading: `world`'],
32+ [
33+ null,
34+ 'github.md:5:37-5:51: Link to unknown heading: `world`',
35+ 'github.md:27:10-27:37: Link to unknown file: `examples/world.md`',
36+ 'github.md:29:10-29:35: Link to unknown file: `examples/world.md`',
37+ 'github.md:49:10-49:40: Link to unknown file: `examples/world.md`',
38+ 'github.md:51:10-51:38: Link to unknown file: `examples/world.md`'
39+ ],
3240 'should report messages'
3341 )
3442 })
3543 })
3644
37− t.test('should throw on unparsable git repositories', function(st) {
38− st.plan(1)
39−
40− execa(bin, [
41− '--no-config',
42− '--no-ignore',
43− '--use',
44− '../..=repository:"invalid:shortcode"',
45− '--use',
46− '../sort',
47− 'definitions.md'
48− ]).then(
49− function() {
50− st.fail('should not be successful')
51− },
52− function(err) {
53− st.equal(
54− strip(err.stderr)
55− .split('\n')
56− .slice(0, 2)
57− .join('\n'),
58− [
59− 'definitions.md',
60− ' 1:1 error Error: remark-validate-links cannot parse `repository` (`invalid:shortcode`)'
61− ].join('\n'),
62− 'should report an error'
63− )
64− }
45+ t.test('should ignore invalid repositories', function (st) {
46+ st.plan(1)
47+
48+ childProcess.exec(
49+ [
50+ bin,
51+ '--no-config',
52+ '--no-ignore',
53+ '--use',
54+ '"../..=repository:\\"invalid:shortcode\\""',
55+ '--use',
56+ '../sort',
57+ 'small.md'
58+ ].join(' '),
59+ onexec
6560 )
61+
62+ function onexec(err, stdout, stderr) {
63+ st.deepEqual(
64+ [err, strip(stderr)],
65+ [
66+ null,
67+ [
68+ 'small.md',
69+ ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links',
70+ '',
71+ '⚠ 1 warning',
72+ ''
73+ ].join('\n')
74+ ],
75+ 'should work'
76+ )
77+ }
6678 })
6779
68− t.test('should throw on gist repositories', function(st) {
69− st.plan(1)
70−
71− execa(bin, [
72− '--no-config',
73− '--no-ignore',
74− '--use',
75− '../..=repository:"gist:wooorm/8504606"',
76− '--use',
77− '../sort',
78− 'definitions.md'
79− ]).then(
80− function() {
81− st.fail('should not be successful')
82− },
83− function(err) {
84− st.equal(
85− strip(err.stderr)
86− .split('\n')
87− .slice(0, 2)
88− .join('\n'),
80+ t.test('should throw on Gist repositories', function (st) {
81+ st.plan(1)
82+
83+ childProcess.exec(
84+ [
85+ bin,
86+ '--no-config',
87+ '--no-ignore',
88+ '--use',
89+ '"../..=repository:\\"gist:wooorm/8504606\\""',
90+ '--use',
91+ '../sort',
92+ 'small.md'
93+ ].join(' '),
94+ onexec
95+ )
96+
97+ function onexec(err, stdout, stderr) {
98+ st.deepEqual(
99+ [err, strip(stderr)],
100+ [
101+ null,
89102 [
90− 'definitions.md',
91− ' 1:1 error Error: remark-validate-links does not support gist repositories'
92− ].join('\n'),
93− 'should report an error'
94− )
95− }
103+ 'small.md',
104+ ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links',
105+ '',
106+ '⚠ 1 warning',
107+ ''
108+ ].join('\n')
109+ ],
110+ 'should work'
111+ )
112+ }
113+ })
114+
115+ t.test('should ignore unfound files (#1)', function (st) {
116+ st.plan(1)
117+
118+ childProcess.exec(
119+ [
120+ bin,
121+ '--no-config',
122+ '--no-ignore',
123+ '--use',
124+ '../..',
125+ '--use',
126+ '../sort',
127+ 'FOOOO'
128+ ].join(' '),
129+ onexec
96130 )
131+
132+ function onexec(err, stdout, stderr) {
133+ st.deepEqual(
134+ [/command failed/i.test(err), strip(stderr)],
135+ [
136+ true,
137+ [
138+ 'FOOOO',
139+ ' 1:1 error No such file or directory',
140+ '',
141+ '✖ 1 error',
142+ ''
143+ ].join('\n')
144+ ],
145+ 'should work'
146+ )
147+ }
97148 })
98149
99− t.test('should ignore unfound files', function(st) {
100− st.plan(1)
101−
102− execa(bin, [
103− '--no-config',
104− '--no-ignore',
105− '--use',
106− '../..',
107− 'definitions.md',
108− '--use',
109− '../sort',
110− 'FOOOO'
111− ]).then(
112− function() {
113− st.fail('should not be successful')
114− },
115− function(err) {
116− st.equal(
117− strip(err.stderr),
150+ t.test('should ignore unfound files (#2)', function (st) {
151+ st.plan(1)
152+
153+ childProcess.exec(
154+ [
155+ bin,
156+ '--no-config',
157+ '--no-ignore',
158+ '--use',
159+ '../..',
160+ '--use',
161+ '../sort',
162+ 'definitions.md',
163+ 'FOOOO'
164+ ].join(' '),
165+ onexec
166+ )
167+
168+ function onexec(err, stdout, stderr) {
169+ st.deepEqual(
170+ [/command failed/i.test(err), strip(stderr)],
171+ [
172+ true,
118173 [
119174 'FOOOO',
120− ' 1:1 error No such file or directory',
175+ ' 1:1 error No such file or directory',
121176 '',
122177 'definitions.md',
123− ' 5:12-5:21 warning Link to unknown heading: `world` missing-heading remark-validate-links',
178+ ' 10:1-10:18 warning Link to unknown heading: `world` missing-heading remark-validate-links',
124179 '',
125180 '2 messages (✖ 1 error, ⚠ 1 warning)',
126181 ''
127− ].join('\n'),
128− 'should report an error'
129− )
130− }
182+ ].join('\n')
183+ ],
184+ 'should work'
185+ )
186+ }
187+ })
188+
189+ t.test('should work if there are no links', function (st) {
190+ st.plan(1)
191+
192+ childProcess.exec(
193+ [
194+ bin,
195+ '--no-config',
196+ '--no-ignore',
197+ '--use',
198+ '../..',
199+ '--use',
200+ '../sort',
201+ 'empty.md'
202+ ].join(' '),
203+ onexec
131204 )
205+
206+ function onexec(err, stdout, stderr) {
207+ st.deepEqual(
208+ [err, strip(stderr)],
209+ [null, 'empty.md: no issues found\n'],
210+ 'should work'
211+ )
212+ }
132213 })
133214
134− t.test('should work when not all files are given', function(st) {
215+ t.test('should work with stdin', function (st) {
135216 st.plan(1)
136217
137− execa(bin, [
138− '--no-config',
139− '--no-ignore',
140− '--use',
141− '../..',
142− '--use',
143− '../sort',
144− 'github.md'
145− ]).then(function(result) {
146− st.equal(
147− strip(result.stderr),
218+ var subprocess = childProcess.exec(
219+ [
220+ bin,
221+ '--no-config',
222+ '--no-ignore',
223+ '--use',
224+ '../..',
225+ '--use',
226+ '../sort'
227+ ].join(' '),
228+ onexec
229+ )
230+
231+ fs.createReadStream('github.md').pipe(subprocess.stdin)
232+
233+ function onexec(err, stdout, stderr) {
234+ st.deepEqual(
235+ [err, strip(stderr)],
148236 [
149− 'github.md',
150− ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
151− ' 23:10-23:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
152− ' 25:10-25:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
153− ' 37:10-37:41 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
154− ' 39:10-39:39 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
155− ' 45:10-45:40 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
156− ' 45:10-45:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
157− ' 47:10-47:38 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
158− ' 47:10-47:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
159− '',
160− '⚠ 9 warnings'
161− ].join('\n'),
162− 'should report'
237+ null,
238+ [
239+ '<stdin>',
240+ ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
241+ '',
242+ '⚠ 1 warning',
243+ ''
244+ ].join('\n')
245+ ],
246+ 'should work'
163247 )
164− }, st.error)
248+ }
165249 })
166250
167− t.test('should work when all files are given', function(st) {
251+ t.test('should work when not all files are given', function (st) {
168252 st.plan(1)
169253
170− execa(bin, [
171− '--no-config',
172− '--no-ignore',
173− '--use',
174− '../..',
175− '--use',
176− '../sort',
177− 'github.md',
178− 'examples/github.md'
179− ]).then(function(result) {
180− st.equal(
181− strip(result.stderr),
254+ childProcess.exec(
255+ [
256+ bin,
257+ '--no-config',
258+ '--no-ignore',
259+ '--use',
260+ '../..',
261+ '--use',
262+ '../sort',
263+ 'github.md'
264+ ].join(' '),
265+ onexec
266+ )
267+
268+ function onexec(err, stdout, stderr) {
269+ st.deepEqual(
270+ [err, strip(stderr)],
182271 [
183− 'examples/github.md',
184− ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
185− ' 19:10-19:29 warning Link to unknown file: `world.md` missing-file remark-validate-links',
186− ' 29:10-29:33 warning Link to unknown heading in `github.md`: `world` missing-heading-in-file remark-validate-links',
187− ' 35:10-35:32 warning Link to unknown file: `world.md` missing-file remark-validate-links',
188− ' 35:10-35:32 warning Link to unknown heading in `world.md`: `hello` missing-heading-in-file remark-validate-links',
189− '',
190− 'github.md',
191− ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
192− ' 23:10-23:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
193− ' 25:10-25:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
194− ' 37:10-37:41 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
195− ' 39:10-39:39 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
196− ' 45:10-45:40 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
197− ' 45:10-45:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
198− ' 47:10-47:38 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
199− ' 47:10-47:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
200− '',
201− '⚠ 14 warnings'
202− ].join('\n'),
203− 'should report'
272+ null,
273+ [
274+ 'github.md',
275+ ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
276+ ' 27:10-27:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
277+ ' 29:10-29:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
278+ ' 41:10-41:41 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
279+ ' 43:10-43:39 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
280+ ' 49:10-49:40 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
281+ ' 49:10-49:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
282+ ' 51:10-51:38 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
283+ ' 51:10-51:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
284+ '',
285+ '⚠ 9 warnings',
286+ ''
287+ ].join('\n')
288+ ],
289+ 'should work'
204290 )
205− }, st.error)
291+ }
206292 })
207293
208− t.test('should work with definitions', function(st) {
294+ t.test('should work when all files are given', function (st) {
209295 st.plan(1)
210296
211− execa(bin, [
212− '--no-config',
213− '--no-ignore',
214− '--use',
215− '../..',
216− '--use',
217− '../sort',
218− 'definitions.md'
219− ]).then(function(result) {
220− st.equal(
221− strip(result.stderr),
297+ childProcess.exec(
298+ [
299+ bin,
300+ '--no-config',
301+ '--no-ignore',
302+ '--use',
303+ '../..',
304+ '--use',
305+ '../sort',
306+ 'github.md',
307+ 'examples/github.md'
308+ ].join(' '),
309+ onexec
310+ )
311+
312+ function onexec(err, stdout, stderr) {
313+ st.deepEqual(
314+ [err, strip(stderr)],
222315 [
223− 'definitions.md',
224− ' 5:12-5:21 warning Link to unknown heading: `world` missing-heading remark-validate-links',
225− '',
226− '⚠ 1 warning'
227− ].join('\n'),
228− 'should report'
316+ null,
317+ [
318+ 'examples/github.md',
319+ ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
320+ ' 19:10-19:29 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
321+ ' 29:10-29:33 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links',
322+ ' 35:10-35:32 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
323+ ' 35:10-35:32 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links',
324+ '',
325+ 'github.md',
326+ ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
327+ ' 27:10-27:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
328+ ' 29:10-29:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
329+ ' 41:10-41:41 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
330+ ' 43:10-43:39 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
331+ ' 49:10-49:40 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
332+ ' 49:10-49:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
333+ ' 51:10-51:38 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
334+ ' 51:10-51:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
335+ '',
336+ '⚠ 14 warnings',
337+ ''
338+ ].join('\n')
339+ ],
340+ 'should work'
229341 )
230− }, st.error)
342+ }
231343 })
232344
233− t.test('should work on GitHub URLs when given a repo', function(st) {
345+ t.test('should work with definitions', function (st) {
234346 st.plan(1)
235347
236− execa(bin, [
237− '--no-config',
238− '--no-ignore',
239− '--use',
240− '../..=repository:"wooorm/test"',
241− '--use',
242− '../sort',
243− 'github.md',
244− 'examples/github.md'
245− ]).then(function(result) {
246− st.equal(
247− strip(result.stderr),
348+ childProcess.exec(
349+ [
350+ bin,
351+ '--no-config',
352+ '--no-ignore',
353+ '--use',
354+ '../..',
355+ '--use',
356+ '../sort',
357+ 'definitions.md'
358+ ].join(' '),
359+ onexec
360+ )
361+
362+ function onexec(err, stdout, stderr) {
363+ st.deepEqual(
364+ [err, strip(stderr)],
248365 [
249− 'examples/github.md',
250− ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
251− ' 15:34-15:93 warning Link to unknown file: `world.md` missing-file remark-validate-links',
252− ' 17:12-17:72 warning Link to unknown file: `world.md` missing-file remark-validate-links',
253− ' 19:10-19:29 warning Link to unknown file: `world.md` missing-file remark-validate-links',
254− ' 29:10-29:33 warning Link to unknown heading in `github.md`: `world` missing-heading-in-file remark-validate-links',
255− ' 31:10-31:73 warning Link to unknown heading in `github.md`: `world` missing-heading-in-file remark-validate-links',
256− ' 33:10-33:74 warning Link to unknown heading in `github.md`: `world` missing-heading-in-file remark-validate-links',
257− ' 35:10-35:32 warning Link to unknown file: `world.md` missing-file remark-validate-links',
258− ' 35:10-35:32 warning Link to unknown heading in `world.md`: `hello` missing-heading-in-file remark-validate-links',
259− ' 37:10-37:72 warning Link to unknown file: `world.md` missing-file remark-validate-links',
260− ' 37:10-37:72 warning Link to unknown heading in `world.md`: `hello` missing-heading-in-file remark-validate-links',
261− ' 39:10-39:73 warning Link to unknown file: `world.md` missing-file remark-validate-links',
262− ' 39:10-39:73 warning Link to unknown heading in `world.md`: `hello` missing-heading-in-file remark-validate-links',
263− '',
264− 'github.md',
265− ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
266− ' 19:34-19:102 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
267− ' 21:12-21:81 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
268− ' 23:10-23:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
269− ' 25:10-25:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
270− ' 37:10-37:41 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
271− ' 39:10-39:39 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
272− ' 41:10-41:82 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
273− ' 43:10-43:83 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
274− ' 45:10-45:40 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
275− ' 45:10-45:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
276− ' 47:10-47:38 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
277− ' 47:10-47:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
278− ' 49:10-49:81 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
279− ' 49:10-49:81 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
280− ' 51:10-51:82 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
281− ' 51:10-51:82 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
282− '',
283− '⚠ 30 warnings'
284− ].join('\n'),
285− 'should report'
366+ null,
367+ [
368+ 'definitions.md',
369+ ' 10:1-10:18 warning Link to unknown heading: `world` missing-heading remark-validate-links',
370+ '',
371+ '⚠ 1 warning',
372+ ''
373+ ].join('\n')
374+ ],
375+ 'should work'
286376 )
287− }, st.error)
377+ }
288378 })
289379
290− t.test('should work on GitHub URLs when with package.json', function(st) {
380+ t.test('should work on GitHub URLs when given a repo', function (st) {
291381 st.plan(1)
292382
293− // `cwd` is moved to `test/fixtures`.
294− fs.writeFileSync(
295− './package.json',
296− JSON.stringify({repository: 'wooorm/test'}, 0, 2)
383+ childProcess.exec(
384+ [
385+ bin,
386+ '--no-config',
387+ '--no-ignore',
388+ '--use',
389+ '"../..=repository:\\"wooorm/test\\""',
390+ '--use',
391+ '../sort',
392+ 'github.md',
393+ 'examples/github.md'
394+ ].join(' '),
395+ onexec
297396 )
298397
299− function clean() {
300− fs.unlinkSync('./package.json')
301− }
302−
303− execa(bin, [
304− '--no-config',
305− '--no-ignore',
306− '--use',
307− '../..',
308− '--use',
309− '../sort',
310− 'github.md',
311− 'examples/github.md'
312− ]).then(
313− function(result) {
314− clean()
315− st.equal(
316− strip(result.stderr),
398+ function onexec(err, stdout, stderr) {
399+ st.deepEqual(
400+ [err, strip(stderr)],
401+ [
402+ null,
317403 [
318404 'examples/github.md',
319405 ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
320− ' 15:34-15:93 warning Link to unknown file: `world.md` missing-file remark-validate-links',
321− ' 17:12-17:72 warning Link to unknown file: `world.md` missing-file remark-validate-links',
322− ' 19:10-19:29 warning Link to unknown file: `world.md` missing-file remark-validate-links',
323− ' 29:10-29:33 warning Link to unknown heading in `github.md`: `world` missing-heading-in-file remark-validate-links',
324− ' 31:10-31:73 warning Link to unknown heading in `github.md`: `world` missing-heading-in-file remark-validate-links',
325− ' 33:10-33:74 warning Link to unknown heading in `github.md`: `world` missing-heading-in-file remark-validate-links',
326− ' 35:10-35:32 warning Link to unknown file: `world.md` missing-file remark-validate-links',
327− ' 35:10-35:32 warning Link to unknown heading in `world.md`: `hello` missing-heading-in-file remark-validate-links',
328− ' 37:10-37:72 warning Link to unknown file: `world.md` missing-file remark-validate-links',
329− ' 37:10-37:72 warning Link to unknown heading in `world.md`: `hello` missing-heading-in-file remark-validate-links',
330− ' 39:10-39:73 warning Link to unknown file: `world.md` missing-file remark-validate-links',
331− ' 39:10-39:73 warning Link to unknown heading in `world.md`: `hello` missing-heading-in-file remark-validate-links',
406+ ' 15:34-15:91 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
407+ ' 17:12-17:72 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
408+ ' 19:10-19:29 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
409+ ' 29:10-29:33 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links',
410+ ' 31:10-31:71 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links',
411+ ' 33:10-33:74 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links',
412+ ' 35:10-35:32 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
413+ ' 35:10-35:32 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links',
414+ ' 37:10-37:70 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
415+ ' 37:10-37:70 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links',
416+ ' 39:10-39:73 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
417+ ' 39:10-39:73 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links',
332418 '',
333419 'github.md',
334420 ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
335− ' 19:34-19:102 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
336− ' 21:12-21:81 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
337− ' 23:10-23:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
338− ' 25:10-25:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
339− ' 37:10-37:41 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
340− ' 39:10-39:39 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
341− ' 41:10-41:82 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
342− ' 43:10-43:83 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
343− ' 45:10-45:40 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
344− ' 45:10-45:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
345− ' 47:10-47:38 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
346− ' 47:10-47:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
347− ' 49:10-49:81 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
348− ' 49:10-49:81 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
349− ' 51:10-51:82 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
350− ' 51:10-51:82 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
421+ ' 21:34-21:100 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
422+ ' 23:34-23:82 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
423+ ' 25:12-25:81 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
424+ ' 27:10-27:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
425+ ' 29:10-29:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
426+ ' 41:10-41:41 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
427+ ' 43:10-43:39 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
428+ ' 45:10-45:80 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
429+ ' 47:10-47:83 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
430+ ' 49:10-49:40 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
431+ ' 49:10-49:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
432+ ' 51:10-51:38 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
433+ ' 51:10-51:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
434+ ' 53:10-53:79 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
435+ ' 53:10-53:79 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
436+ ' 55:10-55:82 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
437+ ' 55:10-55:82 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
351438 '',
352− '⚠ 30 warnings'
353− ].join('\n'),
354− 'should report'
439+ '⚠ 31 warnings',
440+ ''
441+ ].join('\n')
442+ ],
443+ 'should work'
444+ )
445+ }
446+ })
447+
448+ t.test('should work when with Git directory', function (st) {
449+ st.plan(1)
450+
451+ childProcess.exec('git init', oninit)
452+
453+ function oninit(err) {
454+ if (err) {
455+ t.ifErr(err)
456+ } else {
457+ childProcess.exec(
458+ 'git remote add origin git@github.com:wooorm/test.git',
459+ onremote
355460 )
356− },
357− function(err) {
461+ }
462+ }
463+
464+ function onremote(err) {
465+ if (err) {
358466 clean()
359− st.error(err)
467+ t.ifErr(err)
468+ } else {
469+ childProcess.exec(
470+ [
471+ bin,
472+ '--no-config',
473+ '--no-ignore',
474+ '--use',
475+ '../..',
476+ '--use',
477+ '../sort',
478+ 'github.md',
479+ 'examples/github.md'
480+ ].join(' '),
481+ onexec
482+ )
360483 }
484+ }
485+
486+ function onexec(err, stdout, stderr) {
487+ clean()
488+ st.deepEqual(
489+ [err, strip(stderr)],
490+ [
491+ null,
492+ [
493+ 'examples/github.md',
494+ ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
495+ ' 15:34-15:91 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
496+ ' 17:12-17:72 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
497+ ' 19:10-19:29 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
498+ ' 29:10-29:33 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links',
499+ ' 31:10-31:71 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links',
500+ ' 33:10-33:74 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links',
501+ ' 35:10-35:32 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
502+ ' 35:10-35:32 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links',
503+ ' 37:10-37:70 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
504+ ' 37:10-37:70 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links',
505+ ' 39:10-39:73 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
506+ ' 39:10-39:73 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links',
507+ '',
508+ 'github.md',
509+ ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
510+ ' 21:34-21:100 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
511+ ' 23:34-23:82 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
512+ ' 25:12-25:81 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
513+ ' 27:10-27:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
514+ ' 29:10-29:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
515+ ' 41:10-41:41 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
516+ ' 43:10-43:39 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
517+ ' 45:10-45:80 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
518+ ' 47:10-47:83 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
519+ ' 49:10-49:40 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
520+ ' 49:10-49:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
521+ ' 51:10-51:38 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
522+ ' 51:10-51:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
523+ ' 53:10-53:79 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
524+ ' 53:10-53:79 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
525+ ' 55:10-55:82 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
526+ ' 55:10-55:82 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
527+ '',
528+ '⚠ 31 warnings',
529+ ''
530+ ].join('\n')
531+ ],
532+ 'should work'
533+ )
534+ }
535+
536+ function clean() {
537+ rimraf.sync('./.git')
538+ }
539+ })
540+
541+ t.test('should fail w/o Git repository', function (st) {
542+ st.plan(1)
543+
544+ fs.renameSync('../../.git', '../../.git.bak')
545+
546+ childProcess.exec(
547+ [
548+ bin,
549+ '--no-config',
550+ '--no-ignore',
551+ '--use',
552+ '../..',
553+ '--use',
554+ '../sort',
555+ 'github.md'
556+ ].join(' '),
557+ onexec
558+ )
559+
560+ function onexec(err) {
561+ fs.renameSync('../../.git.bak', '../../.git')
562+ st.ok(/not a git repository/i.test(err), 'should fail')
563+ }
564+ })
565+
566+ t.test('should fail w/o Git repository w/o remote', function (st) {
567+ st.plan(1)
568+
569+ childProcess.exec('git init', oninit)
570+
571+ function oninit(err) {
572+ if (err) {
573+ t.ifErr(err)
574+ } else {
575+ childProcess.exec(
576+ [
577+ bin,
578+ '--no-config',
579+ '--no-ignore',
580+ '--use',
581+ '../..',
582+ 'github.md'
583+ ].join(' '),
584+ onexec
585+ )
586+ }
587+ }
588+
589+ function onexec(err) {
590+ rimraf.sync('./.git')
591+ st.ok(/Could not find remote origin/.test(err), 'should fail')
592+ }
593+ })
594+
595+ t.test('should work w/o Git repository w/ repo', function (st) {
596+ st.plan(1)
597+
598+ fs.renameSync('../../.git', '../../.git.bak')
599+
600+ childProcess.exec(
601+ [
602+ bin,
603+ '--no-config',
604+ '--no-ignore',
605+ '--use',
606+ '"../..=repository:\\"wooorm/test\\""',
607+ '--use',
608+ '../sort',
609+ 'small.md'
610+ ].join(' '),
611+ onexec
612+ )
613+
614+ function onexec(err, stdout, stderr) {
615+ fs.renameSync('../../.git.bak', '../../.git')
616+ st.deepEqual(
617+ [err, strip(stderr)],
618+ [
619+ null,
620+ [
621+ 'small.md',
622+ ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links',
623+ '',
624+ '⚠ 1 warning',
625+ ''
626+ ].join('\n')
627+ ],
628+ 'should work'
629+ )
630+ }
631+ })
632+
633+ t.test('should work w/o Git repository w/ remote', function (st) {
634+ st.plan(1)
635+
636+ fs.renameSync('../../.git', '../../.git.bak')
637+
638+ childProcess.exec(
639+ [
640+ bin,
641+ '--no-config',
642+ '--no-ignore',
643+ '--use',
644+ '"../..=repository:{remote:\\"wooorm/test\\"}"',
645+ 'small.md'
646+ ].join(' '),
647+ onexec
648+ )
649+
650+ function onexec(err, stdout, stderr) {
651+ fs.renameSync('../../.git.bak', '../../.git')
652+ st.deepEqual(
653+ [err, strip(stderr)],
654+ [
655+ null,
656+ [
657+ 'small.md',
658+ ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links',
659+ '',
660+ '⚠ 1 warning',
661+ ''
662+ ].join('\n')
663+ ],
664+ 'should work'
665+ )
666+ }
667+ })
668+
669+ t.test('should work w/o Git repository w/ remote and root', function (st) {
670+ st.plan(1)
671+
672+ fs.renameSync('../../.git', '../../.git.bak')
673+
674+ childProcess.exec(
675+ [
676+ bin,
677+ '--no-config',
678+ '--no-ignore',
679+ '--use',
680+ '"../..=repository:\\"wooorm/test\\",root:\\"../\\""',
681+ 'small.md'
682+ ].join(' '),
683+ onexec
684+ )
685+
686+ function onexec(err, stdout, stderr) {
687+ fs.renameSync('../../.git.bak', '../../.git')
688+ st.deepEqual(
689+ [err, strip(stderr)],
690+ [
691+ null,
692+ [
693+ 'small.md',
694+ ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links',
695+ '',
696+ '⚠ 1 warning',
697+ ''
698+ ].join('\n')
699+ ],
700+ 'should work'
701+ )
702+ }
703+ })
704+
705+ t.test('should work with `repository:false`', function (st) {
706+ st.plan(1)
707+
708+ fs.renameSync('../../.git', '../../.git.bak')
709+
710+ childProcess.exec(
711+ [
712+ bin,
713+ '--no-config',
714+ '--no-ignore',
715+ '--use',
716+ '"../..=repository:false"',
717+ '--use',
718+ '../sort',
719+ 'github.md',
720+ 'examples/github.md'
721+ ].join(' '),
722+ onexec
723+ )
724+
725+ function onexec(err, stdout, stderr) {
726+ fs.renameSync('../../.git.bak', '../../.git')
727+ st.deepEqual(
728+ [err, strip(stderr)],
729+ [
730+ null,
731+ [
732+ 'examples/github.md',
733+ ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
734+ ' 19:10-19:29 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
735+ ' 29:10-29:33 warning Link to unknown heading in `../github.md`: `world` missing-heading-in-file remark-validate-links',
736+ ' 35:10-35:32 warning Link to unknown file: `../world.md` missing-file remark-validate-links',
737+ ' 35:10-35:32 warning Link to unknown heading in `../world.md`: `hello` missing-heading-in-file remark-validate-links',
738+ '',
739+ 'github.md',
740+ ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
741+ ' 27:10-27:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
742+ ' 29:10-29:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
743+ ' 41:10-41:41 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
744+ ' 43:10-43:39 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
745+ ' 49:10-49:40 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
746+ ' 49:10-49:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
747+ ' 51:10-51:38 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
748+ ' 51:10-51:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
749+ ' 71:41-71:56 warning Link to unknown heading: `readme` missing-heading remark-validate-links',
750+ '',
751+ '⚠ 15 warnings',
752+ ''
753+ ].join('\n')
754+ ],
755+ 'should work'
756+ )
757+ }
758+ })
759+
760+ t.test('should work when finding non-hosted Git remotes', function (st) {
761+ st.plan(1)
762+
763+ childProcess.exec(
764+ [
765+ bin,
766+ '--no-config',
767+ '--no-ignore',
768+ '--use',
769+ '"../..=repository:\\"ssh://git@domain.com/user/project.git\\""',
770+ '--use',
771+ '../sort',
772+ 'small.md'
773+ ].join(' '),
774+ onexec
775+ )
776+
777+ function onexec(err, stdout, stderr) {
778+ st.deepEqual(
779+ [err, strip(stderr)],
780+ [
781+ null,
782+ [
783+ 'small.md',
784+ ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links',
785+ '',
786+ '⚠ 1 warning',
787+ ''
788+ ].join('\n')
789+ ],
790+ 'should work'
791+ )
792+ }
793+ })
794+
795+ t.test('should support a GitLab shortcode', function (st) {
796+ st.plan(1)
797+
798+ childProcess.exec(
799+ [
800+ bin,
801+ '--no-config',
802+ '--no-ignore',
803+ '--use',
804+ '"../..=repository:\\"gitlab:wooorm/test\\""',
805+ '--use',
806+ '../sort',
807+ 'gitlab.md'
808+ ].join(' '),
809+ onexec
810+ )
811+
812+ function onexec(err, stdout, stderr) {
813+ st.deepEqual(
814+ [err, strip(stderr)],
815+ [
816+ null,
817+ [
818+ 'gitlab.md',
819+ ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
820+ ' 19:34-19:100 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
821+ ' 21:12-21:81 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
822+ ' 23:10-23:37 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
823+ ' 25:10-25:35 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
824+ ' 37:10-37:41 warning Link to unknown heading in `examples/gitlab.md`: `world` missing-heading-in-file remark-validate-links',
825+ ' 39:10-39:39 warning Link to unknown heading in `examples/gitlab.md`: `world` missing-heading-in-file remark-validate-links',
826+ ' 41:10-41:80 warning Link to unknown heading in `examples/gitlab.md`: `world` missing-heading-in-file remark-validate-links',
827+ ' 43:10-43:83 warning Link to unknown heading in `examples/gitlab.md`: `world` missing-heading-in-file remark-validate-links',
828+ ' 45:10-45:40 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
829+ ' 45:10-45:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
830+ ' 47:10-47:38 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
831+ ' 47:10-47:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
832+ ' 49:10-49:79 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
833+ ' 49:10-49:79 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
834+ ' 51:10-51:82 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
835+ ' 51:10-51:82 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
836+ '',
837+ '⚠ 17 warnings',
838+ ''
839+ ].join('\n')
840+ ],
841+ 'should work'
842+ )
843+ }
844+ })
845+
846+ t.test('should support a Bitbucket shortcode', function (st) {
847+ st.plan(1)
848+
849+ childProcess.exec(
850+ [
851+ bin,
852+ '--no-config',
853+ '--no-ignore',
854+ '--use',
855+ '"../..=repository:\\"bitbucket:wooorm/test\\""',
856+ '--use',
857+ '../sort',
858+ 'bitbucket.md'
859+ ].join(' '),
860+ onexec
861+ )
862+
863+ function onexec(err, stdout, stderr) {
864+ st.deepEqual(
865+ [err, strip(stderr)],
866+ [
867+ null,
868+ [
869+ 'bitbucket.md',
870+ ' 5:37-5:67 warning Link to unknown heading: `world` missing-heading remark-validate-links',
871+ ' 21:34-21:102 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
872+ ' 23:12-23:83 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
873+ ' 25:10-25:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
874+ ' 27:10-27:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
875+ ' 39:10-39:60 warning Link to unknown heading in `examples/bitbucket.md`: `world` missing-heading-in-file remark-validate-links',
876+ ' 41:10-41:58 warning Link to unknown heading in `examples/bitbucket.md`: `world` missing-heading-in-file remark-validate-links',
877+ ' 43:10-43:101 warning Link to unknown heading in `examples/bitbucket.md`: `world` missing-heading-in-file remark-validate-links',
878+ ' 45:10-45:104 warning Link to unknown heading in `examples/bitbucket.md`: `world` missing-heading-in-file remark-validate-links',
879+ ' 47:10-47:56 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
880+ ' 47:10-47:56 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
881+ ' 49:10-49:54 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
882+ ' 49:10-49:54 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
883+ ' 51:10-51:97 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
884+ ' 51:10-51:97 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
885+ ' 53:10-53:100 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
886+ ' 53:10-53:100 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
887+ '',
888+ '⚠ 17 warnings',
889+ ''
890+ ].join('\n')
891+ ],
892+ 'should work'
893+ )
894+ }
895+ })
896+
897+ t.test('should suggest similar links', function (st) {
898+ st.plan(1)
899+
900+ childProcess.exec(
901+ [
902+ bin,
903+ '--no-config',
904+ '--no-ignore',
905+ '--use',
906+ '../..',
907+ '--use',
908+ '../sort',
909+ 'suggestions.md'
910+ ].join(' '),
911+ onexec
912+ )
913+
914+ function onexec(err, stdout, stderr) {
915+ st.deepEqual(
916+ [err, strip(stderr)],
917+ [
918+ null,
919+ [
920+ 'suggestions.md',
921+ ' 3:22-3:37 warning Link to unknown heading: `helloo`. Did you mean `hello` missing-heading remark-validate-links',
922+ ' 7:17-7:39 warning Link to unknown heading in `github.md`: `fiiiles`. Did you mean `files` missing-heading-in-file remark-validate-links',
923+ '',
924+ '⚠ 2 warnings',
925+ ''
926+ ].join('\n')
927+ ],
928+ 'should work'
929+ )
930+ }
931+ })
932+
933+ t.test('should recognise links to particular lines', function (st) {
934+ st.plan(1)
935+
936+ childProcess.exec(
937+ [
938+ bin,
939+ '--no-config',
940+ '--no-ignore',
941+ '--use',
942+ '"../..=repository:\\"wooorm/test\\""',
943+ '--use',
944+ '../sort',
945+ 'line-links.md'
946+ ].join(' '),
947+ onexec
948+ )
949+
950+ function onexec(err, stdout, stderr) {
951+ st.deepEqual(
952+ [err, strip(stderr)],
953+ [
954+ null,
955+ [
956+ 'line-links.md',
957+ ' 5:9-5:61 warning Link to unknown file: `examples/missing.js` missing-file remark-validate-links',
958+ ' 9:1-9:69 warning Link to unknown file: `examples/missing.js` missing-file remark-validate-links',
959+ '',
960+ '⚠ 2 warnings',
961+ ''
962+ ].join('\n')
963+ ],
964+ 'should work'
965+ )
966+ }
967+ })
968+
969+ t.test('should recognise links with encoded URLs', function (st) {
970+ st.plan(1)
971+
972+ childProcess.exec(
973+ [
974+ bin,
975+ '--no-config',
976+ '--no-ignore',
977+ '--use',
978+ '"../..=repository:\\"wooorm/test\\""',
979+ '--use',
980+ '../sort',
981+ 'weird-characters.md'
982+ ].join(' '),
983+ onexec
361984 )
985+
986+ function onexec(err, stdout, stderr) {
987+ st.deepEqual(
988+ [err, strip(stderr)],
989+ [
990+ null,
991+ [
992+ 'weird-characters.md',
993+ ' 11:17-11:87 warning Link to unknown file: `examples/missing#characters.md`. Did you mean `examples/weird#characters.md` missing-file remark-validate-links',
994+ ' 13:17-13:93 warning Link to unknown file: `examples/missing#character/readme.md`. Did you mean `examples/weird#character/readme.md` missing-file remark-validate-links',
995+ ' 15:17-15:114 warning Link to unknown heading in `examples/weird#characters.md`: `world` missing-heading-in-file remark-validate-links',
996+ ' 17:17-17:120 warning Link to unknown heading in `examples/weird#character/readme.md`: `world` missing-heading-in-file remark-validate-links',
997+ '',
998+ '⚠ 4 warnings',
999+ ''
1000+ ].join('\n')
1001+ ],
1002+ 'should work'
1003+ )
1004+ }
3621005 })
3631006
364− t.test('should support a GitLab shortcode', function(st) {
1007+ t.test('should support folders', function (st) {
3651008 st.plan(1)
3661009
367− execa(bin, [
368− '--no-config',
369− '--no-ignore',
370− '--use',
371− '../..=repository:"gitlab:wooorm/test"',
372− '--use',
373− '../sort',
374− 'gitlab.md'
375− ]).then(function(result) {
376− st.equal(
377− strip(result.stderr),
1010+ childProcess.exec(
1011+ [
1012+ bin,
1013+ '--no-config',
1014+ '--no-ignore',
1015+ '--use',
1016+ '"../..=repository:\\"wooorm/test\\""',
1017+ '--use',
1018+ '../sort',
1019+ 'folder.md'
1020+ ].join(' '),
1021+ onexec
1022+ )
1023+
1024+ function onexec(err, stdout, stderr) {
1025+ st.deepEqual(
1026+ [err, strip(stderr)],
3781027 [
379− 'gitlab.md',
380− ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading remark-validate-links',
381− ' 19:34-19:102 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
382− ' 21:12-21:81 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
383− ' 23:10-23:37 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
384− ' 25:10-25:35 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
385− ' 37:10-37:41 warning Link to unknown heading in `examples/gitlab.md`: `world` missing-heading-in-file remark-validate-links',
386− ' 39:10-39:39 warning Link to unknown heading in `examples/gitlab.md`: `world` missing-heading-in-file remark-validate-links',
387− ' 41:10-41:82 warning Link to unknown heading in `examples/gitlab.md`: `world` missing-heading-in-file remark-validate-links',
388− ' 43:10-43:83 warning Link to unknown heading in `examples/gitlab.md`: `world` missing-heading-in-file remark-validate-links',
389− ' 45:10-45:40 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
390− ' 45:10-45:40 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
391− ' 47:10-47:38 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
392− ' 47:10-47:38 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
393− ' 49:10-49:81 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
394− ' 49:10-49:81 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
395− ' 51:10-51:82 warning Link to unknown file: `examples/world.md`. Did you mean `examples/gitlab.md` missing-file remark-validate-links',
396− ' 51:10-51:82 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
397− '',
398− '⚠ 17 warnings'
399− ].join('\n'),
400− 'should report'
1028+ null,
1029+ [
1030+ 'folder.md',
1031+ ' 9:1-9:40 warning Link to unknown heading in `folder/readme.markdown`: `missing` missing-heading-in-file remark-validate-links',
1032+ ' 17:1-17:24 warning Link to unknown heading in `folder`: `missing` missing-heading-in-file remark-validate-links',
1033+ ' 21:1-21:25 warning Link to unknown file: `missing` missing-file remark-validate-links',
1034+ ' 21:1-21:25 warning Link to unknown heading in `missing`: `missing` missing-heading-in-file remark-validate-links',
1035+ ' 23:1-23:39 warning Link to unknown heading in `folder-without-readme`: `missing` missing-heading-in-file remark-validate-links',
1036+ '',
1037+ '⚠ 5 warnings',
1038+ ''
1039+ ].join('\n')
1040+ ],
1041+ 'should work'
4011042 )
402− }, st.error)
1043+ }
4031044 })
4041045
405− t.test('should support a Bitbucket shortcode', function(st) {
1046+ t.test('should warn on files as folders', function (st) {
4061047 st.plan(1)
4071048
408− execa(bin, [
409− '--no-config',
410− '--no-ignore',
411− '--use',
412− '../..=repository:"bitbucket:wooorm/test"',
413− '--use',
414− '../sort',
415− 'bitbucket.md'
416− ]).then(function(result) {
417− st.equal(
418− strip(result.stderr),
1049+ childProcess.exec(
1050+ [
1051+ bin,
1052+ '--no-config',
1053+ '--no-ignore',
1054+ '--use',
1055+ '../..',
1056+ '--use',
1057+ '../sort',
1058+ 'file-as-folder.md'
1059+ ].join(' '),
1060+ onexec
1061+ )
1062+
1063+ function onexec(err, stdout, stderr) {
1064+ st.deepEqual(
1065+ [err, strip(stderr)],
4191066 [
420− 'bitbucket.md',
421− ' 5:37-5:67 warning Link to unknown heading: `world` missing-heading remark-validate-links',
422− ' 19:34-19:104 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
423− ' 21:12-21:83 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
424− ' 23:10-23:37 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
425− ' 25:10-25:35 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
426− ' 37:10-37:60 warning Link to unknown heading in `examples/bitbucket.md`: `world` missing-heading-in-file remark-validate-links',
427− ' 39:10-39:58 warning Link to unknown heading in `examples/bitbucket.md`: `world` missing-heading-in-file remark-validate-links',
428− ' 41:10-41:103 warning Link to unknown heading in `examples/bitbucket.md`: `world` missing-heading-in-file remark-validate-links',
429− ' 43:10-43:104 warning Link to unknown heading in `examples/bitbucket.md`: `world` missing-heading-in-file remark-validate-links',
430− ' 45:10-45:56 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
431− ' 45:10-45:56 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
432− ' 47:10-47:54 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
433− ' 47:10-47:54 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
434− ' 49:10-49:99 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
435− ' 49:10-49:99 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
436− ' 51:10-51:100 warning Link to unknown file: `examples/world.md` missing-file remark-validate-links',
437− ' 51:10-51:100 warning Link to unknown heading in `examples/world.md`: `hello` missing-heading-in-file remark-validate-links',
438− '',
439− '⚠ 17 warnings'
440− ].join('\n'),
441− 'should report'
1067+ null,
1068+ [
1069+ 'file-as-folder.md',
1070+ ' 1:1-1:28 warning Link to unknown file: `file-as-folder.md/other`. Did you mean `file-as-folder.md` missing-file remark-validate-links',
1071+ '',
1072+ '⚠ 1 warning',
1073+ ''
1074+ ].join('\n')
1075+ ],
1076+ 'should work'
4421077 )
443− }, st.error)
1078+ }
4441079 })
4451080
446− t.test('should suggest similar links', function(st) {
1081+ t.test('should check images', function (st) {
4471082 st.plan(1)
4481083
449− execa(bin, [
450− '--no-config',
451− '--no-ignore',
452− '--use',
453− '../..',
454− '--use',
455− '../sort',
456− 'suggestions.md'
457− ]).then(function(result) {
458− st.equal(
459− strip(result.stderr),
1084+ childProcess.exec(
1085+ [
1086+ bin,
1087+ '--no-config',
1088+ '--no-ignore',
1089+ '--use',
1090+ '"../..=repository:\\"wooorm/test\\""',
1091+ '--use',
1092+ '../sort',
1093+ 'images.md'
1094+ ].join(' '),
1095+ onexec
1096+ )
1097+
1098+ function onexec(err, stdout, stderr) {
1099+ st.deepEqual(
1100+ [err, strip(stderr)],
4601101 [
461− 'suggestions.md',
462− ' 3:22-3:37 warning Link to unknown heading: `helloo`. Did you mean `hello` missing-heading remark-validate-links',
463− ' 7:17-7:39 warning Link to unknown heading in `github.md`: `fiiiles`. Did you mean `files` missing-heading-in-file remark-validate-links',
464− '',
465− '⚠ 2 warnings'
466− ].join('\n'),
467− 'should report'
1102+ null,
1103+ [
1104+ 'images.md',
1105+ ' 19:10-19:50 warning Link to unknown file: `examples/missing.jpg`. Did you mean `examples/image.jpg` missing-file remark-validate-links',
1106+ ' 21:12-21:42 warning Link to unknown file: `examples/missing.jpg`. Did you mean `examples/image.jpg` missing-file remark-validate-links',
1107+ ' 23:10-23:89 warning Link to unknown file: `examples/missing.jpg`. Did you mean `examples/image.jpg` missing-file remark-validate-links',
1108+ ' 35:1-35:38 warning Link to unknown file: `examples/missing.jpg`. Did you mean `examples/image.jpg` missing-file remark-validate-links',
1109+ ' 37:1-37:77 warning Link to unknown file: `examples/missing.jpg`. Did you mean `examples/image.jpg` missing-file remark-validate-links',
1110+ '',
1111+ '⚠ 5 warnings',
1112+ ''
1113+ ].join('\n')
1114+ ],
1115+ 'should work'
4681116 )
469− }, st.error)
1117+ }
4701118 })
4711119
472− t.test('should recognize github links to particular lines', function(st) {
1120+ t.test('should support query parameters', function (st) {
4731121 st.plan(1)
4741122
475− execa(bin, [
476− '--no-config',
477− '--no-ignore',
478− '--use',
479− '../..=repository:"wooorm/test"',
480− '--use',
481− '../sort',
482− 'line-links.md'
483− ]).then(function(result) {
484− st.equal(
485− strip(result.stderr),
1123+ childProcess.exec(
1124+ [
1125+ bin,
1126+ '--no-config',
1127+ '--no-ignore',
1128+ '--use',
1129+ '"../..=repository:\\"wooorm/test\\""',
1130+ '--use',
1131+ '../sort',
1132+ 'query-params.md'
1133+ ].join(' '),
1134+ onexec
1135+ )
1136+
1137+ function onexec(err, stdout, stderr) {
1138+ st.deepEqual(
1139+ [err, strip(stderr)],
4861140 [
487− 'line-links.md',
488− ' 5:9-5:61 warning Link to unknown file: `examples/missing.js` missing-file remark-validate-links',
489− ' 9:1-9:71 warning Link to unknown file: `examples/missing.js` missing-file remark-validate-links',
490− '',
491− '⚠ 2 warnings'
492− ].join('\n'),
493− 'should report'
1141+ null,
1142+ [
1143+ 'query-params.md',
1144+ ' 9:33-9:55 warning Link to unknown heading: `query-params?`. Did you mean `query-params` missing-heading remark-validate-links',
1145+ '',
1146+ '⚠ 1 warning',
1147+ ''
1148+ ].join('\n')
1149+ ],
1150+ 'should work'
4941151 )
495− }, st.error)
1152+ }
4961153 })
4971154
498− t.test('should check images', function(st) {
1155+ t.test('should support case insensitive headings', function (st) {
4991156 st.plan(1)
5001157
501− execa(bin, [
502− '--no-config',
503− '--no-ignore',
504− '--use',
505− '../..=repository:"wooorm/test"',
506− '--use',
507− '../sort',
508− 'images.md'
509− ]).then(function(result) {
510− st.equal(
511− strip(result.stderr),
1158+ childProcess.exec(
1159+ [
1160+ bin,
1161+ '--no-config',
1162+ '--no-ignore',
1163+ '--use',
1164+ '../..',
1165+ '--use',
1166+ '../sort',
1167+ 'case-insensitive-headings.md'
1168+ ].join(' '),
1169+ onexec
1170+ )
1171+
1172+ function onexec(err, stdout, stderr) {
1173+ st.deepEqual(
1174+ [err, strip(stderr)],
5121175 [
513− 'images.md',
514− ' 19:10-19:50 warning Link to unknown file: `examples/missing.jpg` missing-file remark-validate-links',
515− ' 21:12-21:42 warning Link to unknown file: `examples/missing.jpg` missing-file remark-validate-links',
516− ' 23:10-23:91 warning Link to unknown file: `examples/missing.jpg` missing-file remark-validate-links',
517− ' 25:10-25:49 warning Link to unknown file: `examples/missing.jpg` missing-file remark-validate-links',
518− ' 27:10-27:49 warning Link to unknown file: `examples/missing.jpg` missing-file remark-validate-links',
519− '',
520− '⚠ 5 warnings'
521− ].join('\n'),
522− 'should report'
1176+ null,
1177+ [
1178+ 'case-insensitive-headings.md',
1179+ ' 5:13-5:27 warning Link to unknown heading: `world` missing-heading remark-validate-links',
1180+ ' 9:16-9:48 warning Link to unknown heading in `examples/github.md`: `world` missing-heading-in-file remark-validate-links',
1181+ '',
1182+ '⚠ 2 warnings',
1183+ ''
1184+ ].join('\n')
1185+ ],
1186+ 'should work'
5231187 )
524− }, st.error)
1188+ }
1189+ })
1190+
1191+ t.test('should ignore external links', function (st) {
1192+ st.plan(1)
1193+
1194+ childProcess.exec(
1195+ [
1196+ bin,
1197+ '--no-config',
1198+ '--no-ignore',
1199+ '--use',
1200+ '"../..=repository:\\"wooorm/test\\""',
1201+ '--use',
1202+ '../sort',
1203+ 'external.md'
1204+ ].join(' '),
1205+ onexec
1206+ )
1207+
1208+ function onexec(err, stdout, stderr) {
1209+ st.deepEqual(
1210+ [err, strip(stderr)],
1211+ [null, 'external.md: no issues found\n'],
1212+ 'should work'
1213+ )
1214+ }
1215+ })
1216+
1217+ t.test('should ignore external links (without repo)', function (st) {
1218+ st.plan(1)
1219+
1220+ childProcess.exec(
1221+ [
1222+ bin,
1223+ '--no-config',
1224+ '--no-ignore',
1225+ '--use',
1226+ '../..=repository:false',
1227+ '--use',
1228+ '../sort',
1229+ 'external.md'
1230+ ].join(' '),
1231+ onexec
1232+ )
1233+
1234+ function onexec(err, stdout, stderr) {
1235+ st.deepEqual(
1236+ [err, strip(stderr)],
1237+ [null, 'external.md: no issues found\n'],
1238+ 'should work'
1239+ )
1240+ }
1241+ })
1242+
1243+ t.test('should support self-hosted Git solutions', function (st) {
1244+ st.plan(1)
1245+
1246+ childProcess.exec('git init', oninit)
1247+
1248+ function oninit(err) {
1249+ if (err) {
1250+ t.ifErr(err)
1251+ } else {
1252+ childProcess.exec(
1253+ 'git remote add origin git@gitlab.acme.company:acme/project.git',
1254+ onremote
1255+ )
1256+ }
1257+ }
1258+
1259+ function onremote(err) {
1260+ if (err) {
1261+ clean()
1262+ t.ifErr(err)
1263+ } else {
1264+ childProcess.exec(
1265+ [
1266+ bin,
1267+ '--no-config',
1268+ '--no-ignore',
1269+ '--use',
1270+ '"../..=urlConfig:{hostname:\\"gitlab.acme.com\\",prefix:\\"/acme/project/blob/\\",headingPrefix:\\"#\\",lines:true}"',
1271+ 'self-hosted.md'
1272+ ].join(' '),
1273+ onexec
1274+ )
1275+ }
1276+ }
1277+
1278+ function onexec(err, stdout, stderr) {
1279+ clean()
1280+ st.deepEqual(
1281+ [err, strip(stderr)],
1282+ [
1283+ null,
1284+ [
1285+ 'self-hosted.md',
1286+ ' 5:1-5:80 warning Link to unknown heading: `world` missing-heading remark-validate-links',
1287+ '',
1288+ '⚠ 1 warning',
1289+ ''
1290+ ].join('\n')
1291+ ],
1292+ 'should work'
1293+ )
1294+ }
1295+
1296+ function clean() {
1297+ rimraf.sync('./.git')
1298+ }
5251299 })
5261300
5271301 t.end()