Skip to content

Commit

Permalink
feat: support ReferenceLink (#148)
Browse files Browse the repository at this point in the history
* feat: support ReferenceLink

* test: add mocha config

* chore(dev): remove eslint and npm-run-all

* chore: add keywords

* fix: remove eslint
  • Loading branch information
azu committed Oct 29, 2022
1 parent e1e0cdd commit ef0d837
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 970 deletions.
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
}
]
}
]
});

0 comments on commit ef0d837

Please sign in to comment.