Skip to content

Commit

Permalink
refactor: small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mjeanroy committed Aug 13, 2019
1 parent cf5e0f6 commit 14a550f
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions src/license-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,15 +424,39 @@ class LicensePlugin {
_scanLicenseViolation(dependency, allow) {
const license = dependency.license || 'UNLICENSED';
if (license === 'UNLICENSED') {
this.warn(`Dependency "${dependency.name}" does not specify any license.`);
this._handleUnlicensedDependency(dependency);
} else if (!spdxExpressionValidate(license) || !spdxSatisfies(license, allow)) {
this.warn(
`Dependency "${dependency.name}" has a license (${dependency.license}) which is not compatible with requirement (${allow}), ` +
`looks like a license violation to fix.`
);
this._handleLicenseViolation(dependency, allow);
}
}

/**
* Handle unlicensed dependency: print a warning to the console to alert for the dependency
* that should be fixed.
*
* @param {Object} dependency The dependency.
* @return {void}
*/
_handleUnlicensedDependency(dependency) {
this.warn(
`Dependency "${dependency.name}" does not specify any license.`
);
}

/**
* Handle license violation: print a warning to the console to alert about the violation.
*
* @param {Object} dependency The dependency.
* @param {*} allow The allowed expression.
* @return {void}
*/
_handleLicenseViolation(dependency, allow) {
this.warn(
`Dependency "${dependency.name}" has a license (${dependency.license}) which is not compatible with requirement (${allow}), ` +
`looks like a license violation to fix.`
);
}

/**
* Export scanned third party dependencies to a destination output (a function, a
* file written to disk, etc.).
Expand Down

0 comments on commit 14a550f

Please sign in to comment.