Skip to content

Commit d79ef62

Browse files
authored
feat: enable the pMemoize's parameter maxAge to be passed as a rule option (#169)
* feat: enable the `pMemoize`'s parameter `maxAge` to be passed as a rule option * docs: write about the option `linkMaxAge`
1 parent f583765 commit d79ef62

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ The default options are:
6666
"retry": 3,
6767
"userAgent": "textlint-rule-no-dead-link/1.0",
6868
"maxRetryTime": 10,
69-
"maxRetryAfterTime": 90
69+
"maxRetryAfterTime": 90,
70+
"linkMaxAge": 30000
7071
}
7172
}
7273
}
@@ -176,6 +177,12 @@ This `maxRetryAfterTime` option is for that `Retry-After`.
176177

177178
Default: `10`
178179

180+
### linkMaxAge
181+
182+
The time (in milliseconds) that the cache for the result indicating whether a link is available.
183+
184+
Default: `30000`
185+
179186
## CI Integration
180187

181188
Probably, Link Checking take long times.

src/no-dead-link.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export type Options = {
2222
userAgent: string; // {String} a UserAgent,
2323
maxRetryTime: number; // (number) The max of waiting seconds for retry. It is related to `retry` option. It does affect to `Retry-After` header.
2424
maxRetryAfterTime: number; // (number) The max of waiting seconds for `Retry-After` header.
25+
linkMaxAge: number; // (number) The max age in milliseconds for caching link check results.
2526
};
2627
const DEFAULT_OPTIONS: Options = {
2728
checkRelative: true, // {boolean} `false` disables the checks for relative URIs.
@@ -36,7 +37,8 @@ const DEFAULT_OPTIONS: Options = {
3637
intervalCap: 8, // The max number of runs in the given interval of time. [Experimental]
3738
userAgent: "textlint-rule-no-dead-link/1.0", // {String} a UserAgent,
3839
maxRetryTime: 10, // (number) The max of waiting seconds for retry. It is related to `retry` option. It does affect to `Retry-After` header.
39-
maxRetryAfterTime: 10 // (number) The max of waiting seconds for `Retry-After` header.
40+
maxRetryAfterTime: 10, // (number) The max of waiting seconds for `Retry-After` header.
41+
linkMaxAge: 30 * 1000 // (number) The max age in milliseconds for caching link check results.
4042
};
4143

4244
// Adopted from http://stackoverflow.com/a/3809435/951517
@@ -289,9 +291,8 @@ const reporter: TextlintRuleReporter<Options> = (context, options) => {
289291
const helper = new RuleHelper(context);
290292
const ruleOptions = { ...DEFAULT_OPTIONS, ...options };
291293
const isAliveURI = createCheckAliveURL(ruleOptions);
292-
// 30sec memorized
293294
const memorizedIsAliveURI = pMemoize(isAliveURI, {
294-
maxAge: 30 * 1000
295+
maxAge: ruleOptions.linkMaxAge
295296
});
296297
/**
297298
* Checks a given URI's availability and report if it is dead.

0 commit comments

Comments
 (0)