Skip to content

Commit

Permalink
fix: fix handling of redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
azu committed Nov 8, 2021
1 parent c5a2dfe commit e834ab0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/no-dead-link.js
Expand Up @@ -295,17 +295,16 @@ function reporter(context, options = {}) {
: await memorizedIsAliveURI(uri, method, maxRetryCount);
const { ok, redirected, redirectTo, message } = result;

if (!ok) {
const lintMessage = `${uri} is dead. (${message})`;
report(node, new RuleError(lintMessage, { index }));
} else if (redirected && !ruleOptions.ignoreRedirects) {
if (redirected && !ruleOptions.ignoreRedirects) {
const lintMessage = `${uri} is redirected to ${redirectTo}. (${message})`;
const fix = fixer.replaceTextRange(
[index, index + uri.length],
redirectTo,
);

report(node, new RuleError(lintMessage, { fix, index }));
} else if (!ok) {
const lintMessage = `${uri} is dead. (${message})`;
report(node, new RuleError(lintMessage, { index }));
}
};

Expand Down
2 changes: 1 addition & 1 deletion test/no-dead-link.js
Expand Up @@ -17,7 +17,7 @@ tester.run('no-dead-link', rule, {
'should success with retrying on error: [npm results for textlint](https://www.npmjs.com/search?q=textlint)',
'should treat 200 OK as alive: https://httpstat.us/200',
'should treat 200 OK. It require User-Agent: Navigate to [MySQL distribution](https://dev.mysql.com/downloads/mysql/) to install MySQL `5.7`.',
'should treat 200 OK. It require User-Agent: https://tools.ietf.org/html/rfc6749',
'should treat 200 OK. It require User-Agent: https://datatracker.ietf.org/doc/html/rfc6749',
{
text:
'should be able to check a URL in a plain text: https://example.com/',
Expand Down

0 comments on commit e834ab0

Please sign in to comment.