Skip to content

Commit ef0d837

Browse files
authored
feat: support ReferenceLink (#148)
* feat: support ReferenceLink * test: add mocha config * chore(dev): remove eslint and npm-run-all * chore: add keywords * fix: remove eslint
1 parent e1e0cdd commit ef0d837

File tree

10 files changed

+75
-970
lines changed

10 files changed

+75
-970
lines changed

.eslintrc

Lines changed: 0 additions & 15 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.DS_Store
22
node_modules
33
lib
4+
*.log

.mocharc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"require": [
3+
"textlint-scripts/register"
4+
],
5+
"timeout": "20000"
6+
}
File renamed without changes.

package.json

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"description": "A textlint rule to check if all links are alive",
55
"keywords": [
66
"rule",
7-
"textlint"
7+
"textlint",
8+
"textlintrule",
9+
"link-checker"
810
],
911
"homepage": "https://github.com/textlint-rule/textlint-rule-no-dead-link",
1012
"bugs": "https://github.com/textlint-rule/textlint-rule-no-dead-link/issues",
@@ -18,10 +20,8 @@
1820
"main": "lib/no-dead-link.js",
1921
"scripts": {
2022
"build": "textlint-scripts build",
21-
"lint": "eslint --fix src test",
22-
"unittest": "textlint-scripts test",
2323
"prepublish": "yarn run --if-present build",
24-
"test": "npm-run-all lint unittest",
24+
"test": "textlint-scripts test",
2525
"watch": "textlint-scripts build --watch",
2626
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"",
2727
"prepare": "git config --local core.hooksPath .githooks"
@@ -38,16 +38,10 @@
3838
"node-fetch": "^2.6.0",
3939
"p-memoize": "^3.1.0",
4040
"p-queue": "^6.2.0",
41-
"textlint-rule-helper": "^2.1.1"
41+
"textlint-rule-helper": "^2.2.2"
4242
},
4343
"devDependencies": {
44-
"eslint": "^8.25.0",
45-
"eslint-config-airbnb-base": "^15.0.0",
46-
"eslint-config-prettier": "^8.5.0",
47-
"eslint-plugin-immutable": "^1.0.0",
48-
"eslint-plugin-import": "^2.26.0",
4944
"lint-staged": "^13.0.3",
50-
"npm-run-all": "^4.1.5",
5145
"prettier": "^2.7.1",
5246
"textlint": "^12.2.2",
5347
"textlint-scripts": "^12.2.2",

src/no-dead-link.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ function reporter(context, options = {}) {
287287
? await isAliveLocalFile(uri)
288288
: await memorizedIsAliveURI(uri, method, maxRetryCount);
289289
const { ok, redirected, redirectTo, message } = result;
290-
// When ignoreRedirects is true, redirected should be ignore
290+
// When ignoreRedirects is true, redirected should be ignored
291291
if (redirected && ruleOptions.ignoreRedirects) {
292292
return;
293293
}
@@ -349,7 +349,26 @@ function reporter(context, options = {}) {
349349
});
350350
},
351351

352-
[`${context.Syntax.Document}:exit`]() {
352+
// Reference links is markdown specific
353+
Definition: function (node) {
354+
if (!node.url) {
355+
return;
356+
}
357+
358+
// Some link text[1]
359+
//
360+
// [1]: https://foo.bar
361+
// ^
362+
const indexOfUrl = node.raw.indexOf(node.url);
363+
const index = indexOfUrl !== -1 ? indexOfUrl : 0;
364+
URIs.push({
365+
node,
366+
uri: node.url,
367+
index
368+
});
369+
},
370+
371+
[Syntax.DocumentExit]() {
353372
const queue = new PQueue({
354373
concurrency: ruleOptions.concurrency,
355374
intervalCap: ruleOptions.intervalCap,

test/.eslintrc

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/mocha.opts

Lines changed: 0 additions & 2 deletions
This file was deleted.

test/no-dead-link.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,18 @@ tester.run("no-dead-link", rule, {
209209
column: 47
210210
}
211211
]
212+
},
213+
{
214+
text: `Support Reference link[^1] in Markdown.
215+
216+
[^1] https://httpstat.us/404`,
217+
errors: [
218+
{
219+
message: "https://httpstat.us/404 is dead. (404 Not Found)",
220+
line: 3,
221+
column: 6
222+
}
223+
]
212224
}
213225
]
214226
});

0 commit comments

Comments
 (0)