Skip to content

Commit 5ca5a46

Browse files
authoredMay 7, 2022
feat: allow --skip to be defined multiple times (#399)
1 parent 9c2b5d8 commit 5ca5a46

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed
 

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
[![npm version](https://img.shields.io/npm/v/linkinator)](https://www.npmjs.org/package/linkinator)
66
[![Build Status](https://img.shields.io/github/workflow/status/JustinBeckwith/linkinator/ci/main)](https://github.com/JustinBeckwith/linkinator/actions?query=branch%3Amain+workflow%3Aci)
7-
[![codecov](https://img.shields.io/codecov/c/github/JustinBeckwith/linkinator/main)](https://codecov.io/gh/JustinBeckwith/linkinator)
7+
[![codecov](https://img.shields.io/codecov/c/github/JustinBeckwith/linkinator/main)](https://app.codecov.io/gh/JustinBeckwith/linkinator)
88
[![Known Vulnerabilities](https://img.shields.io/snyk/vulnerabilities/github/JustinBeckwith/linkinator)](https://snyk.io/test/github/JustinBeckwith/linkinator)
99
[![Code Style: Google](https://img.shields.io/badge/code%20style-google-blueviolet)](https://github.com/google/gts)
1010
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079)](https://github.com/semantic-release/semantic-release)

‎src/cli.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ const cli = meow(
103103
config: {type: 'string'},
104104
concurrency: {type: 'number'},
105105
recurse: {type: 'boolean', alias: 'r'},
106-
skip: {type: 'string', alias: 's'},
106+
skip: {type: 'string', alias: 's', isMultiple: true},
107107
format: {type: 'string', alias: 'f'},
108108
silent: {type: 'boolean'},
109109
timeout: {type: 'number'},
@@ -184,7 +184,14 @@ async function main() {
184184
if (typeof flags.skip === 'string') {
185185
opts.linksToSkip = flags.skip.split(/[\s,]+/).filter(x => !!x);
186186
} else if (Array.isArray(flags.skip)) {
187-
opts.linksToSkip = flags.skip;
187+
// with `isMultiple` enabled in meow, a comma delimeted list will still
188+
// be passed as an array, but with a single element that still needs to
189+
// be split.
190+
opts.linksToSkip = [];
191+
for (const skip of flags.skip) {
192+
const rules = skip.split(/[\s,]+/).filter(x => !!x);
193+
opts.linksToSkip.push(...rules);
194+
}
188195
}
189196
}
190197
if (flags.urlRewriteSearch && flags.urlRewriteReplace) {

‎src/config.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export interface Flags {
44
concurrency?: number;
55
config?: string;
66
recurse?: boolean;
7-
skip?: string;
7+
skip?: string | string[];
88
format?: string;
99
silent?: boolean;
1010
verbosity?: string;
@@ -42,7 +42,10 @@ export async function getConfig(flags: Flags) {
4242
// doesn't blast away config level settings.
4343
const strippedFlags = Object.assign({}, flags);
4444
Object.entries(strippedFlags).forEach(([key, value]) => {
45-
if (typeof value === 'undefined') {
45+
if (
46+
typeof value === 'undefined' ||
47+
(Array.isArray(value) && value.length === 0)
48+
) {
4649
delete (strippedFlags as {[index: string]: {}})[key];
4750
}
4851
});

‎test/test.cli.ts

+18
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,24 @@ describe('cli', function () {
7373
assert.match(stderr, /scanned 2 links/);
7474
});
7575

76+
it('should allow --skip multiple times', async () => {
77+
const res = await execa(node, [
78+
linkinator,
79+
'--verbosity',
80+
'INFO',
81+
'--skip',
82+
'LICENSE.md',
83+
'--skip',
84+
'unlinked.md',
85+
'test/fixtures/markdown/README.md',
86+
]);
87+
const stdout = stripAnsi(res.stdout);
88+
const stderr = stripAnsi(res.stderr);
89+
assert.match(stdout, /\[SKP\]/);
90+
// make sure we don't report skipped links in the count
91+
assert.match(stderr, /scanned 2 links/);
92+
});
93+
7694
it('should provide CSV if asked nicely', async () => {
7795
const res = await execa(node, [
7896
linkinator,

0 commit comments

Comments
 (0)
Please sign in to comment.