@@ -49,7 +49,7 @@ const ABOUT_CODE_LICENSE_REF_PREFIX = 'LicenseRef-scancode-'
4949
5050const ABOUT_CODE_LICENSE_KEYS = new Set (
5151 license_information . licenses
52- . filter ( ( license ) => ! license . deprecated && license . source === 'aboutCode' )
52+ . filter ( ( license ) => license . source === 'aboutCode' )
5353 . map ( ( license ) => license . license_key )
5454)
5555
@@ -73,49 +73,57 @@ function isAboutCodeLicense(licenseRefToCheck) {
7373 * Recursively checks if a parsed license expression contains not listed licenses.
7474 *
7575 * @param {import('license-expressions').ParsedSpdxExpression } parsedExpression - The parsed license expression
76- * @returns {boolean } True if the expression contains any license references, false otherwise
76+ * @returns {Array<string> } all not listed licenses
7777 */
78- function containsNotListedLicenses ( parsedExpression ) {
78+ function notListedLicenses ( parsedExpression ) {
79+ /** @type {Array<string> } */
80+ const deprecatedLicenses = [ ]
7981 // If it's a LicenseRef type directly
8082 if ( 'licenseRef' in parsedExpression ) {
81- return ! isAboutCodeLicense ( parsedExpression . licenseRef )
83+ if ( ! isAboutCodeLicense ( parsedExpression . licenseRef ) ) {
84+ deprecatedLicenses . push ( parsedExpression . licenseRef )
85+ }
8286 }
8387
8488 // If it's a conjunction, check both sides
8589 if ( 'conjunction' in parsedExpression ) {
86- return (
87- containsNotListedLicenses ( parsedExpression . left ) ||
88- containsNotListedLicenses ( parsedExpression . right )
89- )
90+ deprecatedLicenses . push ( ...notListedLicenses ( parsedExpression . left ) )
91+ deprecatedLicenses . push ( ...notListedLicenses ( parsedExpression . right ) )
9092 }
9193
92- // If it's a LicenseInfo type, it doesn't contain not listed licenses
93- return false
94+ // If it's a valid LicenseInfo type, it doesn't contain not listed license
95+ // Before we call this function we check that the whole expression is valid.
96+ // The expression is not valid, when it contains licences that are not listend
97+ // in the SPDX License List. (We check this in test 6.1.54)
98+
99+ return deprecatedLicenses
94100}
95101
96102/**
97- * Checks if a license expression string contains any document references.
103+ * Checks if a license expression string contains any not listed references.
98104 *
99105 * @param {string } licenseToCheck - The license expression to check
100- * @returns {boolean } True if the license expression contains any document references, false otherwise
106+ * @returns {Array<string> } True if the license expression contains any document references, false otherwise
101107 */
102- function hasNotListedLicenses ( licenseToCheck ) {
108+ function allNotListedLicenses ( licenseToCheck ) {
103109 const parseResult = parse ( licenseToCheck )
104- return containsNotListedLicenses ( parseResult )
110+ return notListedLicenses ( parseResult )
105111}
106112
107113/**
108114 * check if the license_expression contains license identifiers or exceptions
109115 * that are not listed in the SPDX license list or Aboutcode's "ScanCode LicenseDB"
110116 *
111117 * @param {string } licenseToCheck - The license expression to check
112- * @returns {boolean } True if the license has not listed licenses, false otherwise
118+ * @returns {Array<string> } True if the license has not listed licenses, false otherwise
113119 */
114- export function existsNotListedLicenses ( licenseToCheck ) {
115- return (
116- ! licenseToCheck ||
117- ( validate ( licenseToCheck ) . valid && hasNotListedLicenses ( licenseToCheck ) )
118- )
120+ export function getNotListedLicenses ( licenseToCheck ) {
121+ // Validate ensures that no invalid SPDX licenses are present
122+ if ( ! licenseToCheck || ! validate ( licenseToCheck ) . valid ) {
123+ return [ ]
124+ } else {
125+ return allNotListedLicenses ( licenseToCheck )
126+ }
119127}
120128
121129/**
@@ -163,16 +171,19 @@ export function mandatoryTest_6_1_55(doc) {
163171
164172 const licenseToCheck = doc . document . license_expression
165173 if ( isLangEnglishOrUnspecified ( doc . document . lang ) ) {
166- if ( existsNotListedLicenses ( licenseToCheck ) ) {
174+ const notListedLicenses = getNotListedLicenses ( licenseToCheck )
175+ if ( notListedLicenses . length > 0 ) {
167176 const notes = doc . document . notes
168177 if ( ! notes || ! containsOneLegalNote ( notes ) ) {
169178 ctx . isValid = false
170179 ctx . errors . push ( {
171180 instancePath : '/document/notes' ,
172181 message :
173- `The license_expression contains a license identifiers or exceptions that is not ` +
174- `listed in Aboutcode's or SPDX license list. Therefore exactly one note with ` +
175- ` title 'License' and category 'legal_disclaimer' must exist` ,
182+ `The license_expression contains the following license identifiers that ` +
183+ `are nor listed in Aboutcode's or SPDX license list: ` +
184+ `"${ notListedLicenses . join ( ) } ". ` +
185+ `Therefore exactly one note with ` +
186+ `title "License" and category "legal_disclaimer" must exist` ,
176187 } )
177188 }
178189 }
0 commit comments