Skip to content

Commit c613e26

Browse files
lilaconleeazu
authored andcommitted
feat(rule): Add ignore redirects (#106)
* Add ignoreRedirects option * Add ignoreRedirects to ReadMe
1 parent 3984344 commit c613e26

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

ReadMe.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ The default options are:
6363
"checkRelative": true,
6464
"baseURI": null,
6565
"ignore": [],
66-
"preferGET": []
66+
"preferGET": [],
67+
"ignoreRedirects": false
6768
}
6869
}
6970
}
@@ -96,7 +97,7 @@ Examples:
9697

9798
### ignore
9899

99-
An array of URIs or [glob](https://github.com/isaacs/node-glob "glob")s to be ignored.
100+
An array of URIs or [glob](https://github.com/isaacs/node-glob 'glob')s to be ignored.
100101
These list will be skipped from the availability checks.
101102

102103
Example:
@@ -126,6 +127,11 @@ Example:
126127
}
127128
```
128129

130+
### ignoreRedirects
131+
132+
This rule checks for redirects (3xx status codes) and consider's them an error by default.
133+
To ignore redirects during checks, set this value to `false`.
134+
129135
## Tests
130136

131137
```

src/no-dead-link.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ function reporter(context, options = {}) {
183183
const lintMessage = `${uri} is dead. (${message})`;
184184

185185
report(node, new RuleError(lintMessage, { index }));
186-
} else if (redirected) {
186+
} else if (redirected && !opts.ignoreRedirects) {
187187
const lintMessage = `${uri} is redirected to ${redirectTo}. (${message})`;
188188
const fix = fixer.replaceTextRange(
189189
[index, index + uri.length],

test/no-dead-link.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ tester.run('no-dead-link', rule, {
7979
preferGET: ['https://www.npmjs.com/search?q=textlint-rule'],
8080
},
8181
},
82+
{
83+
text:
84+
'should not treat https://httpstat.us/301 when `ignoreRedirects` is true',
85+
options: {
86+
ignoreRedirects: true,
87+
},
88+
},
8289
],
8390
invalid: [
8491
{

0 commit comments

Comments
 (0)