Skip to content

Commit

Permalink
Merge pull request #4 from asyncink/or-expression
Browse files Browse the repository at this point in the history
feat: add support for multiple licenses with OR expression
  • Loading branch information
andrepolischuk authored Feb 28, 2023
2 parents a0831c6 + 685711f commit 3c1f94a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
cache: yarn
node-version: '16.x'
- run: yarn
- run: yarn build
Expand Down
20 changes: 12 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,23 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
cache: yarn
node-version: '16.x'
- run: yarn
- run: yarn test

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
cache: yarn
node-version: '16.x'
- run: yarn
- run: yarn lint
Expand All @@ -39,23 +41,25 @@ jobs:
licenselint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
cache: yarn
node-version: '16.x'
- run: yarn
- run: yarn licenselint

commitlint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Use Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
cache: yarn
node-version: '16.x'
- run: yarn
- uses: wagoid/commitlint-github-action@v3
Expand Down
6 changes: 5 additions & 1 deletion src/lint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ test('lint licenses', async () => {
test('lint licenses with deny list', async () => {
const options = {
production: true,
deny: ['Apache-2.0', 'BSD-2-Clause']
deny: ['Apache-2.0', 'BSD-2-Clause', 'CC0-1.0']
}
const results = await lint(entry, options)
const errors = results.filter((result) => result.error)
expect(errors.map((result) => result.licenses)).toContain('Apache-2.0')
expect(errors.map((result) => result.licenses)).toContain('BSD-2-Clause')
expect(errors.map((result) => result.licenses)).toContain('CC0-1.0')
expect(errors.map((result) => result.licenses)).not.toContain(
'(MIT OR CC0-1.0)'
)
})

test('lint licenses with allow list', async () => {
Expand Down
7 changes: 6 additions & 1 deletion src/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ export const lint = (
result.error = `${result.licenses} is not allowed by \`allow\` list`
}
} else if (deny.length > 0) {
const isDeny = deny.some(matchLicense(result.licenses ?? ''))
const multipleLicenses = result.licenses?.split(' OR ')
const isDeny = Array.isArray(multipleLicenses)
? multipleLicenses.every((license) =>
deny.some(matchLicense(license ?? ''))
)
: deny.some(matchLicense(result.licenses ?? ''))
if (isDeny) {
result.error = `${result.licenses} is denied by \`deny\` list`
}
Expand Down
12 changes: 11 additions & 1 deletion src/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@ test('load default options', async () => {
expect(options).toEqual({
...defaultOptions,
summary: true,
deny: ['GPL', 'LGPL', 'MPL', 'UNKNOWN', 'CUSTOM']
deny: [
'MPL.+2',
'EPL.+2',
'IPL.+1',
'GPL.+2',
'GPL.+3',
'AGPL.+3',
'LGPL.+2.1',
'UNKNOWN',
'CUSTOM'
]
})
})

Expand Down

0 comments on commit 3c1f94a

Please sign in to comment.