From 1707652a223319fa1c29a2decf37e3d9f91c6ce0 Mon Sep 17 00:00:00 2001 From: Andrey Polischuk Date: Wed, 1 Mar 2023 18:25:04 +0300 Subject: [PATCH] feat: support option to exclude licenses by the list --- README.md | 1 + src/cli.ts | 6 ++++++ src/lint.test.ts | 9 +++++++++ src/lint.ts | 12 ++++++++++-- src/options.ts | 4 +++- 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2de5f5d..db2b9f3 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ licenselint --help --summary Output a summary of the license usage --deny Fail on an occurrence of the licenses of the deny list --allow Fail on an occurrence of the licenses not in the allow list + --exclude Exclude modules which licenses are in the list --extends Use custom configuration file Examples diff --git a/src/cli.ts b/src/cli.ts index 6bd5995..3d34cc3 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -20,6 +20,7 @@ const cli = meow( --summary Output a summary of the license usage --deny Fail on an occurrence of the licenses of the deny list --allow Fail on an occurrence of the licenses not in the allow list + --exclude Exclude modules which licenses are in the list --extends Use custom configuration file Examples @@ -54,6 +55,11 @@ const cli = meow( type: 'string', default: defaultArray, isMultiple: true + }, + exclude: { + type: 'string', + default: defaultArray, + isMultiple: true } } } diff --git a/src/lint.test.ts b/src/lint.test.ts index f072555..9349fef 100644 --- a/src/lint.test.ts +++ b/src/lint.test.ts @@ -36,3 +36,12 @@ test('lint licenses with allow list', async () => { expect(errors.map((result) => result.licenses)).not.toContain('MIT') expect(errors.map((result) => result.licenses)).not.toContain('ISC') }) + +test('lint licenses with exclude list', async () => { + const options = { + production: true, + exclude: ['Apache-2.0'] + } + const results = await lint(entry, options) + expect(results.map((result) => result.licenses)).not.toContain('Apache-2.0') +}) diff --git a/src/lint.ts b/src/lint.ts index 45831a5..49786f5 100644 --- a/src/lint.ts +++ b/src/lint.ts @@ -15,12 +15,20 @@ export const lint = ( options: Options ): Promise => new Promise((resolve, reject) => { - const {production, development, deny = [], allow = []} = options + const { + production, + development, + deny = [], + allow = [], + exclude = [] + } = options const checkerOptions: InitOpts = { start: entry, production, - development + development, + // NOTE fix wrong `exclude` type + exclude: exclude.toString() as unknown as string[] } licenseChecker.init(checkerOptions, (error: Error, modulesInfo) => { diff --git a/src/options.ts b/src/options.ts index 87d128d..7f5a2cd 100644 --- a/src/options.ts +++ b/src/options.ts @@ -7,6 +7,7 @@ export interface Options { summary?: boolean deny?: string[] allow?: string[] + exclude?: string[] } export const defaultOptions: Partial = { @@ -14,7 +15,8 @@ export const defaultOptions: Partial = { development: false, summary: false, deny: [], - allow: [] + allow: [], + exclude: [] } const defaultOptionsFileName = '.licenserc.json'