Skip to content

Commit a6df911

Browse files
authored
feat(rule): add dotInIgnore option (#153)
* chore: Format markdown * feat(rule): add `dotInIgnore` option * docs: add `dotInIgnore` option
1 parent 8b4673d commit a6df911

File tree

3 files changed

+36
-18
lines changed

3 files changed

+36
-18
lines changed

README.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ The primary target of this rule is Markdown documents, but it also works on plai
1111

1212
## Installation
1313

14-
```
15-
$ npm install textlint-rule-no-dead-link
14+
```shell
15+
npm install textlint-rule-no-dead-link
1616
```
1717

1818
## Usage
1919

20-
```
21-
$ npm install textlint textlint-rule-no-dead-link
22-
$ textlint --rule textlint-rule-no-dead-link text-to-check.txt
20+
```shell
21+
npm install textlint textlint-rule-no-dead-link
22+
textlint --rule textlint-rule-no-dead-link text-to-check.txt
2323
```
2424

2525
## Features
@@ -60,8 +60,9 @@ The default options are:
6060
"checkRelative": true,
6161
"baseURI": null,
6262
"ignore": [],
63-
"preferGET": [],
63+
"dotInIgnore": false,
6464
"ignoreRedirects": false,
65+
"preferGET": [],
6566
"retry": 3,
6667
"userAgent": "textlint-rule-no-dead-link/1.0",
6768
"maxRetryTime": 10,
@@ -112,6 +113,14 @@ Example:
112113
}
113114
```
114115

116+
### dotInIgnore
117+
118+
This rule allows ignore patterns to match filenames starting with a period.
119+
For example, if the `ignore` option contains `"http://example.com/**"` and the `dotInIgnore` option is set to `true`, paths containing filenames that start with `.` (like `"http://example.com/.hidden/index.html"`) will be ignored.
120+
You can disable this behavior by setting `dotInIgnore` to `false`.
121+
122+
_cf_, <https://github.com/isaacs/minimatch?tab=readme-ov-file#dot>
123+
115124
### preferGET
116125

117126
An array of [origins](https://url.spec.whatwg.org/#origin) to lets the rule connect to the origin's URL by `GET` instead of default `HEAD` request.
@@ -133,7 +142,7 @@ Example:
133142
This rule checks for redirects (3xx status codes) and consider's them an error by default.
134143
To ignore redirects during checks, set this value to `false`.
135144

136-
<!-- Experimental
145+
<!-- Experimental
137146
138147
### concurrency
139148
@@ -170,17 +179,17 @@ Default: `10`
170179
## CI Integration
171180

172181
Probably, Link Checking take long times.
173-
We recommened to use cron job like GitHub Actions.
182+
We recommend to use cron job like GitHub Actions.
174183

175184
### textlint + [SARIF output](https://www.npmjs.com/package/@microsoft/eslint-formatter-sarif) + [code scanning](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/about-code-scanning)
176185

177186
Preparing:
178187

179188
```shell
180189
# Install dependencies
181-
$ npm install --save-dev textlint @microsoft/eslint-formatter-sarif textlint-rule-no-dead-link
190+
npm install --save-dev textlint @microsoft/eslint-formatter-sarif textlint-rule-no-dead-link
182191
# Create .textlintrc
183-
$ npx textlint --init
192+
npx textlint --init
184193
```
185194

186195
Following actions check links and upload the status to [code scanning](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/about-code-scanning).
@@ -219,7 +228,7 @@ jobs:
219228
220229
## Tests
221230
222-
```
231+
```shell
223232
npm test
224233
```
225234

@@ -233,4 +242,4 @@ npm test
233242

234243
## License
235244

236-
MIT License (http://nodaguti.mit-license.org/)
245+
MIT License (<http://nodaguti.mit-license.org/>)

src/no-dead-link.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export type Options = {
1414
checkRelative: boolean; // {boolean} `false` disables the checks for relative URIs.
1515
baseURI: null | string; // {String|null} a base URI to resolve relative URIs.
1616
ignore: string[]; // {Array<String>} URIs to be skipped from availability checks.
17+
dotInIgnore: boolean; // {boolean} `true` allows ignore patterns to match filenames starting with a period
1718
ignoreRedirects: boolean; // {boolean} `false` ignores redirect status codes.
1819
preferGET: string[]; // {Array<String>} origins to prefer GET over HEAD.
1920
retry: number; // {number} Max retry count
@@ -28,6 +29,7 @@ const DEFAULT_OPTIONS: Options = {
2829
checkRelative: true, // {boolean} `false` disables the checks for relative URIs.
2930
baseURI: null, // {String|null} a base URI to resolve relative URIs.
3031
ignore: [], // {Array<String>} URIs to be skipped from availability checks.
32+
dotInIgnore: false, // {boolean} `true` allows ignore patterns to match filenames starting with a period
3133
ignoreRedirects: false, // {boolean} `false` ignores redirect status codes.
3234
preferGET: [], // {Array<String>} origins to prefer GET over HEAD.
3335
retry: 3, // {number} Max retry count
@@ -87,8 +89,8 @@ function isRedirect(code: number) {
8789
return code === 301 || code === 302 || code === 303 || code === 307 || code === 308;
8890
}
8991

90-
function isIgnored(uri: string, ignore: string[] = []) {
91-
return ignore.some((pattern) => minimatch(uri, pattern));
92+
function isIgnored(uri: string, ignore: string[] = [], dotInIgnore: boolean) {
93+
return ignore.some((pattern) => minimatch(uri, pattern, { dot: dotInIgnore }));
9294
}
9395

9496
/**
@@ -148,7 +150,7 @@ const createCheckAliveURL = (ruleOptions: Options) => {
148150
/**
149151
* Checks if a given URI is alive or not.
150152
*
151-
* Normally, this method following strategiry about retry
153+
* Normally, this method following strategy about retry
152154
*
153155
* 1. Head
154156
* 2. Get
@@ -277,7 +279,7 @@ const reporter: TextlintRuleReporter<Options> = (context, options) => {
277279
* @param {number} maxRetryCount retry count of linting
278280
*/
279281
const lint = async ({ node, uri, index }: { node: TxtNode; uri: string; index: number }, maxRetryCount: number) => {
280-
if (isIgnored(uri, ruleOptions.ignore)) {
282+
if (isIgnored(uri, ruleOptions.ignore, ruleOptions.dotInIgnore)) {
281283
return;
282284
}
283285

test/no-dead-link.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ tester.run("no-dead-link", rule, {
2727
ext: ".txt"
2828
},
2929
{
30-
text: "should be able to check relative pathes when checkRelative is true: ![robot](index.html)",
30+
text: "should be able to check relative paths when checkRelative is true: ![robot](index.html)",
3131
options: {
3232
baseURI: "https://example.com/"
3333
}
@@ -44,6 +44,13 @@ tester.run("no-dead-link", rule, {
4444
ignore: ["https://example.com/*"]
4545
}
4646
},
47+
{
48+
text: 'should ignore URLs containing . in their path in the "ignore" option that glob formatted if option is enabled: https://example.com/.hidden/404.html shouldn\'t be checked.',
49+
options: {
50+
ignore: ["https://example.com/**"],
51+
dotInIgnore: true
52+
}
53+
},
4754
{
4855
text: "should ignore relative URIs when `checkRelative` is false: [test](./a.md).",
4956
options: {
@@ -210,7 +217,7 @@ tester.run("no-dead-link", rule, {
210217
},
211218
{
212219
text: `Support Reference link[^1] in Markdown.
213-
220+
214221
[^1] https://httpstat.us/404`,
215222
errors: [
216223
{

0 commit comments

Comments
 (0)