Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support ReferenceLink #148

Merged
merged 5 commits into from Oct 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 0 additions & 15 deletions .eslintrc

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
.DS_Store
node_modules
lib
*.log
6 changes: 6 additions & 0 deletions .mocharc.json
@@ -0,0 +1,6 @@
{
"require": [
"textlint-scripts/register"
],
"timeout": "20000"
}
File renamed without changes.
16 changes: 5 additions & 11 deletions package.json
Expand Up @@ -4,7 +4,9 @@
"description": "A textlint rule to check if all links are alive",
"keywords": [
"rule",
"textlint"
"textlint",
"textlintrule",
"link-checker"
],
"homepage": "https://github.com/textlint-rule/textlint-rule-no-dead-link",
"bugs": "https://github.com/textlint-rule/textlint-rule-no-dead-link/issues",
Expand All @@ -18,10 +20,8 @@
"main": "lib/no-dead-link.js",
"scripts": {
"build": "textlint-scripts build",
"lint": "eslint --fix src test",
"unittest": "textlint-scripts test",
"prepublish": "yarn run --if-present build",
"test": "npm-run-all lint unittest",
"test": "textlint-scripts test",
"watch": "textlint-scripts build --watch",
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"",
"prepare": "git config --local core.hooksPath .githooks"
Expand All @@ -38,16 +38,10 @@
"node-fetch": "^2.6.0",
"p-memoize": "^3.1.0",
"p-queue": "^6.2.0",
"textlint-rule-helper": "^2.1.1"
"textlint-rule-helper": "^2.2.2"
},
"devDependencies": {
"eslint": "^8.25.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-immutable": "^1.0.0",
"eslint-plugin-import": "^2.26.0",
"lint-staged": "^13.0.3",
"npm-run-all": "^4.1.5",
"prettier": "^2.7.1",
"textlint": "^12.2.2",
"textlint-scripts": "^12.2.2",
Expand Down
23 changes: 21 additions & 2 deletions src/no-dead-link.js
Expand Up @@ -287,7 +287,7 @@ function reporter(context, options = {}) {
? await isAliveLocalFile(uri)
: await memorizedIsAliveURI(uri, method, maxRetryCount);
const { ok, redirected, redirectTo, message } = result;
// When ignoreRedirects is true, redirected should be ignore
// When ignoreRedirects is true, redirected should be ignored
if (redirected && ruleOptions.ignoreRedirects) {
return;
}
Expand Down Expand Up @@ -349,7 +349,26 @@ function reporter(context, options = {}) {
});
},

[`${context.Syntax.Document}:exit`]() {
// Reference links is markdown specific
Definition: function (node) {
if (!node.url) {
return;
}

// Some link text[1]
//
// [1]: https://foo.bar
// ^
const indexOfUrl = node.raw.indexOf(node.url);
const index = indexOfUrl !== -1 ? indexOfUrl : 0;
URIs.push({
node,
uri: node.url,
index
});
},

[Syntax.DocumentExit]() {
const queue = new PQueue({
concurrency: ruleOptions.concurrency,
intervalCap: ruleOptions.intervalCap,
Expand Down
5 changes: 0 additions & 5 deletions test/.eslintrc

This file was deleted.

2 changes: 0 additions & 2 deletions test/mocha.opts

This file was deleted.

12 changes: 12 additions & 0 deletions test/no-dead-link.js
Expand Up @@ -209,6 +209,18 @@ tester.run("no-dead-link", rule, {
column: 47
}
]
},
{
text: `Support Reference link[^1] in Markdown.

[^1] https://httpstat.us/404`,
errors: [
{
message: "https://httpstat.us/404 is dead. (404 Not Found)",
line: 3,
column: 6
}
]
}
]
});