diff --git a/lib/index.js b/lib/index.js index ebf2a77..c8e3fa0 100644 --- a/lib/index.js +++ b/lib/index.js @@ -536,17 +536,24 @@ exports.init = function init(args, callback) { } }; + /** + * Check if the current license contains (eventually among others) at least one of the allowed licenses + * + * @param {string} currentLicense The current license + * @param {} packageName The package name + */ const checkForOnlyAllow = (currentLicense, packageName) => { if (toCheckforOnlyAllow.length > 0) { - let hasOnlyAllowedPackages = false; + let containsOneOfAllowedPackages = false; - toCheckforOnlyAllow.forEach((allowedLicense) => { - if (currentLicense.indexOf(allowedLicense) >= 0) { - hasOnlyAllowedPackages = true; + for (const allowedLicense of toCheckforOnlyAllow) { + if (currentLicense.includes(allowedLicense)) { + containsOneOfAllowedPackages = true; + break; } - }); + } - if (!hasOnlyAllowedPackages) { + if (!containsOneOfAllowedPackages) { console.error( `Package "${packageName}" is licensed under "${currentLicense}" which is not permitted by the --onlyAllow flag. Exiting.`, );