git.iko.soy/typeable/remark-validate-links
on main help sign in
53 files changed+2761−792
since splitsnapshots
unifiedsplit
.gitignore+1 .npmrc+1 .prettierignore+3 .travis.yml+2−10 index.js+2−345 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 LICENSE → license package.json+71−40 readme.md+230−71 screenshot.png test/fixtures/bitbucket.md+67 test/fixtures/case-insensitive-headings.md+9 test/fixtures/empty.md+1 test/fixtures/examples/bitbucket.md+39 test/fixtures/examples/example.js+1 test/fixtures/examples/example.md−39 test/fixtures/examples/github.md+39 test/fixtures/examples/gitlab.md+39 test/fixtures/examples/image with space.jpg test/fixtures/examples/image.jpg 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/example.md → test/fixtures/github.md+22−14 test/fixtures/gitlab.md+67 test/fixtures/images.md+39 test/fixtures/line-links.md+9 test/fixtures/query-params.md+9 test/fixtures/self-hosted.md+5 test/fixtures/small.md+5 test/fixtures/suggestions.md+2−2 test/fixtures/weird-characters.md+17 test/index.js+1276−271 test/sort.js+13
.gitignore+1
@@ -3,3 +3,4 @@
33.nyc_output/
44coverage/
55node_modules/
6+yarn.lock
.npmrcnew file+1
@@ -0,0 +1 @@
1+package-lock=false
.prettierignorenew file+3
@@ -0,0 +1,3 @@
1+coverage/
2+*.json
3+*.md
.travis.yml+2−10
@@ -1,13 +1,5 @@
11language: node_js
22node_js:
3−- '4.0'
4−- '6.0'
3+ - lts/dubnium
4+ - node
55after_success: bash <(curl -s https://codecov.io/bash)
6−deploy:
7− provider: npm
8− email: tituswormer@gmail.com
9− api_key:
10− secure: NslAC8ebv6SgJQOGIER9ivZfTUTpT4t0FX7JukKXzAj2syfoKxsm/MzImfN3usDVkmTxnWw/PJQgUhkiD0Mw03ceLPgxAssoNcneE7mrTR/LJcT+r+TxM8rfZszO917G7hJonN/sHBUqzSmPKJmD1zKnFiPD1SN6x6T09sFVeS0VgJIiKZA1LZDtHatbX6USNiGfk7J0KVocJs2P8SWqU5NEGwDYWIgYtAFP2xHPc5ttn9p29kMZ3v1geKVyaKU6+TwUJ6T83wSy5bX5mDdGSpM0zwox0pqoYsbwZCUAudlNjHYm1NZxowhfkseExA6sLef3QKd2aoUclXO9CMbpOP6bHpyaukHc7x0vJzmOsZDnvrSLf/iZzwzT13BSGjs+Im22gAJ8A3zBBnG/acWNpQZ8sIS8jXPw0oTrPSRAf3JAfA28Q/zYnGaDRInbO7JXtencNI3nR+royQsBf0VNdvfMug03GwMeAq4xXCzuafsux+VRyOxu9c+YV+2olQFC4zxrF6ecpN+PpyAquHyINsgqEQNmbopnq6xvX2tlogpys/ehPmFaFqmBq7ghsLLpl3YyZZ4CHlSnlJ4wBeyBi4bYiLnToPE1AS6Ykq1Os0xwYpyKqx6o3EzQ9hMXOfe9Z98Zv0VQHM8JWOFt90HFhzdBpN0dwKgzIBBfgBcgxo4=
11− on:
12− tags: true
13− node: '6.0'
index.js+2−345
@@ -1,346 +1,3 @@
1−'use strict';
1+'use strict'
22
3−var url = require('url');
4−var fs = require('fs');
5−var path = require('path');
6−var propose = require('propose');
7−var visit = require('unist-util-visit');
8−var definitions = require('mdast-util-definitions');
9−var gh = require('github-url-to-object');
10−var urljoin = require('urljoin');
11−var slug = require('remark-slug');
12−var xtend = require('xtend');
13−
14−module.exports = attacher;
15−
16−completer.pluginId = 'remark-validate-links';
17−
18−var exists = fs.existsSync;
19−var parse = url.parse;
20−
21−function attacher(options, fileSet) {
22− var repo = (options || {}).repository;
23− var pack;
24−
25− /* Throw when not on the CLI. */
26− if (!fileSet) {
27− throw new Error('remark-validate-links only works on the CLI');
28− }
29−
30− /* Try to get the repo from `package.json` when not
31− * given. */
32− if (!repo) {
33− try {
34− pack = fileSet.files[0].cwd;
35− // eslint-disable-next-line import/no-dynamic-require
36− pack = require(path.resolve(pack, 'package.json'));
37− } catch (err) {
38− pack = {};
39− }
40−
41− repo = pack.repository ? pack.repository.url || pack.repository : '';
42− }
43−
44− repo = repo ? gh(repo) : {};
45−
46− /* Attach a `completer`. */
47− fileSet.use(completer);
48−
49− /* Attach `slug`. */
50− this.use(slug).use(subplugin);
51−
52− function subplugin() {
53− /* Expose transformer. */
54− return transformerFactory({user: repo.user, repo: repo.repo}, fileSet);
55− }
56−}
57−
58−/* Completer. */
59−function completer(set, done) {
60− var exposed = {};
61−
62− set.valueOf().forEach(function (file) {
63− var landmarks = file.data.remarkValidateLinksLandmarks;
64−
65− if (landmarks) {
66− exposed = xtend(exposed, landmarks);
67− }
68− });
69−
70− set.valueOf().forEach(function (file) {
71− /* istanbul ignore else - stdin */
72− if (file.path) {
73− validate(exposed, file);
74− }
75− });
76−
77− done();
78−}
79−
80−/* Factory to create a transformer based on the given
81− * project and set. */
82−function transformerFactory(project, fileSet) {
83− return transformer;
84−
85− /* Transformer. Adds references files to the set. */
86− function transformer(ast, file) {
87− var filePath = file.path;
88− var space = file.data;
89− var links = [];
90− var landmarks = {};
91− var references;
92− var current;
93− var link;
94− var pathname;
95−
96− /* istanbul ignore if - stdin */
97− if (!filePath) {
98− return;
99− }
100−
101− references = gatherReferences(file, ast, project);
102− current = getPathname(filePath);
103−
104− for (link in references) {
105− pathname = getPathname(link);
106−
107− if (
108− pathname !== current &&
109− getHash(link) &&
110− links.indexOf(pathname) === -1
111− ) {
112− links.push(pathname);
113− fileSet.add(pathname);
114− }
115− }
116−
117− landmarks[filePath] = true;
118−
119− visit(ast, function (node) {
120− var data = node.data || {};
121− var attrs = data.htmlAttributes || {};
122− var id = attrs.name || attrs.id || data.id;
123−
124− if (id) {
125− landmarks[filePath + '#' + id] = true;
126− }
127− });
128−
129− space.remarkValidateLinksReferences = references;
130− space.remarkValidateLinksLandmarks = landmarks;
131− }
132−}
133−
134−/* Check if `file` references headings or files not in
135− * `exposed`. If `project` is given, normalizes GitHub blob
136− * URLs. */
137−function validate(exposed, file) {
138− var references = file.data.remarkValidateLinksReferences;
139− var filePath = file.path;
140− var reference;
141− var nodes;
142− var real;
143− var hash;
144− var pathname;
145− var warning;
146− var suggestion;
147−
148− for (reference in references) {
149− nodes = references[reference];
150− real = exposed[reference];
151− hash = getHash(reference);
152−
153− /* Check if files without `hash` can be linked to.
154− * Because there’s no need to inspect those files
155− * for headings they are not added to remark. This
156− * is especially useful because they might be
157− * non-markdown files. Here we check if they exist. */
158− if ((real === undefined || real === null) && !hash) {
159− real = exists(reference);
160− references[reference] = real;
161− }
162−
163− if (!real) {
164− if (hash) {
165− pathname = getPathname(reference);
166− warning = 'Link to unknown heading';
167−
168− if (pathname !== filePath) {
169− warning += ' in `' + pathname + '`';
170− }
171−
172− warning += ': `' + hash + '`';
173− } else {
174− warning = 'Link to unknown file: `' + reference + '`';
175− }
176−
177− suggestion = getClosest(reference, exposed);
178−
179− if (suggestion) {
180− warning += '. Did you mean `' + suggestion + '`';
181− }
182−
183− warnAll(file, nodes, warning);
184− }
185− }
186−}
187−
188−/* Gather references: a map of file-paths references
189− * to be one or more nodes. */
190−function gatherReferences(file, tree, project) {
191− var cache = {};
192− var filePath = file.path;
193− var dirname = file.dirname;
194− var getDefinition;
195− var prefix = '';
196−
197− getDefinition = definitions(tree);
198−
199− if (project.user && project.repo) {
200− prefix = '/' + project.user + '/' + project.repo + '/blob/';
201− }
202−
203− /* Handle new links. */
204− function onlink(node) {
205− var link = node.url;
206− var definition;
207− var index;
208− var uri;
209− var pathname;
210− var hash;
211−
212− /* Handle link-references. */
213− if (node.identifier) {
214− definition = getDefinition(node.identifier);
215− link = definition && definition.url;
216− }
217−
218− /* Ignore definitions without link. */
219− if (!link) {
220− return;
221− }
222−
223− uri = parse(link);
224−
225− if (!uri.hostname) {
226− /* Handle hashes, or relative files. */
227− if (!uri.pathname && uri.hash) {
228− link = filePath + uri.hash;
229− uri = parse(link);
230− } else {
231− link = urljoin(dirname, link);
232− if (uri.hash) {
233− link += uri.hash;
234− }
235− uri = parse(link);
236− }
237− }
238−
239− /* Handle full links.
240− * Only works with GitHub.
241− */
242− if (uri.hostname) {
243− if (!prefix) {
244− return;
245− }
246−
247− if (
248− uri.hostname !== 'github.com' ||
249− uri.pathname.slice(0, prefix.length) !== prefix
250− ) {
251− return;
252− }
253−
254− link = uri.pathname.slice(prefix.length) + (uri.hash || '');
255−
256− /* Things get interesting here: branches.
257− * `foo/bar/baz` could be `baz` on the
258− * `foo/bar` branch. Or, `baz` in the `bar`
259− * directory on the `foo` branch.
260− *
261− * Currently, I’m ignoring this and just not
262− * supporting branches. */
263− link = link.slice(link.indexOf('/') + 1);
264−
265− uri = parse(link);
266− }
267−
268− /* Handle file links, or combinations of files
269− * and hashes. */
270− index = link.indexOf('#');
271−
272− if (index === -1) {
273− pathname = link;
274− hash = null;
275− } else {
276− pathname = link.slice(0, index);
277− hash = link.slice(index + 1);
278− }
279−
280− if (!cache[pathname]) {
281− cache[pathname] = [];
282− }
283−
284− cache[pathname].push(node);
285−
286− if (hash) {
287− if (!cache[link]) {
288− cache[link] = [];
289− }
290−
291− cache[link].push(node);
292− }
293− }
294−
295− visit(tree, 'link', onlink);
296− visit(tree, 'linkReference', onlink);
297−
298− return cache;
299−}
300−
301−/* Utilitity to warn `reason` for each node in `nodes`,
302− * on `file`. */
303−function warnAll(file, nodes, reason) {
304− nodes.forEach(function (node) {
305− var message = file.message(reason, node);
306− message.source = 'remark-validate-links';
307− message.ruleId = 'remark-validate-links';
308− });
309−}
310−
311−/* Suggest a possible similar reference. */
312−function getClosest(pathname, references) {
313− var hash = getHash(pathname);
314− var base = getPathname(pathname);
315− var dictionary = [];
316− var reference;
317− var subhash;
318− var subbase;
319−
320− for (reference in references) {
321− subbase = getPathname(reference);
322− subhash = getHash(reference);
323−
324− if (getPathname(reference) === base) {
325− if (subhash && hash) {
326− dictionary.push(subhash);
327− }
328− } else if (!subhash && !hash) {
329− dictionary.push(subbase);
330− }
331− }
332−
333− return propose(hash ? hash : base, dictionary, {threshold: 0.7});
334−}
335−
336−/* Get the `hash` of `uri`, if applicable. */
337−function getHash(uri) {
338− var hash = parse(uri).hash;
339−
340− return hash ? hash.slice(1) : null;
341−}
342−
343−/* Get the `pathname` of `uri`, if applicable. */
344−function getPathname(uri) {
345− return parse(uri).pathname;
346−}
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+}
LICENSE → licenserenamed

The content is the same.

package.json+71−40
@@ -1,61 +1,72 @@
11{
22 "name": "remark-validate-links",
3− "version": "6.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 ],
14− "dependencies": {
15− "github-url-to-object": "^3.0.0",
16− "mdast-util-definitions": "^1.0.0",
17− "propose": "0.0.5",
18− "remark-slug": "^4.2.1",
19− "unist-util-visit": "^1.0.0",
20− "urljoin": "^0.1.5",
21− "xtend": "^4.0.1"
19+ "repository": "remarkjs/remark-validate-links",
20+ "bugs": "https://github.com/remarkjs/remark-validate-links/issues",
21+ "funding": {
22+ "type": "opencollective",
23+ "url": "https://opencollective.com/unified"
2224 },
23− "repository": "https://github.com/wooorm/remark-validate-links",
24− "bugs": "https://github.com/wooorm/remark-validate-links/issues",
25− "author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",
25+ "author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
2626 "contributors": [
27− "Titus Wormer <tituswormer@gmail.com> (http://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>"
2834 ],
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+ },
2939 "files": [
40+ "lib/",
3041 "index.js"
3142 ],
43+ "dependencies": {
44+ "github-slugger": "^1.0.0",
45+ "hosted-git-info": "^3.0.0",
46+ "mdast-util-to-string": "^1.0.0",
47+ "propose": "0.0.5",
48+ "to-vfile": "^6.0.0",
49+ "trough": "^1.0.0",
50+ "unist-util-visit": "^2.0.0",
51+ "xtend": "^4.0.0"
52+ },
3253 "devDependencies": {
33− "execa": "^0.6.0",
34− "nyc": "^10.0.0",
35− "remark": "^7.0.0",
36− "remark-cli": "^3.0.0",
37− "remark-preset-wooorm": "^2.0.0",
38− "strip-ansi": "^3.0.1",
39− "tape": "^4.0.0",
40− "xo": "^0.18.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"
4164 },
4265 "scripts": {
43− "build-md": "remark *.md -qfo",
44− "build": "npm run build-md",
45− "lint": "xo",
46− "test-api": "node test/index.js",
66+ "format": "remark . -qfo --ignore-pattern test/ && prettier . --write && xo --fix",
67+ "test-api": "node test",
4768 "test-coverage": "nyc --reporter lcov tape test/index.js",
48− "test": "npm run build && npm run lint && npm run test-coverage"
49− },
50− "xo": {
51− "space": true,
52− "esnext": false,
53− "rules": {
54− "no-eq-null": "off",
55− "eqeqeq": "off",
56− "guard-for-in": "off",
57− "max-lines": "off"
58− }
69+ "test": "npm run format && npm run test-coverage"
5970 },
6071 "nyc": {
6172 "check-coverage": true,
@@ -63,7 +74,27 @@
6374 "functions": 100,
6475 "branches": 100
6576 },
77+ "prettier": {
78+ "tabWidth": 2,
79+ "useTabs": false,
80+ "singleQuote": true,
81+ "bracketSpacing": false,
82+ "semi": false,
83+ "trailingComma": "none"
84+ },
85+ "xo": {
86+ "prettier": true,
87+ "esnext": false,
88+ "rules": {
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"
93+ }
94+ },
6695 "remarkConfig": {
67− "plugins": ["preset-wooorm"]
96+ "plugins": [
97+ "preset-wooorm"
98+ ]
6899 }
69100}
readme.md+230−71
@@ -1,123 +1,254 @@
1−# remark-validate-links [![Build Status][build-badge]][build-status] [![Coverage Status][coverage-badge]][coverage-status] [![Chat][chat-badge]][chat]
1+# remark-validate-links
22
3−[**remark**][remark] plug-in to validate if links to headings and files
4−in markdown point to existing things.
3+[![Build][build-badge]][build]
4+[![Coverage][coverage-badge]][coverage]
5+[![Downloads][downloads-badge]][downloads]
6+[![Size][size-badge]][size]
7+[![Sponsors][sponsors-badge]][collective]
8+[![Backers][backers-badge]][collective]
9+[![Chat][chat-badge]][chat]
10+
11+[**remark**][remark] plugin to validate that Markdown links and images reference
12+existing local files and headings.
513
614For example, this document does not have a heading named `Hello`.
7−So if I link to that (`[welcome](#hello)`), this plug-in will warn
8−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.
920
10−In addition, when I link to a heading in another document
11−(`examples/foo.md#hello`), if this file exists but the heading does not,
12−or if the file does not exist, this plug-in will also warn.
21+Linking to other files, such as `license` or `index.js` (when they exist) is
22+fine.
1323
14−Linking to other files, such as `LICENSE` or `index.js` (when they exist)
15−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]).
1627
17−## Table of Contents
28+## Contents
1829
19−* [Installation](#installation)
20−* [Command line](#command-line)
21−* [Programmatic](#programmatic)
30+* [Install](#install)
31+* [Use](#use)
32+ * [CLI](#cli)
33+ * [API](#api)
2234* [Configuration](#configuration)
2335* [Integration](#integration)
36+* [Security](#security)
2437* [Related](#related)
38+* [Contribute](#contribute)
2539* [License](#license)
2640
27−## Installation
41+## Install
2842
2943[npm][]:
3044
31−```bash
45+```sh
3246npm install remark-validate-links
3347```
3448
35−## Command line
49+## Use
3650
37−![Example of how remark-validate-links looks on screen][screenshot]
51+### CLI
3852
39−Use **remark-validate-links** together with [**remark**][remark]:
53+Use `remark-validate-links` together with [**remark**][remark]:
4054
4155```bash
42−npm install --global remark remark-validate-links
56+npm install --global remark-cli remark-validate-links
4357```
4458
4559Let’s say `readme.md` is this document, and `example.md` looks as follows:
4660
47−```md
61+```markdown
4862# Hello
4963
5064Read more [whoops, this does not exist](#world).
5165
5266This doesn’t exist either [whoops!](readme.md#foo).
5367
54−But this does exist: [LICENSE](LICENSE).
68+But this does exist: [license](license).
5569
5670So does this: [README](readme.md#installation).
5771```
5872
59−Then, to run **remark-validate-links** on `example.md` and `readme.md`:
73+Now, running `remark -u validate-links .` yields:
6074
61−```bash
62−remark -u remark-validate-links example.md
63−#
64−# Yields:
65−#
66−# example.md
67−# 3:11 warning Link to unknown heading: `world`
68−# 5:27 warning Link to unknown heading in `readme.md`: `foo`
69−#
70−# ✖ 2 problems (0 errors, 2 warnings)
75+```text
76+example.md
77+ 3:11-3:48 warning Link to unknown heading: `world` missing-heading remark-validate-links
78+ 5:27-5:51 warning Link to unknown heading in `readme.md`: `foo` missing-heading-in-file remark-validate-links
79+
80+readme.md: no issues found
81+
82+⚠ 2 warnings
7183```
7284
73−## 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.
7487
75−This plug-in is **not** available on the API of remark.
88+### API
7689
77−## Configuration
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.
7893
79−You can pass a `repository`, containing anything `package.json`s
80−[`repository`][package-repository] can handle. If this is omitted,
81−**remark-validate-links** will try the `package.json` in your
82−current working directory.
94+Say we have the following file, `example.md`:
8395
84−```bash
96+```markdown
97+# Alpha
98+
99+Links are checked:
100+
101+This [exists](#alpha).
102+This [one does not](#does-not).
103+
104+# Bravo
105+
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:
110+
111+[alpha]: #alpha
112+[charlie]: #charlie
113+
114+References w/o definitions are not checked: [delta]
115+```
116+
117+And our script, `example.js`, looks as follows:
118+
119+```js
120+var vfile = require('to-vfile')
121+var report = require('vfile-reporter')
122+var remark = require('remark')
123+var links = require('remark-validate-links')
124+
125+remark()
126+ .use(links)
127+ .process(vfile.readSync('example.md'), function (err, file) {
128+ console.error(report(err || file))
129+ })
130+```
131+
132+Now, running `node example` yields:
133+
134+```markdown
135+example.md
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
139+
140+⚠ 3 warnings
141+```
142+
143+(Note that `readme.md#nosuchheading` is not warned about, because the API
144+does not check headings in other Markdown files).
145+
146+## Configuration
147+
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
85164remark --use 'validate-links=repository:"foo/bar"' example.md
86165```
87166
88−When a repository is given or detected, links to GitHub are normalized
89−to the file-system. For example,
90−`https://github.com/foo/bar/blob/master/example.md` becomes `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.
91171
92172You can define this repository in [configuration files][cli] too.
93173An example `.remarkrc` file could look as follows:
94174
95175```json
96176{
97− "plugins": {
98− "validate-links": {
99− "repository": "foo/bar"
100− }
101− }
177+ "plugins": [
178+ [
179+ "validate-links",
180+ {
181+ "repository": "foo/bar"
182+ }
183+ ]
184+ ]
185+}
186+```
187+
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
102214}
103215```
104216
105217## Integration
106218
107−**remark-validate-links** can detect anchors on nodes through
108−several properties on nodes:
219+`remark-validate-links` can detect anchors on nodes through several properties
220+on nodes:
109221
110−* `node.data.htmlAttributes.name` — Used by [`remark-html`][remark-html]
111− to create a `name` attribute, which anchors can link to;
112−* `node.data.htmlAttributes.id` — Used by [`remark-html`][remark-html]
113− to create an `id` attribute, which anchors can link to;
222+* `node.data.hProperties.name` — Used by [`remark-html`][remark-html]
223+ to create a `name` attribute, which anchors can link to
224+* `node.data.hProperties.id` — Used by [`remark-html`][remark-html]
225+ to create an `id` attribute, which anchors can link to
114226* `node.data.id` — Used, in the future, by other tools to signal
115− unique identifiers on nodes.
227+ unique identifiers on nodes
228+
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.
116237
117238## Related
118239
119−* [`wooorm/remark-lint`][remark-lint]
120− — Markdown code style linter.
240+* [`remark-lint`][remark-lint] — Markdown code style linter
241+* [`remark-lint-no-dead-urls`][no-dead-urls] — Ensure external links are alive
242+
243+## Contribute
244+
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.
248+
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.
121252
122253## License
123254
@@ -125,32 +256,60 @@ several properties on nodes:
125256
126257<!-- Definitions -->
127258
128−[build-badge]: https://img.shields.io/travis/wooorm/remark-validate-links.svg
259+[build-badge]: https://img.shields.io/travis/remarkjs/remark-validate-links/main.svg
129260
130−[build-status]: https://travis-ci.org/wooorm/remark-validate-links
261+[build]: https://travis-ci.org/remarkjs/remark-validate-links
131262
132−[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/remark-validate-links.svg
263+[coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-validate-links.svg
133264
134−[coverage-status]: https://codecov.io/github/wooorm/remark-validate-links
265+[coverage]: https://codecov.io/github/remarkjs/remark-validate-links
135266
136−[chat-badge]: https://img.shields.io/gitter/room/wooorm/remark.svg
267+[downloads-badge]: https://img.shields.io/npm/dm/remark-validate-links.svg
137268
138−[chat]: https://gitter.im/wooorm/remark
269+[downloads]: https://www.npmjs.com/package/remark-validate-links
139270
140−[license]: LICENSE
271+[size-badge]: https://img.shields.io/bundlephobia/minzip/remark-validate-links.svg
141272
142−[author]: http://wooorm.com
273+[size]: https://bundlephobia.com/result?p=remark-validate-links
274+
275+[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
276+
277+[backers-badge]: https://opencollective.com/unified/backers/badge.svg
278+
279+[collective]: https://opencollective.com/unified
280+
281+[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
282+
283+[chat]: https://github.com/remarkjs/remark/discussions
143284
144285[npm]: https://docs.npmjs.com/cli/install
145286
146−[remark]: https://github.com/wooorm/remark
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
147292
148−[remark-lint]: https://github.com/wooorm/remark-lint
293+[coc]: https://github.com/remarkjs/.github/blob/HEAD/code-of-conduct.md
149294
150−[remark-html]: https://github.com/wooorm/remark-html
295+[license]: license
151296
152−[screenshot]: https://cdn.rawgit.com/wooorm/remark-validate-links/master/screenshot.png#1
297+[author]: https://wooorm.com
298+
299+[remark]: https://github.com/remarkjs/remark
300+
301+[cli]: https://github.com/remarkjs/remark/tree/HEAD/packages/remark-cli#readme
302+
303+[remark-lint]: https://github.com/remarkjs/remark-lint
304+
305+[remark-html]: https://github.com/remarkjs/remark-html
306+
307+[no-dead-urls]: https://github.com/davidtheclark/remark-lint-no-dead-urls
308+
309+[no-undef-refs]: https://github.com/remarkjs/remark-lint/tree/master/packages/remark-lint-no-undefined-references
153310
154311[package-repository]: https://docs.npmjs.com/files/package.json#repository
155312
156−[cli]: https://github.com/wooorm/remark/tree/master/packages/remark-cli#readme
313+[cwd]: https://github.com/vfile/vfile#vfilecwd
314+
315+[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
screenshot.pngdeleted

Binary file not shown.

test/fixtures/bitbucket.mdnew file+67
@@ -0,0 +1,67 @@
1+# Hello
2+
3+This is a valid relative heading [link](#markdown-header-hello).
4+
5+This is an invalid relative heading [link](#markdown-header-world).
6+
7+This is an ignored hash [link](#world).
8+
9+## Files
10+
11+This is a valid relative file [link](https://bitbucket.org/wooorm/test/src/main/examples/bitbucket.md).
12+
13+So is this [link](https://bitbucket.org/wooorm/test/src/foo-bar/examples/bitbucket.md).
14+
15+And this [link](./examples/bitbucket.md).
16+
17+And this [link](examples/bitbucket.md).
18+
19+This is a valid external [file](../index.js).
20+
21+This is an invalid relative file [link](https://bitbucket.org/wooorm/test/src/main/examples/world.md).
22+
23+So is this [link](https://bitbucket.org/wooorm/test/src/foo-bar/examples/world.md).
24+
25+And this [link](./examples/world.md).
26+
27+And this [link](examples/world.md).
28+
29+## Combination
30+
31+Valid: [a](./examples/bitbucket.md#markdown-header-hello).
32+
33+Valid: [b](examples/bitbucket.md#markdown-header-hello).
34+
35+Valid: [c](https://bitbucket.org/wooorm/test/src/main/examples/bitbucket.md#markdown-header-hello).
36+
37+Valid: [d](https://bitbucket.org/wooorm/test/src/foo-bar/examples/bitbucket.md#markdown-header-hello).
38+
39+Invalid: [e](./examples/bitbucket.md#markdown-header-world).
40+
41+Invalid: [f](examples/bitbucket.md#markdown-header-world).
42+
43+Invalid: [g](https://bitbucket.org/wooorm/test/src/main/examples/bitbucket.md#markdown-header-world).
44+
45+Invalid: [h](https://bitbucket.org/wooorm/test/src/foo-bar/examples/bitbucket.md#markdown-header-world).
46+
47+Invalid: [i](./examples/world.md#markdown-header-hello).
48+
49+Invalid: [j](examples/world.md#markdown-header-hello).
50+
51+Invalid: [k](https://bitbucket.org/wooorm/test/src/main/examples/world.md#markdown-header-hello).
52+
53+Invalid: [l](https://bitbucket.org/wooorm/test/src/foo-bar/examples/world.md#markdown-header-hello).
54+
55+This is an ignored hash [j](https://bitbucket.org/wooorm/test/src/foo-bar/examples/bitbucket.md#world).
56+
57+## External
58+
59+These are all invalid, because they do not link to Bitbucket.
60+
61+Valid: [a](irc://foo).
62+
63+Valid: [b](http://example.com).
64+
65+Valid: [b](http://example.com/foo/bar/baz).
66+
67+Valid: [b](http://github.com/wooorm/test/blob/foo-bar/examples/world.md#markdown-header-hello).
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.mdnew file+39
@@ -0,0 +1,39 @@
1+# Hello
2+
3+This is a valid relative heading [link](#markdown-header-hello).
4+
5+This is an invalid relative heading [link](#markdown-header-world).
6+
7+## Files
8+
9+This is a valid relative file [link](https://bitbucket.org/wooorm/test/src/main/bitbucket.md).
10+
11+So is this [link](https://bitbucket.org/wooorm/test/src/foo-bar/bitbucket.md).
12+
13+And this [link](../bitbucket.md).
14+
15+This is an invalid relative file [link](https://bitbucket.org/wooorm/test/src/main/world.md).
16+
17+So is this [link](https://bitbucket.org/wooorm/test/src/foo-bar/world.md).
18+
19+And this [link](../world.md).
20+
21+## Combination
22+
23+Valid: [a](../bitbucket.md#markdown-header-hello).
24+
25+Valid: [b](https://bitbucket.org/wooorm/test/src/main/bitbucket.md#markdown-header-hello).
26+
27+Valid: [c](https://bitbucket.org/wooorm/test/src/foo-bar/bitbucket.md#markdown-header-hello).
28+
29+Invalid: [d](../bitbucket.md#markdown-header-world).
30+
31+Invalid: [e](https://bitbucket.org/wooorm/test/src/main/bitbucket.md#markdown-header-world).
32+
33+Invalid: [f](https://bitbucket.org/wooorm/test/src/foo-bar/bitbucket.md#markdown-header-world).
34+
35+Invalid: [g](../world.md#markdown-header-hello).
36+
37+Invalid: [h](https://bitbucket.org/wooorm/test/src/main/world.md#markdown-header-hello).
38+
39+Invalid: [i](https://bitbucket.org/wooorm/test/src/foo-bar/world.md#markdown-header-hello).
test/fixtures/examples/example.jsnew file+1
@@ -0,0 +1 @@
1+console.log('Hello world!')
test/fixtures/examples/example.mddeleted−39
@@ -1,39 +0,0 @@
1−# Hello
2−
3−This is a valid relative heading [link](#hello).
4−
5−This is an invalid relative heading [link](#world).
6−
7−## Files
8−
9−This is a valid relative file [link](https://github.com/wooorm/test/blob/master/example.md).
10−
11−So is this [link](https://github.com/wooorm/test/blob/foo-bar/example.md).
12−
13−And this [link](../example.md).
14−
15−This is an invalid relative file [link](https://github.com/wooorm/test/blob/master/world.md).
16−
17−So is this [link](https://github.com/wooorm/test/blob/foo-bar/world.md).
18−
19−And this [link](../world.md).
20−
21−## Combination
22−
23−Valid: [a](../example.md#hello).
24−
25−Valid: [b](https://github.com/wooorm/test/blob/master/example.md#hello).
26−
27−Valid: [c](https://github.com/wooorm/test/blob/foo-bar/example.md#hello).
28−
29−Invalid: [d](../example.md#world).
30−
31−Invalid: [e](https://github.com/wooorm/test/blob/master/example.md#world).
32−
33−Invalid: [f](https://github.com/wooorm/test/blob/foo-bar/example.md#world).
34−
35−Invalid: [g](../world.md#hello).
36−
37−Invalid: [h](https://github.com/wooorm/test/blob/master/world.md#hello).
38−
39−Invalid: [i](https://github.com/wooorm/test/blob/foo-bar/world.md#hello).
test/fixtures/examples/github.mdnew file+39
@@ -0,0 +1,39 @@
1+# Hello
2+
3+This is a valid relative heading [link](#hello).
4+
5+This is an invalid relative heading [link](#world).
6+
7+## Files
8+
9+This is a valid relative file [link](https://github.com/wooorm/test/blob/main/github.md).
10+
11+So is this [link](https://github.com/wooorm/test/blob/foo-bar/github.md).
12+
13+And this [link](../github.md).
14+
15+This is an invalid relative file [link](https://github.com/wooorm/test/blob/main/world.md).
16+
17+So is this [link](https://github.com/wooorm/test/blob/foo-bar/world.md).
18+
19+And this [link](../world.md).
20+
21+## Combination
22+
23+Valid: [a](../github.md#hello).
24+
25+Valid: [b](https://github.com/wooorm/test/blob/main/github.md#hello).
26+
27+Valid: [c](https://github.com/wooorm/test/blob/foo-bar/github.md#hello).
28+
29+Invalid: [d](../github.md#world).
30+
31+Invalid: [e](https://github.com/wooorm/test/blob/main/github.md#world).
32+
33+Invalid: [f](https://github.com/wooorm/test/blob/foo-bar/github.md#world).
34+
35+Invalid: [g](../world.md#hello).
36+
37+Invalid: [h](https://github.com/wooorm/test/blob/main/world.md#hello).
38+
39+Invalid: [i](https://github.com/wooorm/test/blob/foo-bar/world.md#hello).
test/fixtures/examples/gitlab.mdnew file+39
@@ -0,0 +1,39 @@
1+# Hello
2+
3+This is a valid relative heading [link](#hello).
4+
5+This is an invalid relative heading [link](#world).
6+
7+## Files
8+
9+This is a valid relative file [link](https://gitlab.com/wooorm/test/blob/main/gitlab.md).
10+
11+So is this [link](https://gitlab.com/wooorm/test/blob/foo-bar/gitlab.md).
12+
13+And this [link](../gitlab.md).
14+
15+This is an invalid relative file [link](https://gitlab.com/wooorm/test/blob/main/world.md).
16+
17+So is this [link](https://gitlab.com/wooorm/test/blob/foo-bar/world.md).
18+
19+And this [link](../world.md).
20+
21+## Combination
22+
23+Valid: [a](../gitlab.md#hello).
24+
25+Valid: [b](https://gitlab.com/wooorm/test/blob/main/gitlab.md#hello).
26+
27+Valid: [c](https://gitlab.com/wooorm/test/blob/foo-bar/gitlab.md#hello).
28+
29+Invalid: [d](../gitlab.md#world).
30+
31+Invalid: [e](https://gitlab.com/wooorm/test/blob/main/gitlab.md#world).
32+
33+Invalid: [f](https://gitlab.com/wooorm/test/blob/foo-bar/gitlab.md#world).
34+
35+Invalid: [g](../world.md#hello).
36+
37+Invalid: [h](https://gitlab.com/wooorm/test/blob/main/world.md#hello).
38+
39+Invalid: [i](https://gitlab.com/wooorm/test/blob/foo-bar/world.md#hello).
test/fixtures/examples/image with space.jpgnew file

Binary file not shown.

test/fixtures/examples/image.jpgnew file

Binary file not shown.

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/example.md → test/fixtures/github.mdrenamed+22−14
@@ -6,17 +6,21 @@ 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/example.md).
9+This is a valid relative file [link](https://github.com/wooorm/test/blob/main/examples/github.md).
1010
11−So is this [link](https://github.com/wooorm/test/blob/foo-bar/examples/example.md).
11+This is a valid absolute file [link](/wooorm/test/blob/main/examples/github.md).
1212
13−And this [link](./examples/example.md).
13+So is this [link](https://github.com/wooorm/test/blob/foo-bar/examples/github.md).
1414
15−And this [link](examples/example.md).
15+And this [link](./examples/github.md).
16+
17+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
@@ -26,27 +30,27 @@ And this [link](examples/world.md).
2630
2731## Combination
2832
29−Valid: [a](./examples/example.md#hello).
33+Valid: [a](./examples/github.md#hello).
3034
31−Valid: [b](examples/example.md#hello).
35+Valid: [b](examples/github.md#hello).
3236
33−Valid: [c](https://github.com/wooorm/test/blob/master/examples/example.md#hello).
37+Valid: [c](https://github.com/wooorm/test/blob/main/examples/github.md#hello).
3438
35−Valid: [d](https://github.com/wooorm/test/blob/foo-bar/examples/example.md#hello).
39+Valid: [d](https://github.com/wooorm/test/blob/foo-bar/examples/github.md#hello).
3640
37−Invalid: [e](./examples/example.md#world).
41+Invalid: [e](./examples/github.md#world).
3842
39−Invalid: [f](examples/example.md#world).
43+Invalid: [f](examples/github.md#world).
4044
41−Invalid: [g](https://github.com/wooorm/test/blob/master/examples/example.md#world).
45+Invalid: [g](https://github.com/wooorm/test/blob/main/examples/github.md#world).
4246
43−Invalid: [h](https://github.com/wooorm/test/blob/foo-bar/examples/example.md#world).
47+Invalid: [h](https://github.com/wooorm/test/blob/foo-bar/examples/github.md#world).
4448
4549Invalid: [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.mdnew file+67
@@ -0,0 +1,67 @@
1+# Hello
2+
3+This is a valid relative heading [link](#hello).
4+
5+This is an invalid relative heading [link](#world).
6+
7+## Files
8+
9+This is a valid relative file [link](https://gitlab.com/wooorm/test/blob/main/examples/gitlab.md).
10+
11+So is this [link](https://gitlab.com/wooorm/test/blob/foo-bar/examples/gitlab.md).
12+
13+And this [link](./examples/gitlab.md).
14+
15+And this [link](examples/gitlab.md).
16+
17+This is a valid external [file](../index.js).
18+
19+This is an invalid relative file [link](https://gitlab.com/wooorm/test/blob/main/examples/world.md).
20+
21+So is this [link](https://gitlab.com/wooorm/test/blob/foo-bar/examples/world.md).
22+
23+And this [link](./examples/world.md).
24+
25+And this [link](examples/world.md).
26+
27+## Combination
28+
29+Valid: [a](./examples/gitlab.md#hello).
30+
31+Valid: [b](examples/gitlab.md#hello).
32+
33+Valid: [c](https://gitlab.com/wooorm/test/blob/main/examples/gitlab.md#hello).
34+
35+Valid: [d](https://gitlab.com/wooorm/test/blob/foo-bar/examples/gitlab.md#hello).
36+
37+Invalid: [e](./examples/gitlab.md#world).
38+
39+Invalid: [f](examples/gitlab.md#world).
40+
41+Invalid: [g](https://gitlab.com/wooorm/test/blob/main/examples/gitlab.md#world).
42+
43+Invalid: [h](https://gitlab.com/wooorm/test/blob/foo-bar/examples/gitlab.md#world).
44+
45+Invalid: [i](./examples/world.md#hello).
46+
47+Invalid: [j](examples/world.md#hello).
48+
49+Invalid: [k](https://gitlab.com/wooorm/test/blob/main/examples/world.md#hello).
50+
51+Invalid: [l](https://gitlab.com/wooorm/test/blob/foo-bar/examples/world.md#hello).
52+
53+## External
54+
55+These are all invalid, because they do not link to GitLab.
56+
57+Valid: [a](irc://foo).
58+
59+Valid: [b](http://example.com).
60+
61+Valid: [b](http://example.com/foo/bar/baz).
62+
63+Valid: [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.mdnew file+39
@@ -0,0 +1,39 @@
1+# Image references
2+
3+<!-- Valid: -->
4+
5+Relative ![image](./examples/image.jpg)
6+
7+No `./` in ![image](examples/image.jpg)
8+
9+Absolute ![image](https://github.com/wooorm/test/blob/main/examples/image.jpg)
10+
11+Relative ![image reference][rel]
12+
13+Absolute ![image reference][abs]
14+
15+Relative with whitespace ![image reference][rel-whitespace]
16+
17+<!-- Invalid: -->
18+
19+Relative ![missing image](./examples/missing.jpg)
20+
21+No `./` in ![image](examples/missing.jpg)
22+
23+Absolute ![missing image](https://github.com/wooorm/test/blob/main/examples/missing.jpg)
24+
25+Relative ![missing image reference][rel-missing]
26+
27+Absolute ![missing image reference][abs-missing]
28+
29+<!-- Definitions: -->
30+
31+[rel]: ./examples/image.jpg
32+
33+[abs]: https://github.com/wooorm/test/blob/main/examples/image.jpg
34+
35+[rel-missing]: ./examples/missing.jpg
36+
37+[abs-missing]: https://github.com/wooorm/test/blob/main/examples/missing.jpg
38+
39+[rel-whitespace]: "./examples/image with space.jpg"
test/fixtures/line-links.mdnew file+9
@@ -0,0 +1,9 @@
1+# Source Code Link
2+
3+Link to [a line](./examples/example.js#L1)
4+
5+Link to [a line in a missing file](./examples/missing.js#L1)
6+
7+[a](https://github.com/wooorm/test/blob/main/examples/example.js#L1).
8+
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/suggestions.md+2−2
@@ -4,8 +4,8 @@ This should suggest: [link](#helloo).
44
55## Files
66
7−So should this: [k](example.md#fiiiles).
7+So should this: [k](github.md#fiiiles).
88
9−##
9+##
1010
1111An empty header.
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+1276−271
@@ -1,297 +1,1302 @@
1−'use strict';
1+'use strict'
22
3−var fs = require('fs');
4−var path = require('path');
5−var test = require('tape');
6−var execa = require('execa');
7−var remark = require('remark');
8−var strip = require('strip-ansi');
9−var links = require('..');
3+var fs = require('fs')
4+var path = require('path')
5+var childProcess = require('child_process')
6+var test = require('tape')
7+var vfile = require('to-vfile')
8+var remark = require('remark')
9+var strip = require('strip-ansi')
10+var rimraf = require('rimraf')
11+var sort = require('./sort')
12+var links = require('..')
1013
11−process.chdir(path.resolve(process.cwd(), 'test', 'fixtures'));
14+process.chdir(path.resolve(process.cwd(), 'test', 'fixtures'))
1215
1316test.onFinish(function () {
14− process.chdir(path.resolve(process.cwd(), '..', '..'));
15−});
17+ process.chdir(path.resolve(process.cwd(), '..', '..'))
18+})
1619
17−var bin = path.join('..', '..', 'node_modules', '.bin', 'remark');
18−
19−var source = ' remark-validate-links remark-validate-links';
20+var bin = path.join('..', '..', 'node_modules', '.bin', 'remark')
2021
2122test('remark-validate-links', function (t) {
22− t.plan(8);
23−
24− t.throws(
25− function () {
26− remark().use(links).freeze();
27− },
28− /Error: remark-validate-links only works on the CLI/,
29− 'should throw an error when not on the CLI'
30− );
31−
32− t.test('should ignore unfound files', function (st) {
33− st.plan(2);
34−
35− execa.stderr(bin, [
36− '--no-config',
37− '--no-ignore',
38− '--use',
39− '../../index',
40− 'definitions.md',
41− 'FOOOO'
42− ]).catch(function (err) {
43− st.equal(err.code, 1, 'should exit with `1`');
44− st.equal(
45− strip(err.stderr),
23+ t.test('should work on the API', function (st) {
24+ st.plan(1)
25+
26+ remark()
27+ .use(links)
28+ .use(sort)
29+ .process(vfile.readSync('github.md'), function (err, file) {
30+ st.deepEqual(
31+ [err].concat(file.messages.map(String)),
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+ ],
40+ 'should report messages'
41+ )
42+ })
43+ })
44+
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
60+ )
61+
62+ function onexec(err, stdout, stderr) {
63+ st.deepEqual(
64+ [err, strip(stderr)],
4665 [
47− 'FOOOO',
48− ' 1:1 error No such file or directory',
49− '',
50− 'definitions.md',
51− ' 5:12-5:21 warning Link to unknown heading: `world`' + source,
52− '',
53− '2 messages (✖ 1 error, ⚠ 1 warning)',
54− ''
55− ].join('\n'),
56− 'should report'
57− );
58− });
59− });
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+ }
78+ })
79+
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,
102+ [
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
130+ )
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+ }
148+ })
149+
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,
173+ [
174+ 'FOOOO',
175+ ' 1:1 error No such file or directory',
176+ '',
177+ 'definitions.md',
178+ ' 10:1-10:18 warning Link to unknown heading: `world` missing-heading remark-validate-links',
179+ '',
180+ '2 messages (✖ 1 error, ⚠ 1 warning)',
181+ ''
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
204+ )
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+ }
213+ })
214+
215+ t.test('should work with stdin', function (st) {
216+ st.plan(1)
217+
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)],
236+ [
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'
247+ )
248+ }
249+ })
60250
61251 t.test('should work when not all files are given', function (st) {
62− st.plan(1);
63−
64− execa.stderr(bin, [
65− '--no-config',
66− '--no-ignore',
67− '--use',
68− '../../index',
69− 'example.md'
70− ]).then(function (stderr) {
71− st.equal(
72− strip(stderr),
252+ st.plan(1)
253+
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)],
73271 [
74− 'example.md',
75− ' 5:37-5:51 warning Link to unknown heading: `world` ' + source,
76− ' 23:10-23:37 warning Link to unknown file: `examples/world.md` ' + source,
77− ' 25:10-25:35 warning Link to unknown file: `examples/world.md` ' + source,
78− ' 37:10-37:42 warning Link to unknown heading in `examples/example.md`: `world`' + source,
79− ' 39:10-39:40 warning Link to unknown heading in `examples/example.md`: `world`' + source,
80− ' 45:10-45:40 warning Link to unknown file: `examples/world.md` ' + source,
81− ' 45:10-45:40 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
82− ' 47:10-47:38 warning Link to unknown file: `examples/world.md` ' + source,
83− ' 47:10-47:38 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
84− '',
85− '⚠ 9 warnings'
86− ].join('\n'),
87− 'should report'
88− );
89− });
90− });
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'
290+ )
291+ }
292+ })
91293
92294 t.test('should work when all files are given', function (st) {
93− st.plan(1);
94−
95− execa.stderr(bin, [
96− '--no-config',
97− '--no-ignore',
98− '--use',
99− '../../index',
100− 'example.md',
101− 'examples/example.md'
102− ]).then(function (stderr) {
103− st.equal(
104− strip(stderr),
295+ st.plan(1)
296+
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)],
105315 [
106− 'example.md',
107− ' 5:37-5:51 warning Link to unknown heading: `world` ' + source,
108− ' 23:10-23:37 warning Link to unknown file: `examples/world.md` ' + source,
109− ' 25:10-25:35 warning Link to unknown file: `examples/world.md` ' + source,
110− ' 37:10-37:42 warning Link to unknown heading in `examples/example.md`: `world`' + source,
111− ' 39:10-39:40 warning Link to unknown heading in `examples/example.md`: `world`' + source,
112− ' 45:10-45:40 warning Link to unknown file: `examples/world.md` ' + source,
113− ' 45:10-45:40 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
114− ' 47:10-47:38 warning Link to unknown file: `examples/world.md` ' + source,
115− ' 47:10-47:38 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
116− '',
117− 'examples/example.md',
118− ' 5:37-5:51 warning Link to unknown heading: `world` ' + source,
119− ' 19:10-19:29 warning Link to unknown file: `world.md` ' + source,
120− ' 29:10-29:34 warning Link to unknown heading in `example.md`: `world` ' + source,
121− ' 35:10-35:32 warning Link to unknown file: `world.md` ' + source,
122− ' 35:10-35:32 warning Link to unknown heading in `world.md`: `hello` ' + source,
123− '',
124− '⚠ 14 warnings'
125− ].join('\n'),
126− 'should report'
127− );
128− });
129− });
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'
341+ )
342+ }
343+ })
130344
131345 t.test('should work with definitions', function (st) {
132− st.plan(1);
133−
134− execa.stderr(bin, [
135− '--no-config',
136− '--no-ignore',
137− '--use',
138− '../../index',
139− 'definitions.md'
140− ]).then(function (stderr) {
141− st.equal(
142− strip(stderr),
346+ st.plan(1)
347+
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)],
143365 [
144− 'definitions.md',
145− ' 5:12-5:21 warning Link to unknown heading: `world`' + source,
146− '',
147− '⚠ 1 warning'
148− ].join('\n'),
149− 'should report'
150− );
151− });
152− });
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'
376+ )
377+ }
378+ })
153379
154380 t.test('should work on GitHub URLs when given a repo', function (st) {
155− st.plan(1);
156−
157− execa.stderr(bin, [
158− '--no-config',
159− '--no-ignore',
160− '--use',
161− '../../index=repository:"wooorm/test"',
162− 'example.md',
163− 'examples/example.md'
164− ]).then(function (stderr) {
165− st.equal(
166− strip(stderr),
381+ st.plan(1)
382+
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
396+ )
397+
398+ function onexec(err, stdout, stderr) {
399+ st.deepEqual(
400+ [err, strip(stderr)],
401+ [
402+ null,
403+ [
404+ 'examples/github.md',
405+ ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading 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',
418+ '',
419+ 'github.md',
420+ ' 5:37-5:51 warning Link to unknown heading: `world` missing-heading 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',
438+ '',
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
460+ )
461+ }
462+ }
463+
464+ function onremote(err) {
465+ if (err) {
466+ clean()
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+ )
483+ }
484+ }
485+
486+ function onexec(err, stdout, stderr) {
487+ clean()
488+ st.deepEqual(
489+ [err, strip(stderr)],
167490 [
168− 'example.md',
169− ' 5:37-5:51 warning Link to unknown heading: `world` ' + source,
170− ' 19:34-19:102 warning Link to unknown file: `examples/world.md` ' + source,
171− ' 21:12-21:81 warning Link to unknown file: `examples/world.md` ' + source,
172− ' 23:10-23:37 warning Link to unknown file: `examples/world.md` ' + source,
173− ' 25:10-25:35 warning Link to unknown file: `examples/world.md` ' + source,
174− ' 37:10-37:42 warning Link to unknown heading in `examples/example.md`: `world`' + source,
175− ' 39:10-39:40 warning Link to unknown heading in `examples/example.md`: `world`' + source,
176− ' 41:10-41:83 warning Link to unknown heading in `examples/example.md`: `world`' + source,
177− ' 43:10-43:84 warning Link to unknown heading in `examples/example.md`: `world`' + source,
178− ' 45:10-45:40 warning Link to unknown file: `examples/world.md` ' + source,
179− ' 45:10-45:40 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
180− ' 47:10-47:38 warning Link to unknown file: `examples/world.md` ' + source,
181− ' 47:10-47:38 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
182− ' 49:10-49:81 warning Link to unknown file: `examples/world.md` ' + source,
183− ' 49:10-49:81 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
184− ' 51:10-51:82 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
185− ' 51:10-51:82 warning Link to unknown file: `examples/world.md` ' + source,
186− '',
187− 'examples/example.md',
188− ' 5:37-5:51 warning Link to unknown heading: `world` ' + source,
189− ' 15:34-15:93 warning Link to unknown file: `world.md` ' + source,
190− ' 17:12-17:72 warning Link to unknown file: `world.md` ' + source,
191− ' 19:10-19:29 warning Link to unknown file: `world.md` ' + source,
192− ' 29:10-29:34 warning Link to unknown heading in `example.md`: `world` ' + source,
193− ' 31:10-31:74 warning Link to unknown heading in `example.md`: `world` ' + source,
194− ' 33:10-33:75 warning Link to unknown heading in `example.md`: `world` ' + source,
195− ' 35:10-35:32 warning Link to unknown file: `world.md` ' + source,
196− ' 35:10-35:32 warning Link to unknown heading in `world.md`: `hello` ' + source,
197− ' 37:10-37:72 warning Link to unknown file: `world.md` ' + source,
198− ' 37:10-37:72 warning Link to unknown heading in `world.md`: `hello` ' + source,
199− ' 39:10-39:73 warning Link to unknown heading in `world.md`: `hello` ' + source,
200− ' 39:10-39:73 warning Link to unknown file: `world.md` ' + source,
201− '',
202− '⚠ 30 warnings'
203− ].join('\n'),
204− 'should report'
205− );
206− });
207− });
208−
209− t.test('should work on GitHub URLs when with package.json', function (st) {
210− st.plan(1);
211−
212− /* `cwd` is moved to `test/fixtures`. */
213− fs.writeFileSync('./package.json', JSON.stringify({
214− repository: 'wooorm/test'
215− }, 0, 2));
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+ }
216535
217536 function clean() {
218− fs.unlinkSync('./package.json');
219− }
220−
221− execa.stderr(bin, [
222− '--no-config',
223− '--no-ignore',
224− '--use',
225− '../..',
226− 'example.md',
227− 'examples/example.md'
228− ]).then(function (stderr) {
229− clean();
230− st.equal(
231− strip(stderr),
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)],
232690 [
233− 'example.md',
234− ' 5:37-5:51 warning Link to unknown heading: `world` ' + source,
235− ' 19:34-19:102 warning Link to unknown file: `examples/world.md` ' + source,
236− ' 21:12-21:81 warning Link to unknown file: `examples/world.md` ' + source,
237− ' 23:10-23:37 warning Link to unknown file: `examples/world.md` ' + source,
238− ' 25:10-25:35 warning Link to unknown file: `examples/world.md` ' + source,
239− ' 37:10-37:42 warning Link to unknown heading in `examples/example.md`: `world`' + source,
240− ' 39:10-39:40 warning Link to unknown heading in `examples/example.md`: `world`' + source,
241− ' 41:10-41:83 warning Link to unknown heading in `examples/example.md`: `world`' + source,
242− ' 43:10-43:84 warning Link to unknown heading in `examples/example.md`: `world`' + source,
243− ' 45:10-45:40 warning Link to unknown file: `examples/world.md` ' + source,
244− ' 45:10-45:40 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
245− ' 47:10-47:38 warning Link to unknown file: `examples/world.md` ' + source,
246− ' 47:10-47:38 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
247− ' 49:10-49:81 warning Link to unknown file: `examples/world.md` ' + source,
248− ' 49:10-49:81 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
249− ' 51:10-51:82 warning Link to unknown heading in `examples/world.md`: `hello` ' + source,
250− ' 51:10-51:82 warning Link to unknown file: `examples/world.md` ' + source,
251− '',
252− 'examples/example.md',
253− ' 5:37-5:51 warning Link to unknown heading: `world` ' + source,
254− ' 15:34-15:93 warning Link to unknown file: `world.md` ' + source,
255− ' 17:12-17:72 warning Link to unknown file: `world.md` ' + source,
256− ' 19:10-19:29 warning Link to unknown file: `world.md` ' + source,
257− ' 29:10-29:34 warning Link to unknown heading in `example.md`: `world` ' + source,
258− ' 31:10-31:74 warning Link to unknown heading in `example.md`: `world` ' + source,
259− ' 33:10-33:75 warning Link to unknown heading in `example.md`: `world` ' + source,
260− ' 35:10-35:32 warning Link to unknown file: `world.md` ' + source,
261− ' 35:10-35:32 warning Link to unknown heading in `world.md`: `hello` ' + source,
262− ' 37:10-37:72 warning Link to unknown file: `world.md` ' + source,
263− ' 37:10-37:72 warning Link to unknown heading in `world.md`: `hello` ' + source,
264− ' 39:10-39:73 warning Link to unknown heading in `world.md`: `hello` ' + source,
265− ' 39:10-39:73 warning Link to unknown file: `world.md` ' + source,
266− '',
267− '⚠ 30 warnings'
268− ].join('\n'),
269− 'should report'
270− );
271− }, clean);
272− });
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+ })
273896
274897 t.test('should suggest similar links', function (st) {
275− st.plan(1);
276−
277− execa.stderr(bin, [
278− '--no-config',
279− '--no-ignore',
280− '--use',
281− '../../index',
282− 'suggestions.md'
283− ]).then(function (stderr) {
284− st.equal(
285− strip(stderr),
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
984+ )
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+ }
1005+ })
1006+
1007+ t.test('should support folders', function (st) {
1008+ st.plan(1)
1009+
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)],
1027+ [
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'
1042+ )
1043+ }
1044+ })
1045+
1046+ t.test('should warn on files as folders', function (st) {
1047+ st.plan(1)
1048+
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)],
1066+ [
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'
1077+ )
1078+ }
1079+ })
1080+
1081+ t.test('should check images', function (st) {
1082+ st.plan(1)
1083+
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)],
1101+ [
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'
1116+ )
1117+ }
1118+ })
1119+
1120+ t.test('should support query parameters', function (st) {
1121+ st.plan(1)
1122+
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)],
1140+ [
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'
1151+ )
1152+ }
1153+ })
1154+
1155+ t.test('should support case insensitive headings', function (st) {
1156+ st.plan(1)
1157+
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)],
1175+ [
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'
1187+ )
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)],
2861282 [
287− 'suggestions.md',
288− ' 3:22-3:37 warning Link to unknown heading: `helloo`. Did you mean `hello` ' + source,
289− ' 7:17-7:40 warning Link to unknown heading in `example.md`: `fiiiles`. Did you mean `files`' + source,
290− '',
291− '⚠ 2 warnings'
292− ].join('\n'),
293− 'should report'
294− );
295− });
296− });
297−});
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+ }
1299+ })
1300+
1301+ t.end()
1302+})
test/sort.jsnew file+13
@@ -0,0 +1,13 @@
1+'use strict'
2+
3+var vfileSort = require('vfile-sort')
4+
5+module.exports = sort
6+
7+function sort() {
8+ return transform
9+}
10+
11+function transform(tree, file) {
12+ vfileSort(file)
13+}