Skip to content

Commit

Permalink
feat(rule): add dotInIgnore option
Browse files Browse the repository at this point in the history
  • Loading branch information
kangetsu121 committed Aug 5, 2024
1 parent dd03ca8 commit d163480
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/no-dead-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type Options = {
checkRelative: boolean; // {boolean} `false` disables the checks for relative URIs.
baseURI: null | string; // {String|null} a base URI to resolve relative URIs.
ignore: string[]; // {Array<String>} URIs to be skipped from availability checks.
dotInIgnore: boolean; // {boolean} `true` allows ignore patterns to match filenames starting with a period
ignoreRedirects: boolean; // {boolean} `false` ignores redirect status codes.
preferGET: string[]; // {Array<String>} origins to prefer GET over HEAD.
retry: number; // {number} Max retry count
Expand All @@ -28,6 +29,7 @@ const DEFAULT_OPTIONS: Options = {
checkRelative: true, // {boolean} `false` disables the checks for relative URIs.
baseURI: null, // {String|null} a base URI to resolve relative URIs.
ignore: [], // {Array<String>} URIs to be skipped from availability checks.
dotInIgnore: false, // {boolean} `true` allows ignore patterns to match filenames starting with a period
ignoreRedirects: false, // {boolean} `false` ignores redirect status codes.
preferGET: [], // {Array<String>} origins to prefer GET over HEAD.
retry: 3, // {number} Max retry count
Expand Down Expand Up @@ -87,8 +89,8 @@ function isRedirect(code: number) {
return code === 301 || code === 302 || code === 303 || code === 307 || code === 308;
}

function isIgnored(uri: string, ignore: string[] = []) {
return ignore.some((pattern) => minimatch(uri, pattern));
function isIgnored(uri: string, ignore: string[] = [], dotInIgnore: boolean) {
return ignore.some((pattern) => minimatch(uri, pattern, { dot: dotInIgnore }));
}

/**
Expand Down Expand Up @@ -148,7 +150,7 @@ const createCheckAliveURL = (ruleOptions: Options) => {
/**
* Checks if a given URI is alive or not.
*
* Normally, this method following strategiry about retry
* Normally, this method following strategy about retry
*
* 1. Head
* 2. Get
Expand Down Expand Up @@ -277,7 +279,7 @@ const reporter: TextlintRuleReporter<Options> = (context, options) => {
* @param {number} maxRetryCount retry count of linting
*/
const lint = async ({ node, uri, index }: { node: TxtNode; uri: string; index: number }, maxRetryCount: number) => {
if (isIgnored(uri, ruleOptions.ignore)) {
if (isIgnored(uri, ruleOptions.ignore, ruleOptions.dotInIgnore)) {
return;
}

Expand Down
11 changes: 9 additions & 2 deletions test/no-dead-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ tester.run("no-dead-link", rule, {
ext: ".txt"
},
{
text: "should be able to check relative pathes when checkRelative is true: ![robot](index.html)",
text: "should be able to check relative paths when checkRelative is true: ![robot](index.html)",
options: {
baseURI: "https://example.com/"
}
Expand All @@ -44,6 +44,13 @@ tester.run("no-dead-link", rule, {
ignore: ["https://example.com/*"]
}
},
{
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.',
options: {
ignore: ["https://example.com/**"],
dotInIgnore: true
}
},
{
text: "should ignore relative URIs when `checkRelative` is false: [test](./a.md).",
options: {
Expand Down Expand Up @@ -210,7 +217,7 @@ tester.run("no-dead-link", rule, {
},
{
text: `Support Reference link[^1] in Markdown.
[^1] https://httpstat.us/404`,
errors: [
{
Expand Down

0 comments on commit d163480

Please sign in to comment.