git.iko.soy/typeable/remark-validate-links
on main help sign in
Refactor code-style to use `xo`
commitaaf7831ff3c7e0f578b067e74283a66a81d5b589 authorTitus Wormer <tituswormer@gmail.com> dateSat 23 Jul 2016, 20:13 (10 years ago) parent28190d3
8 files changed+616−762
.editorconfig+1−7 .eslintignore−1 .eslintrc−6 .jscs.json−39 .remarkrc−13 index.js+264−359 package.json+31−13 test/index.js+320−324
.editorconfig+1−7
@@ -2,14 +2,8 @@ root = true
22
33[*]
44indent_style = space
5−indent_size = 4
5+indent_size = 2
66end_of_line = lf
77charset = utf-8
88trim_trailing_whitespace = true
99insert_final_newline = true
10−
11−[*.{json,html,svg,css,remarkrc,eslintrc}]
12−indent_size = 2
13−
14−[*.md]
15−trim_trailing_whitespace = false
.eslintignoredeleted−1
@@ -1 +0,0 @@
1−coverage/
.eslintrcdeleted−6
@@ -1,6 +0,0 @@
1−{
2− "extends": "eslint:recommended",
3− "rules": {
4− "quotes": [2, "single"]
5− }
6−}
.jscs.jsondeleted−39
@@ -1,39 +0,0 @@
1−{
2− "excludeFiles": [
3− "coverage/",
4− "node_modules/"
5− ],
6− "preset": "crockford",
7− "requireMultipleVarDecl": false,
8− "requireVarDeclFirst": false,
9− "disallowDanglingUnderscores": false,
10− "maximumLineLength": {
11− "value": 79,
12− "allExcept": [
13− "regex",
14− "urlComments",
15− "require"
16− ]
17− },
18− "requireQuotedKeysInObjects": true,
19− "disallowKeywords": [
20− "with"
21− ],
22− "jsDoc": {
23− "checkAnnotations": "jsdoc3",
24− "checkParamExistence": true,
25− "checkParamNames": true,
26− "checkRedundantAccess": true,
27− "checkRedundantParams": true,
28− "checkRedundantReturns": true,
29− "checkReturnTypes": true,
30− "checkTypes": "strictNativeCase",
31− "enforceExistence": true,
32− "requireHyphenBeforeDescription": true,
33− "requireNewlineAfterDescription": true,
34− "requireParamDescription": true,
35− "requireParamTypes": true,
36− "requireReturnDescription": true,
37− "requireReturnTypes": true
38− }
39−}
.remarkrcdeleted−13
@@ -1,13 +0,0 @@
1−{
2− "output": true,
3− "plugins": [
4− "comment-config",
5− "lint",
6− "github",
7− "toc",
8− "./"
9− ],
10− "settings": {
11− "bullet": "*"
12− }
13−}
index.js+264−359
@@ -10,10 +10,7 @@
1010
1111/* eslint-env node */
1212
13−/*
14− * Dependencies.
15− */
16−
13+/* Dependencies. */
1714var url = require('url');
1815var fs = require('fs');
1916var path = require('path');
@@ -25,17 +22,14 @@ var urljoin = require('urljoin');
2522var slug = require('remark-slug');
2623var xtend = require('xtend');
2724
28−/*
29− * Methods.
30− */
25+/* Expose. */
26+module.exports = attacher;
3127
28+/* Methods. */
3229var exists = fs.existsSync;
3330var parse = url.parse;
3431
35−/*
36− * Constants.
37− */
38−
32+/* Constants. */
3933var NS = 'remark-validate-links';
4034
4135/**
@@ -46,7 +40,7 @@ var NS = 'remark-validate-links';
4640 * @return {string?} - Pathname.
4741 */
4842function getPathname(uri) {
49− return parse(uri).pathname;
43+ return parse(uri).pathname;
5044}
5145
5246/**
@@ -57,9 +51,9 @@ function getPathname(uri) {
5751 * @return {string?} - Hash.
5852 */
5953function getHash(uri) {
60− var hash = parse(uri).hash;
54+ var hash = parse(uri).hash;
6155
62− return hash ? hash.slice(1) : null;
56+ return hash ? hash.slice(1) : null;
6357}
6458
6559/**
@@ -71,31 +65,27 @@ function getHash(uri) {
7165 * @return {string?} - Suggested reference.
7266 */
7367function getClosest(pathname, references) {
74− var hash = getHash(pathname);
75− var base = getPathname(pathname);
76− var dictionary = [];
77− var reference;
78− var subhash;
79− var subbase;
80−
81− for (reference in references) {
82− subbase = getPathname(reference);
83− subhash = getHash(reference);
84−
85− if (getPathname(reference) === base) {
86− if (subhash && hash) {
87− dictionary.push(subhash);
88− }
89− } else {
90− if (!subhash && !hash) {
91− dictionary.push(subbase);
92− }
93− }
68+ var hash = getHash(pathname);
69+ var base = getPathname(pathname);
70+ var dictionary = [];
71+ var reference;
72+ var subhash;
73+ var subbase;
74+
75+ for (reference in references) {
76+ subbase = getPathname(reference);
77+ subhash = getHash(reference);
78+
79+ if (getPathname(reference) === base) {
80+ if (subhash && hash) {
81+ dictionary.push(subhash);
82+ }
83+ } else if (!subhash && !hash) {
84+ dictionary.push(subbase);
9485 }
86+ }
9587
96− return propose(hash ? hash : base, dictionary, {
97− 'threshold': 0.7
98− });
88+ return propose(hash ? hash : base, dictionary, {threshold: 0.7});
9989}
10090
10191/**
@@ -107,18 +97,15 @@ function getClosest(pathname, references) {
10797 * @param {string} warning - Message.
10898 */
10999function warnAll(file, nodes, warning) {
110− nodes.forEach(function (node) {
111− file.warn(warning, node);
112− });
100+ nodes.forEach(function (node) {
101+ file.warn(warning, node);
102+ });
113103}
114104
115105/**
116106 * Gather references: a map of file-paths references
117107 * to be one or more nodes.
118108 *
119− * @example
120− * gatherReferences(new File(), {type: 'root'}, {});
121− *
122109 * @param {File} file - Set of virtual files.
123110 * @param {Node} tree - Syntax tree.
124111 * @param {Object.<string, string>} project - GitHub
@@ -128,149 +115,116 @@ function warnAll(file, nodes, warning) {
128115 * file-paths (and anchors) which are referenced.
129116 */
130117function gatherReferences(file, tree, project) {
131− var cache = {};
132− var filePath = file.filePath();
133− var directory = file.directory;
134− var getDefinition;
135− var prefix = '';
136−
137− getDefinition = definitions(tree);
118+ var cache = {};
119+ var filePath = file.filePath();
120+ var directory = file.directory;
121+ var getDefinition;
122+ var prefix = '';
123+
124+ getDefinition = definitions(tree);
125+
126+ if (project.user && project.repo) {
127+ prefix = '/' + project.user + '/' + project.repo + '/blob/';
128+ }
129+
130+ /**
131+ * Handle new links.
132+ */
133+ function onlink(node) {
134+ var link = node.url;
135+ var definition;
136+ var index;
137+ var uri;
138+ var pathname;
139+ var hash;
138140
139− if (project.user && project.repo) {
140− prefix = '/' + project.user + '/' + project.repo + '/blob/';
141+ /* Handle link-references. */
142+ if (node.identifier) {
143+ definition = getDefinition(node.identifier);
144+ link = definition && definition.url;
141145 }
142146
143− /**
144− * Handle new links.
145− *
146− * @example
147− * link({
148− * url: 'foo/bar/baz.md#foo',
149− * children: [
150− * {
151− * type: 'text',
152− * value: 'foo'
153− * }
154− * ]
155− * });
156− *
157− * @param {Node} node - Link or link-reference node.
158− */
159− function onlink(node) {
160− var link = node.url;
161− var definition;
162− var index;
163− var uri;
164− var pathname;
165− var hash;
166−
167− /*
168− * Handle link-references.
169− */
170−
171− if (node.identifier) {
172− definition = getDefinition(node.identifier);
173− link = definition && definition.url;
174− }
175−
176− /*
177− * Ignore definitions without link.
178− */
147+ /* Ignore definitions without link. */
148+ if (!link) {
149+ return;
150+ }
179151
180− if (!link) {
181− return;
182− }
152+ uri = parse(link);
183153
154+ if (!uri.hostname) {
155+ /* Handle hashes, or relative files. */
156+ if (!uri.pathname && uri.hash) {
157+ link = filePath + uri.hash;
184158 uri = parse(link);
185−
186− if (!uri.hostname) {
187− /*
188− * Handle hashes, or relative files.
189− */
190− if (!uri.pathname && uri.hash) {
191− link = filePath + uri.hash;
192− uri = parse(link);
193− } else {
194− // var a = link;
195− link = urljoin(directory || './', link);
196− if (uri.hash) {
197− // console.error('a: ', a, link, '\n\n');
198− link += uri.hash;
199− }
200− uri = parse(link);
201− // console.error(['a', directory, link, a]);
202− }
203− }
204− // console.error(['b', link]);
205−
206− /*
207− * Handle full links.
208− * Only works with GitHub.
209− */
210−
211− if (uri.hostname) {
212− if (!prefix) {
213− return;
214− }
215−
216− if (
217− uri.hostname !== 'github.com' ||
218− uri.pathname.slice(0, prefix.length) !== prefix
219− ) {
220− return;
221− }
222−
223− link = uri.pathname.slice(prefix.length) + (uri.hash || '');
224−
225− /*
226− * Things get interesting here: branches.
227− * `foo/bar/baz` could be `baz` on the
228− * `foo/bar` branch. Or, `baz` in the `bar`
229− * directory on the `foo` branch.
230− *
231− * Currently, I’m ignoring this and just not
232− * supporting branches.
233− */
234−
235− link = link.slice(link.indexOf('/') + 1);
236−
237− uri = parse(link);
159+ } else {
160+ link = urljoin(directory || './', link);
161+ if (uri.hash) {
162+ link += uri.hash;
238163 }
164+ uri = parse(link);
165+ }
166+ }
239167
240− /*
241− * Handle file links, or combinations of files
242− * and hashes.
243− */
168+ /* Handle full links.
169+ * Only works with GitHub.
170+ */
171+ if (uri.hostname) {
172+ if (!prefix) {
173+ return;
174+ }
175+
176+ if (
177+ uri.hostname !== 'github.com' ||
178+ uri.pathname.slice(0, prefix.length) !== prefix
179+ ) {
180+ return;
181+ }
182+
183+ link = uri.pathname.slice(prefix.length) + (uri.hash || '');
184+
185+ /* Things get interesting here: branches.
186+ * `foo/bar/baz` could be `baz` on the
187+ * `foo/bar` branch. Or, `baz` in the `bar`
188+ * directory on the `foo` branch.
189+ *
190+ * Currently, I’m ignoring this and just not
191+ * supporting branches. */
192+ link = link.slice(link.indexOf('/') + 1);
193+
194+ uri = parse(link);
195+ }
244196
245− index = link.indexOf('#');
197+ /* Handle file links, or combinations of files
198+ * and hashes. */
199+ index = link.indexOf('#');
246200
247− if (index === -1) {
248− pathname = link;
249− hash = null;
250− } else {
251− pathname = link.slice(0, index);
252− hash = link.slice(index + 1);
253− }
201+ if (index === -1) {
202+ pathname = link;
203+ hash = null;
204+ } else {
205+ pathname = link.slice(0, index);
206+ hash = link.slice(index + 1);
207+ }
254208
255− if (!cache[pathname]) {
256− cache[pathname] = [];
257− }
209+ if (!cache[pathname]) {
210+ cache[pathname] = [];
211+ }
258212
259− cache[pathname].push(node);
213+ cache[pathname].push(node);
260214
261− if (hash) {
262− if (!cache[link]) {
263− cache[link] = [];
264− }
215+ if (hash) {
216+ if (!cache[link]) {
217+ cache[link] = [];
218+ }
265219
266− cache[link].push(node);
267− }
220+ cache[link].push(node);
268221 }
222+ }
269223
270− visit(tree, 'link', onlink);
271− visit(tree, 'linkReference', onlink);
224+ visit(tree, 'link', onlink);
225+ visit(tree, 'linkReference', onlink);
272226
273− return cache;
227+ return cache;
274228}
275229
276230/**
@@ -278,76 +232,63 @@ function gatherReferences(file, tree, project) {
278232 * `exposed`. If `project` is given, normalizes GitHub blob
279233 * URLs.
280234 *
281− * @example
282− * validate({'example.md': true}, new File());
283− *
284235 * @param {Object.<string, boolean?>} exposed - Map of
285236 * file-paths (and anchors) which can be references to.
286237 * @param {File} file - Set of virtual files.
287238 */
288239function validate(exposed, file) {
289− var references = file.namespace(NS).references;
290− var filePath = file.filePath();
291− var reference;
292− var nodes;
293− var real;
294− var hash;
295− var pathname;
296− var warning;
297− var suggestion;
298−
299− for (reference in references) {
300− nodes = references[reference];
301− real = exposed[reference];
302− hash = getHash(reference);
303−
304− // if (hash) {
305− // console.error(['hash', reference, hash]);
306− // }
307−
308− /*
309− * Check if files without `hash` can be linked to.
310− * Because there’s no need to inspect those files
311− * for headings they are not added to remark. This
312− * is especially useful because they might be
313− * non-markdown files. Here we check if they exist.
314− */
315−
316− if ((real === undefined || real === null) && !hash) {
317− real = references[reference] = exists(reference);
318− }
240+ var references = file.namespace(NS).references;
241+ var filePath = file.filePath();
242+ var reference;
243+ var nodes;
244+ var real;
245+ var hash;
246+ var pathname;
247+ var warning;
248+ var suggestion;
249+
250+ for (reference in references) {
251+ nodes = references[reference];
252+ real = exposed[reference];
253+ hash = getHash(reference);
254+
255+ /* Check if files without `hash` can be linked to.
256+ * Because there’s no need to inspect those files
257+ * for headings they are not added to remark. This
258+ * is especially useful because they might be
259+ * non-markdown files. Here we check if they exist. */
260+ if ((real === undefined || real === null) && !hash) {
261+ real = references[reference] = exists(reference);
262+ }
319263
320− if (!real) {
321− if (hash) {
322− pathname = getPathname(reference);
323− warning = 'Link to unknown heading';
264+ if (!real) {
265+ if (hash) {
266+ pathname = getPathname(reference);
267+ warning = 'Link to unknown heading';
324268
325− if (pathname !== filePath) {
326− warning += ' in `' + pathname + '`';
327− }
269+ if (pathname !== filePath) {
270+ warning += ' in `' + pathname + '`';
271+ }
328272
329− warning += ': `' + hash + '`';
330− } else {
331− warning = 'Link to unknown file: `' + reference + '`';
332− }
273+ warning += ': `' + hash + '`';
274+ } else {
275+ warning = 'Link to unknown file: `' + reference + '`';
276+ }
333277
334− suggestion = getClosest(reference, exposed);
278+ suggestion = getClosest(reference, exposed);
335279
336− if (suggestion) {
337− warning += '. Did you mean `' + suggestion + '`';
338− }
280+ if (suggestion) {
281+ warning += '. Did you mean `' + suggestion + '`';
282+ }
339283
340− warnAll(file, nodes, warning);
341− }
284+ warnAll(file, nodes, warning);
342285 }
286+ }
343287}
344288
345289/**
346290 * Completer.
347291 *
348− * @example
349− * completer(new FileSet(), console.log)
350− *
351292 * @property {*} pluginId - Unique ID so completers by
352293 * this plug-in are not added multiple times to a single
353294 * file-set pipeline.
@@ -355,169 +296,133 @@ function validate(exposed, file) {
355296 * @param {function(err?)} done - Callback.
356297 */
357298function completer(set, done) {
358− var exposed = {};
299+ var exposed = {};
359300
360− set.valueOf().forEach(function (file) {
361− var landmarks = file.namespace(NS).landmarks;
301+ set.valueOf().forEach(function (file) {
302+ var landmarks = file.namespace(NS).landmarks;
362303
363− if (landmarks) {
364− exposed = xtend(exposed, landmarks);
365− }
366− });
304+ if (landmarks) {
305+ exposed = xtend(exposed, landmarks);
306+ }
307+ });
367308
368− set.valueOf().forEach(function (file) {
369− /* istanbul ignore else - stdin */
370− if (file.filePath()) {
371− validate(exposed, file);
372− }
373− });
309+ set.valueOf().forEach(function (file) {
310+ /* istanbul ignore else - stdin */
311+ if (file.filePath()) {
312+ validate(exposed, file);
313+ }
314+ });
374315
375− done();
316+ done();
376317}
377318
378319completer.pluginId = 'remark-validate-links';
379320
380321/**
381− * Factory to create a transformer based on the given
382− * project and set.
383− *
384− * @example
385− * transformerFactory({}, new FileSet());
386− *
387− * @param {Object.<string, string>} project - GitHub
388− * project, with a `user` and `repo` property
389− * (optional).
390− * @param {FileSet} fileSet - Set of virtual files.
391− * @return {function(ast, file)} - Transformer.
392− */
322+* Factory to create a transformer based on the given
323+* project and set.
324+*
325+* @param {Object.<string, string>} project - GitHub
326+* project, with a `user` and `repo` property
327+* (optional).
328+* @param {FileSet} fileSet - Set of virtual files.
329+* @return {function(ast, file)} - Transformer.
330+*/
393331function transformerFactory(project, fileSet) {
394− /**
395− * Transformer. Adds references files to the set.
396− *
397− * @example
398− * transformer({}, new File());
399− *
400− * @param {*} ast - Node.
401− * @param {File} file - Virtual file.
402− */
403− function transformer(ast, file) {
404− var filePath = file.filePath();
405− var space = file.namespace(NS);
406− var links = [];
407− var landmarks = {};
408− var references;
409− var current;
410− var link;
411− var pathname;
412−
413− /* istanbul ignore if - stdin */
414− if (!filePath) {
415− return;
416− }
332+ /**
333+ * Transformer. Adds references files to the set.
334+ *
335+ * @param {*} ast - Node.
336+ * @param {File} file - Virtual file.
337+ */
338+ function transformer(ast, file) {
339+ var filePath = file.filePath();
340+ var space = file.namespace(NS);
341+ var links = [];
342+ var landmarks = {};
343+ var references;
344+ var current;
345+ var link;
346+ var pathname;
417347
418− references = gatherReferences(file, ast, project);
419− current = getPathname(filePath);
348+ /* istanbul ignore if - stdin */
349+ if (!filePath) {
350+ return;
351+ }
420352
421− for (link in references) {
422− pathname = getPathname(link);
353+ references = gatherReferences(file, ast, project);
354+ current = getPathname(filePath);
423355
424− if (
425− pathname !== current &&
426− getHash(link) &&
427− links.indexOf(pathname) === -1
428− ) {
429− links.push(pathname);
430− fileSet.add(pathname);
431− }
432− }
356+ for (link in references) {
357+ pathname = getPathname(link);
358+
359+ if (
360+ pathname !== current &&
361+ getHash(link) &&
362+ links.indexOf(pathname) === -1
363+ ) {
364+ links.push(pathname);
365+ fileSet.add(pathname);
366+ }
367+ }
433368
434− landmarks[filePath] = true;
369+ landmarks[filePath] = true;
435370
436− visit(ast, function (node) {
437− var data = node.data || {};
438− var attrs = data.htmlAttributes || {};
439− var id = attrs.name || attrs.id || data.id;
371+ visit(ast, function (node) {
372+ var data = node.data || {};
373+ var attrs = data.htmlAttributes || {};
374+ var id = attrs.name || attrs.id || data.id;
440375
441− if (id) {
442− landmarks[filePath + '#' + id] = true;
443− }
444− });
376+ if (id) {
377+ landmarks[filePath + '#' + id] = true;
378+ }
379+ });
445380
446− space.references = references;
447− space.landmarks = landmarks;
448− }
381+ space.references = references;
382+ space.landmarks = landmarks;
383+ }
449384
450− return transformer;
385+ return transformer;
451386}
452387
453388/**
454− * Attacher.
455− *
456− * @example
457− * attacher(remark())
458− * // [Error: remark-validate-links only works on the CLI]
459− *
460− * @param {Remark} remark - Processor.
461− * @param {Object?} options - Settings.
462− * @param {FileSet?} fileSet - Virtual file-set.
463− * @throws {Error} - When `fileSet` is not given (when not on
464− * the CLI).
465− */
389+* Attacher.
390+*
391+* @param {Remark} remark - Processor.
392+* @param {Object?} options - Settings.
393+* @param {FileSet?} fileSet - Virtual file-set.
394+* @throws {Error} - When `fileSet` is not given (when not on
395+* the CLI).
396+*/
466397function attacher(remark, options, fileSet) {
467− var repo = (options || {}).repository;
468− var pack;
469−
470− /*
471− * Throw when not on the CLI.
472− */
473−
474− if (!fileSet) {
475− throw new Error('remark-validate-links only works on the CLI');
476− }
477−
478− /*
479− * Try to get the repo from `package.json` when not
480− * given.
481− */
482−
483− if (!repo) {
484− try {
485− pack = require(path.resolve(process.cwd(), 'package.json'));
486− } catch (exception) {
487− pack = {};
488− }
489−
490− repo = pack.repository ? pack.repository.url || pack.repository : '';
398+ var repo = (options || {}).repository;
399+ var pack;
400+
401+ /* Throw when not on the CLI. */
402+ if (!fileSet) {
403+ throw new Error('remark-validate-links only works on the CLI');
404+ }
405+
406+ /* Try to get the repo from `package.json` when not
407+ * given. */
408+ if (!repo) {
409+ try {
410+ pack = require(path.resolve(process.cwd(), 'package.json'));
411+ } catch (err) {
412+ pack = {};
491413 }
492414
493− repo = repo ? gh(repo) : {};
415+ repo = pack.repository ? pack.repository.url || pack.repository : '';
416+ }
494417
495− repo = {
496− 'user': repo.user,
497− 'repo': repo.repo
498− };
418+ repo = repo ? gh(repo) : {};
499419
500− /*
501− * Attach a `completer`.
502− */
503−
504− fileSet.use(completer);
505−
506− /*
507− * Attach `slug`.
508− */
509−
510− remark.use(slug);
420+ /* Attach a `completer`. */
421+ fileSet.use(completer);
511422
512− /*
513− * Expose transformer.
514− */
423+ /* Attach `slug`. */
424+ remark.use(slug);
515425
516− return transformerFactory(repo, fileSet);
426+ /* Expose transformer. */
427+ return transformerFactory({user: repo.user, repo: repo.repo}, fileSet);
517428}
518−
519−/*
520− * Expose.
521− */
522−
523−module.exports = attacher;
package.json+31−13
@@ -33,10 +33,7 @@
3333 "index.js"
3434 ],
3535 "devDependencies": {
36− "eslint": "^2.0.0",
3736 "execa": "^0.4.0",
38− "jscs": "^3.0.0",
39− "jscs-jsdoc": "^2.0.0",
4037 "nyc": "^7.0.0",
4138 "remark": "^5.0.0",
4239 "remark-cli": "^1.0.0",
@@ -45,22 +42,43 @@
4542 "remark-lint": "^4.0.0",
4643 "remark-toc": "^3.0.0",
4744 "strip-ansi": "^3.0.1",
48− "tape": "^4.0.0"
49− },
50− "nyc": {
51− "check-coverage": true,
52− "lines": 100,
53− "functions": 100,
54− "branches": 100
45+ "tape": "^4.0.0",
46+ "xo": "^0.16.0"
5547 },
5648 "scripts": {
5749 "build-md": "remark . --quiet --frail",
5850 "build": "npm run build-md",
59− "lint-api": "eslint .",
60− "lint-style": "jscs --reporter inline .",
61− "lint": "npm run lint-api && npm run lint-style",
51+ "lint": "xo",
6252 "test-api": "node test/index.js",
6353 "test-coverage": "nyc --reporter lcov tape test/index.js",
6454 "test": "npm run build && npm run lint && npm run test-coverage"
55+ },
56+ "xo": {
57+ "space": true,
58+ "rules": {
59+ "no-eq-null": "off",
60+ "eqeqeq": "off",
61+ "guard-for-in": "off",
62+ "max-lines": "off"
63+ }
64+ },
65+ "nyc": {
66+ "check-coverage": true,
67+ "lines": 100,
68+ "functions": 100,
69+ "branches": 100
70+ },
71+ "remarkConfig": {
72+ "output": true,
73+ "plugins": [
74+ "comment-config",
75+ "github",
76+ "lint",
77+ "toc",
78+ "./"
79+ ],
80+ "settings": {
81+ "bullet": "*"
82+ }
6583 }
6684}
test/index.js+320−324
@@ -8,10 +8,6 @@
88
99'use strict';
1010
11−/* eslint-env node */
12−/* jscs:disable jsDoc */
13−/* jscs:disable maximumLineLength */
14−
1511/* Dependencies. */
1612var fs = require('fs');
1713var path = require('path');
@@ -25,353 +21,353 @@ var links = require('..');
2521process.chdir(path.resolve(process.cwd(), 'test', 'fixtures'));
2622
2723test.onFinish(function () {
28− process.chdir(path.resolve(process.cwd(), '..', '..'));
24+ process.chdir(path.resolve(process.cwd(), '..', '..'));
2925});
3026
3127var bin = path.join('..', '..', 'node_modules', '.bin', 'remark');
3228
3329/* Tests. */
3430test('remark-validate-links', function (t) {
35− t.plan(8);
31+ t.plan(8);
3632
37− t.throws(
38− function () {
39− remark().use(links);
40− },
41− /Error: remark-validate-links only works on the CLI/,
42− 'should throw an error when not on the CLI'
43− );
33+ t.throws(
34+ function () {
35+ remark().use(links);
36+ },
37+ /Error: remark-validate-links only works on the CLI/,
38+ 'should throw an error when not on the CLI'
39+ );
4440
45− t.test('should ignore unfound files', function (st) {
46− st.plan(2);
41+ t.test('should ignore unfound files', function (st) {
42+ st.plan(2);
4743
48− execa.stderr(bin, [
49− '--no-config',
50− '--no-ignore',
51− '--use',
52− '.',
53− 'definitions.md',
54− 'FOOOO'
55− ]).catch(function (err) {
56− st.equal(err.code, 1, 'should exit with `1`');
57− st.equal(
58− strip(err.stderr),
59− [
60− 'FOOOO',
61− ' 1:1 error No such file or directory',
62− '',
63− 'definitions.md',
64− ' 5:12-5:21 warning Link to unknown heading: `world`',
65− '',
66− '2 messages (✖ 1 error, ⚠ 1 warning)',
67− ''
68− ].join('\n'),
69− 'should report'
70− );
71− });
44+ execa.stderr(bin, [
45+ '--no-config',
46+ '--no-ignore',
47+ '--use',
48+ '.',
49+ 'definitions.md',
50+ 'FOOOO'
51+ ]).catch(function (err) {
52+ st.equal(err.code, 1, 'should exit with `1`');
53+ st.equal(
54+ strip(err.stderr),
55+ [
56+ 'FOOOO',
57+ ' 1:1 error No such file or directory',
58+ '',
59+ 'definitions.md',
60+ ' 5:12-5:21 warning Link to unknown heading: `world`',
61+ '',
62+ '2 messages (✖ 1 error, ⚠ 1 warning)',
63+ ''
64+ ].join('\n'),
65+ 'should report'
66+ );
7267 });
68+ });
7369
74− t.test('should work when not all files are given', function (st) {
75− st.plan(1);
70+ t.test('should work when not all files are given', function (st) {
71+ st.plan(1);
7672
77− execa.stderr(bin, [
78− '--no-config',
79− '--no-ignore',
80− '--use',
81− '.',
82− 'example.md'
83− ]).then(function (stderr) {
84− st.equal(
85− strip(stderr),
86− [
87− 'example.md',
88− ' 5:37-5:51 warning Link to unknown heading: `world`',
89− ' 23:10-23:37 warning Link to unknown file: `examples/world.md`',
90− ' 25:10-25:35 warning Link to unknown file: `examples/world.md`',
91− ' 37:10-37:42 warning Link to unknown heading in `examples/example.md`: `world`',
92− ' 39:10-39:40 warning Link to unknown heading in `examples/example.md`: `world`',
93− ' 45:10-45:40 warning Link to unknown file: `examples/world.md`',
94− ' 45:10-45:40 warning Link to unknown heading in `examples/world.md`: `hello`',
95− ' 47:10-47:38 warning Link to unknown file: `examples/world.md`',
96− ' 47:10-47:38 warning Link to unknown heading in `examples/world.md`: `hello`',
97− '',
98− '⚠ 9 warnings'
99− ].join('\n'),
100− 'should report'
101− );
102− });
73+ execa.stderr(bin, [
74+ '--no-config',
75+ '--no-ignore',
76+ '--use',
77+ '.',
78+ 'example.md'
79+ ]).then(function (stderr) {
80+ st.equal(
81+ strip(stderr),
82+ [
83+ 'example.md',
84+ ' 5:37-5:51 warning Link to unknown heading: `world`',
85+ ' 23:10-23:37 warning Link to unknown file: `examples/world.md`',
86+ ' 25:10-25:35 warning Link to unknown file: `examples/world.md`',
87+ ' 37:10-37:42 warning Link to unknown heading in `examples/example.md`: `world`',
88+ ' 39:10-39:40 warning Link to unknown heading in `examples/example.md`: `world`',
89+ ' 45:10-45:40 warning Link to unknown file: `examples/world.md`',
90+ ' 45:10-45:40 warning Link to unknown heading in `examples/world.md`: `hello`',
91+ ' 47:10-47:38 warning Link to unknown file: `examples/world.md`',
92+ ' 47:10-47:38 warning Link to unknown heading in `examples/world.md`: `hello`',
93+ '',
94+ '⚠ 9 warnings'
95+ ].join('\n'),
96+ 'should report'
97+ );
10398 });
99+ });
104100
105− t.test('should work when all files are given', function (st) {
106− st.plan(1);
101+ t.test('should work when all files are given', function (st) {
102+ st.plan(1);
107103
108− execa.stderr(bin, [
109− '--no-config',
110− '--no-ignore',
111− '--use',
112− '.',
113− 'example.md',
114− 'examples/example.md'
115− ]).then(function (stderr) {
116− st.equal(
117− strip(stderr),
118− [
119− 'example.md',
120− ' 5:37-5:51 warning Link to unknown heading: `world`',
121− ' 23:10-23:37 warning Link to unknown file: `examples/world.md`',
122− ' 25:10-25:35 warning Link to unknown file: `examples/world.md`',
123− ' 37:10-37:42 warning Link to unknown heading in `examples/example.md`: `world`',
124− ' 39:10-39:40 warning Link to unknown heading in `examples/example.md`: `world`',
125− ' 45:10-45:40 warning Link to unknown file: `examples/world.md`',
126− ' 45:10-45:40 warning Link to unknown heading in `examples/world.md`: `hello`',
127− ' 47:10-47:38 warning Link to unknown file: `examples/world.md`',
128− ' 47:10-47:38 warning Link to unknown heading in `examples/world.md`: `hello`',
129− '',
130− 'examples/example.md',
131− ' 5:37-5:51 warning Link to unknown heading: ' +
132− '`world`',
133− ' 19:10-19:29 warning Link to unknown file: ' +
134− '`world.md`',
135− ' 29:10-29:34 warning Link to unknown heading in ' +
136− '`example.md`: `world`',
137− ' 35:10-35:32 warning Link to unknown file: ' +
138− '`world.md`',
139− ' 35:10-35:32 warning Link to unknown heading in ' +
140− '`world.md`: `hello`',
141− '',
142− '⚠ 14 warnings'
143− ].join('\n'),
144− 'should report'
145− );
146− });
104+ execa.stderr(bin, [
105+ '--no-config',
106+ '--no-ignore',
107+ '--use',
108+ '.',
109+ 'example.md',
110+ 'examples/example.md'
111+ ]).then(function (stderr) {
112+ st.equal(
113+ strip(stderr),
114+ [
115+ 'example.md',
116+ ' 5:37-5:51 warning Link to unknown heading: `world`',
117+ ' 23:10-23:37 warning Link to unknown file: `examples/world.md`',
118+ ' 25:10-25:35 warning Link to unknown file: `examples/world.md`',
119+ ' 37:10-37:42 warning Link to unknown heading in `examples/example.md`: `world`',
120+ ' 39:10-39:40 warning Link to unknown heading in `examples/example.md`: `world`',
121+ ' 45:10-45:40 warning Link to unknown file: `examples/world.md`',
122+ ' 45:10-45:40 warning Link to unknown heading in `examples/world.md`: `hello`',
123+ ' 47:10-47:38 warning Link to unknown file: `examples/world.md`',
124+ ' 47:10-47:38 warning Link to unknown heading in `examples/world.md`: `hello`',
125+ '',
126+ 'examples/example.md',
127+ ' 5:37-5:51 warning Link to unknown heading: ' +
128+ '`world`',
129+ ' 19:10-19:29 warning Link to unknown file: ' +
130+ '`world.md`',
131+ ' 29:10-29:34 warning Link to unknown heading in ' +
132+ '`example.md`: `world`',
133+ ' 35:10-35:32 warning Link to unknown file: ' +
134+ '`world.md`',
135+ ' 35:10-35:32 warning Link to unknown heading in ' +
136+ '`world.md`: `hello`',
137+ '',
138+ '⚠ 14 warnings'
139+ ].join('\n'),
140+ 'should report'
141+ );
147142 });
143+ });
148144
149− t.test('should work with definitions', function (st) {
150− st.plan(1);
145+ t.test('should work with definitions', function (st) {
146+ st.plan(1);
151147
152− execa.stderr(bin, [
153− '--no-config',
154− '--no-ignore',
155− '--use',
156− '.',
157− 'definitions.md'
158− ]).then(function (stderr) {
159− st.equal(
160− strip(stderr),
161− [
162− 'definitions.md',
163− ' 5:12-5:21 warning Link to unknown heading: `world`',
164− '',
165− '⚠ 1 warning'
166− ].join('\n'),
167− 'should report'
168− );
169− });
148+ execa.stderr(bin, [
149+ '--no-config',
150+ '--no-ignore',
151+ '--use',
152+ '.',
153+ 'definitions.md'
154+ ]).then(function (stderr) {
155+ st.equal(
156+ strip(stderr),
157+ [
158+ 'definitions.md',
159+ ' 5:12-5:21 warning Link to unknown heading: `world`',
160+ '',
161+ '⚠ 1 warning'
162+ ].join('\n'),
163+ 'should report'
164+ );
170165 });
166+ });
171167
172− t.test('should work on GitHub URLs when given a repo', function (st) {
173− st.plan(1);
168+ t.test('should work on GitHub URLs when given a repo', function (st) {
169+ st.plan(1);
174170
175− execa.stderr(bin, [
176− '--no-config',
177− '--no-ignore',
178− '--use',
179− '.=repository:"wooorm/test"',
180− 'example.md',
181− 'examples/example.md'
182− ]).then(function (stderr) {
183− st.equal(
184− strip(stderr),
185− [
186− 'example.md',
187− ' 5:37-5:51 warning Link to unknown heading: ' +
188− '`world`',
189− ' 19:34-19:102 warning Link to unknown file: ' +
190− '`examples/world.md`',
191− ' 21:12-21:81 warning Link to unknown file: ' +
192− '`examples/world.md`',
193− ' 23:10-23:37 warning Link to unknown file: ' +
194− '`examples/world.md`',
195− ' 25:10-25:35 warning Link to unknown file: ' +
196− '`examples/world.md`',
197− ' 37:10-37:42 warning Link to unknown heading in ' +
198− '`examples/example.md`: `world`',
199− ' 39:10-39:40 warning Link to unknown heading in ' +
200− '`examples/example.md`: `world`',
201− ' 41:10-41:83 warning Link to unknown heading in ' +
202− '`examples/example.md`: `world`',
203− ' 43:10-43:84 warning Link to unknown heading in ' +
204− '`examples/example.md`: `world`',
205− ' 45:10-45:40 warning Link to unknown file: ' +
206− '`examples/world.md`',
207− ' 45:10-45:40 warning Link to unknown heading in ' +
208− '`examples/world.md`: `hello`',
209− ' 47:10-47:38 warning Link to unknown file: ' +
210− '`examples/world.md`',
211− ' 47:10-47:38 warning Link to unknown heading in ' +
212− '`examples/world.md`: `hello`',
213− ' 49:10-49:81 warning Link to unknown file: ' +
214− '`examples/world.md`',
215− ' 49:10-49:81 warning Link to unknown heading in ' +
216− '`examples/world.md`: `hello`',
217− ' 51:10-51:82 warning Link to unknown heading in ' +
218− '`examples/world.md`: `hello`',
219− ' 51:10-51:82 warning Link to unknown file: ' +
220− '`examples/world.md`',
221− '',
222− 'examples/example.md',
223− ' 5:37-5:51 warning Link to unknown heading: ' +
224− '`world`',
225− ' 15:34-15:93 warning Link to unknown file: ' +
226− '`world.md`',
227− ' 17:12-17:72 warning Link to unknown file: ' +
228− '`world.md`',
229− ' 19:10-19:29 warning Link to unknown file: ' +
230− '`world.md`',
231− ' 29:10-29:34 warning Link to unknown heading in ' +
232− '`example.md`: `world`',
233− ' 31:10-31:74 warning Link to unknown heading in ' +
234− '`example.md`: `world`',
235− ' 33:10-33:75 warning Link to unknown heading in ' +
236− '`example.md`: `world`',
237− ' 35:10-35:32 warning Link to unknown file: ' +
238− '`world.md`',
239− ' 35:10-35:32 warning Link to unknown heading in ' +
240− '`world.md`: `hello`',
241− ' 37:10-37:72 warning Link to unknown file: ' +
242− '`world.md`',
243− ' 37:10-37:72 warning Link to unknown heading in ' +
244− '`world.md`: `hello`',
245− ' 39:10-39:73 warning Link to unknown heading in ' +
246− '`world.md`: `hello`',
247− ' 39:10-39:73 warning Link to unknown file: ' +
248− '`world.md`',
249− '',
250− '⚠ 30 warnings'
251− ].join('\n'),
252− 'should report'
253− );
254− });
171+ execa.stderr(bin, [
172+ '--no-config',
173+ '--no-ignore',
174+ '--use',
175+ '.=repository:"wooorm/test"',
176+ 'example.md',
177+ 'examples/example.md'
178+ ]).then(function (stderr) {
179+ st.equal(
180+ strip(stderr),
181+ [
182+ 'example.md',
183+ ' 5:37-5:51 warning Link to unknown heading: ' +
184+ '`world`',
185+ ' 19:34-19:102 warning Link to unknown file: ' +
186+ '`examples/world.md`',
187+ ' 21:12-21:81 warning Link to unknown file: ' +
188+ '`examples/world.md`',
189+ ' 23:10-23:37 warning Link to unknown file: ' +
190+ '`examples/world.md`',
191+ ' 25:10-25:35 warning Link to unknown file: ' +
192+ '`examples/world.md`',
193+ ' 37:10-37:42 warning Link to unknown heading in ' +
194+ '`examples/example.md`: `world`',
195+ ' 39:10-39:40 warning Link to unknown heading in ' +
196+ '`examples/example.md`: `world`',
197+ ' 41:10-41:83 warning Link to unknown heading in ' +
198+ '`examples/example.md`: `world`',
199+ ' 43:10-43:84 warning Link to unknown heading in ' +
200+ '`examples/example.md`: `world`',
201+ ' 45:10-45:40 warning Link to unknown file: ' +
202+ '`examples/world.md`',
203+ ' 45:10-45:40 warning Link to unknown heading in ' +
204+ '`examples/world.md`: `hello`',
205+ ' 47:10-47:38 warning Link to unknown file: ' +
206+ '`examples/world.md`',
207+ ' 47:10-47:38 warning Link to unknown heading in ' +
208+ '`examples/world.md`: `hello`',
209+ ' 49:10-49:81 warning Link to unknown file: ' +
210+ '`examples/world.md`',
211+ ' 49:10-49:81 warning Link to unknown heading in ' +
212+ '`examples/world.md`: `hello`',
213+ ' 51:10-51:82 warning Link to unknown heading in ' +
214+ '`examples/world.md`: `hello`',
215+ ' 51:10-51:82 warning Link to unknown file: ' +
216+ '`examples/world.md`',
217+ '',
218+ 'examples/example.md',
219+ ' 5:37-5:51 warning Link to unknown heading: ' +
220+ '`world`',
221+ ' 15:34-15:93 warning Link to unknown file: ' +
222+ '`world.md`',
223+ ' 17:12-17:72 warning Link to unknown file: ' +
224+ '`world.md`',
225+ ' 19:10-19:29 warning Link to unknown file: ' +
226+ '`world.md`',
227+ ' 29:10-29:34 warning Link to unknown heading in ' +
228+ '`example.md`: `world`',
229+ ' 31:10-31:74 warning Link to unknown heading in ' +
230+ '`example.md`: `world`',
231+ ' 33:10-33:75 warning Link to unknown heading in ' +
232+ '`example.md`: `world`',
233+ ' 35:10-35:32 warning Link to unknown file: ' +
234+ '`world.md`',
235+ ' 35:10-35:32 warning Link to unknown heading in ' +
236+ '`world.md`: `hello`',
237+ ' 37:10-37:72 warning Link to unknown file: ' +
238+ '`world.md`',
239+ ' 37:10-37:72 warning Link to unknown heading in ' +
240+ '`world.md`: `hello`',
241+ ' 39:10-39:73 warning Link to unknown heading in ' +
242+ '`world.md`: `hello`',
243+ ' 39:10-39:73 warning Link to unknown file: ' +
244+ '`world.md`',
245+ '',
246+ '⚠ 30 warnings'
247+ ].join('\n'),
248+ 'should report'
249+ );
255250 });
251+ });
256252
257− t.test('should work on GitHub URLs when with package.json', function (st) {
258− st.plan(1);
253+ t.test('should work on GitHub URLs when with package.json', function (st) {
254+ st.plan(1);
259255
260− /* cwd is moved to `test/fixtures`. */
261− fs.writeFileSync('./package.json', JSON.stringify({
262− 'repository': 'wooorm/test'
263− }, 0, 2));
256+ /* cwd is moved to `test/fixtures`. */
257+ fs.writeFileSync('./package.json', JSON.stringify({
258+ repository: 'wooorm/test'
259+ }, 0, 2));
264260
265− function clean() {
266− fs.unlinkSync('./package.json');
267− }
261+ function clean() {
262+ fs.unlinkSync('./package.json');
263+ }
268264
269− execa.stderr(bin, [
270− '--no-config',
271− '--no-ignore',
272− '--use',
273− '../..',
274− 'example.md',
275− 'examples/example.md'
276− ]).then(function (stderr) {
277− clean();
278− st.equal(
279− strip(stderr),
280− [
281− 'example.md',
282− ' 5:37-5:51 warning Link to unknown heading: ' +
283− '`world`',
284− ' 19:34-19:102 warning Link to unknown file: ' +
285− '`examples/world.md`',
286− ' 21:12-21:81 warning Link to unknown file: ' +
287− '`examples/world.md`',
288− ' 23:10-23:37 warning Link to unknown file: ' +
289− '`examples/world.md`',
290− ' 25:10-25:35 warning Link to unknown file: ' +
291− '`examples/world.md`',
292− ' 37:10-37:42 warning Link to unknown heading in ' +
293− '`examples/example.md`: `world`',
294− ' 39:10-39:40 warning Link to unknown heading in ' +
295− '`examples/example.md`: `world`',
296− ' 41:10-41:83 warning Link to unknown heading in ' +
297− '`examples/example.md`: `world`',
298− ' 43:10-43:84 warning Link to unknown heading in ' +
299− '`examples/example.md`: `world`',
300− ' 45:10-45:40 warning Link to unknown file: ' +
301− '`examples/world.md`',
302− ' 45:10-45:40 warning Link to unknown heading in ' +
303− '`examples/world.md`: `hello`',
304− ' 47:10-47:38 warning Link to unknown file: ' +
305− '`examples/world.md`',
306− ' 47:10-47:38 warning Link to unknown heading in ' +
307− '`examples/world.md`: `hello`',
308− ' 49:10-49:81 warning Link to unknown file: ' +
309− '`examples/world.md`',
310− ' 49:10-49:81 warning Link to unknown heading in ' +
311− '`examples/world.md`: `hello`',
312− ' 51:10-51:82 warning Link to unknown heading in ' +
313− '`examples/world.md`: `hello`',
314− ' 51:10-51:82 warning Link to unknown file: ' +
315− '`examples/world.md`',
316− '',
317− 'examples/example.md',
318− ' 5:37-5:51 warning Link to unknown heading: ' +
319− '`world`',
320− ' 15:34-15:93 warning Link to unknown file: ' +
321− '`world.md`',
322− ' 17:12-17:72 warning Link to unknown file: ' +
323− '`world.md`',
324− ' 19:10-19:29 warning Link to unknown file: ' +
325− '`world.md`',
326− ' 29:10-29:34 warning Link to unknown heading in ' +
327− '`example.md`: `world`',
328− ' 31:10-31:74 warning Link to unknown heading in ' +
329− '`example.md`: `world`',
330− ' 33:10-33:75 warning Link to unknown heading in ' +
331− '`example.md`: `world`',
332− ' 35:10-35:32 warning Link to unknown file: ' +
333− '`world.md`',
334− ' 35:10-35:32 warning Link to unknown heading in ' +
335− '`world.md`: `hello`',
336− ' 37:10-37:72 warning Link to unknown file: ' +
337− '`world.md`',
338− ' 37:10-37:72 warning Link to unknown heading in ' +
339− '`world.md`: `hello`',
340− ' 39:10-39:73 warning Link to unknown heading in ' +
341− '`world.md`: `hello`',
342− ' 39:10-39:73 warning Link to unknown file: ' +
343− '`world.md`',
344− '',
345− '⚠ 30 warnings'
346− ].join('\n'),
347− 'should report'
348− );
349− }, clean);
350− });
265+ execa.stderr(bin, [
266+ '--no-config',
267+ '--no-ignore',
268+ '--use',
269+ '../..',
270+ 'example.md',
271+ 'examples/example.md'
272+ ]).then(function (stderr) {
273+ clean();
274+ st.equal(
275+ strip(stderr),
276+ [
277+ 'example.md',
278+ ' 5:37-5:51 warning Link to unknown heading: ' +
279+ '`world`',
280+ ' 19:34-19:102 warning Link to unknown file: ' +
281+ '`examples/world.md`',
282+ ' 21:12-21:81 warning Link to unknown file: ' +
283+ '`examples/world.md`',
284+ ' 23:10-23:37 warning Link to unknown file: ' +
285+ '`examples/world.md`',
286+ ' 25:10-25:35 warning Link to unknown file: ' +
287+ '`examples/world.md`',
288+ ' 37:10-37:42 warning Link to unknown heading in ' +
289+ '`examples/example.md`: `world`',
290+ ' 39:10-39:40 warning Link to unknown heading in ' +
291+ '`examples/example.md`: `world`',
292+ ' 41:10-41:83 warning Link to unknown heading in ' +
293+ '`examples/example.md`: `world`',
294+ ' 43:10-43:84 warning Link to unknown heading in ' +
295+ '`examples/example.md`: `world`',
296+ ' 45:10-45:40 warning Link to unknown file: ' +
297+ '`examples/world.md`',
298+ ' 45:10-45:40 warning Link to unknown heading in ' +
299+ '`examples/world.md`: `hello`',
300+ ' 47:10-47:38 warning Link to unknown file: ' +
301+ '`examples/world.md`',
302+ ' 47:10-47:38 warning Link to unknown heading in ' +
303+ '`examples/world.md`: `hello`',
304+ ' 49:10-49:81 warning Link to unknown file: ' +
305+ '`examples/world.md`',
306+ ' 49:10-49:81 warning Link to unknown heading in ' +
307+ '`examples/world.md`: `hello`',
308+ ' 51:10-51:82 warning Link to unknown heading in ' +
309+ '`examples/world.md`: `hello`',
310+ ' 51:10-51:82 warning Link to unknown file: ' +
311+ '`examples/world.md`',
312+ '',
313+ 'examples/example.md',
314+ ' 5:37-5:51 warning Link to unknown heading: ' +
315+ '`world`',
316+ ' 15:34-15:93 warning Link to unknown file: ' +
317+ '`world.md`',
318+ ' 17:12-17:72 warning Link to unknown file: ' +
319+ '`world.md`',
320+ ' 19:10-19:29 warning Link to unknown file: ' +
321+ '`world.md`',
322+ ' 29:10-29:34 warning Link to unknown heading in ' +
323+ '`example.md`: `world`',
324+ ' 31:10-31:74 warning Link to unknown heading in ' +
325+ '`example.md`: `world`',
326+ ' 33:10-33:75 warning Link to unknown heading in ' +
327+ '`example.md`: `world`',
328+ ' 35:10-35:32 warning Link to unknown file: ' +
329+ '`world.md`',
330+ ' 35:10-35:32 warning Link to unknown heading in ' +
331+ '`world.md`: `hello`',
332+ ' 37:10-37:72 warning Link to unknown file: ' +
333+ '`world.md`',
334+ ' 37:10-37:72 warning Link to unknown heading in ' +
335+ '`world.md`: `hello`',
336+ ' 39:10-39:73 warning Link to unknown heading in ' +
337+ '`world.md`: `hello`',
338+ ' 39:10-39:73 warning Link to unknown file: ' +
339+ '`world.md`',
340+ '',
341+ '⚠ 30 warnings'
342+ ].join('\n'),
343+ 'should report'
344+ );
345+ }, clean);
346+ });
351347
352− t.test('should suggest similar links', function (st) {
353− st.plan(1);
348+ t.test('should suggest similar links', function (st) {
349+ st.plan(1);
354350
355− execa.stderr(bin, [
356− '--no-config',
357− '--no-ignore',
358− '--use',
359− '.',
360− 'suggestions.md'
361− ]).then(function (stderr) {
362− st.equal(
363− strip(stderr),
364− [
365− 'suggestions.md',
366− ' 3:22-3:37 warning Link to unknown heading: ' +
367− '`helloo`. Did you mean `hello`',
368− ' 7:17-7:40 warning Link to unknown heading in ' +
369− '`example.md`: `fiiiles`. Did you mean `files`',
370− '',
371− '⚠ 2 warnings'
372− ].join('\n'),
373− 'should report'
374− );
375− });
351+ execa.stderr(bin, [
352+ '--no-config',
353+ '--no-ignore',
354+ '--use',
355+ '.',
356+ 'suggestions.md'
357+ ]).then(function (stderr) {
358+ st.equal(
359+ strip(stderr),
360+ [
361+ 'suggestions.md',
362+ ' 3:22-3:37 warning Link to unknown heading: ' +
363+ '`helloo`. Did you mean `hello`',
364+ ' 7:17-7:40 warning Link to unknown heading in ' +
365+ '`example.md`: `fiiiles`. Did you mean `files`',
366+ '',
367+ '⚠ 2 warnings'
368+ ].join('\n'),
369+ 'should report'
370+ );
376371 });
372+ });
377373});