-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0814fd8
commit 81c0235
Showing
17 changed files
with
1,737 additions
and
130 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": ["@commitlint/config-conventional"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
{ | ||
"parser": "@typescript-eslint/parser", | ||
"extends": ["plugin:@typescript-eslint/recommended", "prettier"], | ||
"rules": { | ||
"@typescript-eslint/no-explicit-any": 0, | ||
"@typescript-eslint/no-unused-vars": ["error", {"argsIgnorePattern": "^_"}], | ||
"@typescript-eslint/explicit-function-return-type": [ | ||
"error", | ||
{"allowExpressions": true} | ||
] | ||
} | ||
"extends": [ | ||
"@rambler-tech/eslint-config", | ||
"@rambler-tech/eslint-config/ts", | ||
"prettier" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,3 @@ | ||
{ | ||
"summary": true, | ||
"deny": [ | ||
"MPL.+2", | ||
"EPL.+2", | ||
"IPL.+1", | ||
"GPL.+2", | ||
"GPL.+3", | ||
"AGPL.+3", | ||
"LGPL.+2.1", | ||
"UNKNOWN", | ||
"CUSTOM" | ||
] | ||
"extends": "@rambler-tech/licenselint-config" | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"*.{js,ts}": ["prettier --write", "eslint --fix"], | ||
"*.json": ["prettier --write"] | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"@rambler-tech/prettier-config" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ const results = [ | |
|
||
test('format success results', () => { | ||
const output = format(results, {}) | ||
|
||
expect(output).toContain(`[email protected] ${chalk.dim('MIT')}`) | ||
expect(output).toContain(`[email protected] ${chalk.dim('ISC')}`) | ||
expect(output).toContain(`[email protected] ${chalk.dim('MIT')}`) | ||
|
@@ -33,6 +34,7 @@ test('format error results', () => { | |
} | ||
] | ||
const output = format(resultsWithError, {}) | ||
|
||
expect(output).toContain(`[email protected] ${chalk.dim('MIT')}`) | ||
expect(output).toContain(`[email protected] ${chalk.dim('ISC')}`) | ||
expect(output).toContain(`1 error`) | ||
|
@@ -41,6 +43,7 @@ test('format error results', () => { | |
|
||
test('format summary success results', () => { | ||
const output = format(results, {summary: true}) | ||
|
||
expect(output).toContain(`MIT ${chalk.dim('2')}`) | ||
expect(output).toContain(`ISC ${chalk.dim('1')}`) | ||
}) | ||
|
@@ -55,6 +58,7 @@ test('format summary error results', () => { | |
} | ||
] | ||
const output = format(resultsWithError, {summary: true}) | ||
|
||
expect(output).toContain(`MIT ${chalk.dim('1')}`) | ||
expect(output).toContain(`ISC ${chalk.dim('1')}`) | ||
expect(output).toContain(`1 error`) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,63 @@ | ||
import {promisify} from 'util' | ||
import licenseChecker, {InitOpts, ModuleInfo} from 'license-checker' | ||
import {Options} from './options' | ||
|
||
const checkLicense = promisify(licenseChecker.init) | ||
|
||
const matchLicense = (license: string) => (reference: string) => | ||
// eslint-disable-next-line security/detect-non-literal-regexp | ||
license.match(new RegExp(reference, 'i')) | ||
|
||
export interface LicenseResult extends Omit<ModuleInfo, 'licenses'> { | ||
name: string | ||
licenses?: string | ||
error?: string | ||
} | ||
|
||
const matchLicense = (license: string) => (reference: string) => | ||
license.match(new RegExp(reference, 'i')) | ||
|
||
export const lint = ( | ||
export const lint = async ( | ||
entry: string, | ||
options: Options | ||
): Promise<LicenseResult[]> => | ||
new Promise<LicenseResult[]>((resolve, reject) => { | ||
const { | ||
production, | ||
development, | ||
deny = [], | ||
allow = [], | ||
exclude = [] | ||
} = options | ||
): Promise<LicenseResult[]> => { | ||
const {production, development, deny = [], allow = [], exclude = []} = options | ||
|
||
const checkerOptions: InitOpts = { | ||
start: entry, | ||
production, | ||
development, | ||
// NOTE fix wrong `exclude` type | ||
exclude: exclude.toString() as unknown as string[] | ||
} | ||
const checkerOptions: InitOpts = { | ||
start: entry, | ||
production, | ||
development, | ||
// NOTE fix wrong `exclude` type | ||
exclude: exclude.toString() as unknown as string[] | ||
} | ||
|
||
licenseChecker.init(checkerOptions, (error: Error, modulesInfo) => { | ||
if (error) { | ||
reject(error) | ||
return | ||
} | ||
const modulesInfo = await checkLicense(checkerOptions) | ||
|
||
return Object.entries(modulesInfo) | ||
.map<LicenseResult>(([name, {licenses, ...info}]) => ({ | ||
name, | ||
...info, | ||
licenses: Array.isArray(licenses) | ||
? `(${licenses.join(' AND ')})` | ||
: licenses | ||
})) | ||
.map((result) => { | ||
if (allow.length > 0) { | ||
const isNotAllow = !allow.some(matchLicense(result.licenses ?? '')) | ||
|
||
const results = Object.entries(modulesInfo) | ||
.map<LicenseResult>(([name, {licenses, ...info}]) => ({ | ||
name, | ||
...info, | ||
licenses: Array.isArray(licenses) | ||
? `(${licenses.join(' AND ')})` | ||
: licenses | ||
})) | ||
.map((result) => { | ||
if (allow.length > 0) { | ||
const isNotAllow = !allow.some(matchLicense(result.licenses ?? '')) | ||
if (isNotAllow) { | ||
result.error = `${result.licenses} is not allowed by \`allow\` list` | ||
} | ||
} else if (deny.length > 0) { | ||
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` | ||
} | ||
} | ||
return result | ||
}) | ||
if (isNotAllow) { | ||
result.error = `${result.licenses} is not allowed by \`allow\` list` | ||
} | ||
} else if (deny.length > 0) { | ||
const multipleLicenses = result.licenses?.split(' OR ') | ||
const isDeny = Array.isArray(multipleLicenses) | ||
? multipleLicenses.every((license) => | ||
deny.some(matchLicense(license ?? '')) | ||
) | ||
: deny.some(matchLicense(result.licenses ?? '')) | ||
|
||
resolve(results) | ||
if (isDeny) { | ||
result.error = `${result.licenses} is denied by \`deny\` list` | ||
} | ||
} | ||
|
||
return result | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.