@@ -17,12 +17,12 @@ SPDX-License-Identifier: Apache-2.0
1717Copyright (c) OWASP Foundation. All Rights Reserved.
1818*/
1919
20-
2120import type NATIVE_FS from 'node:fs'
2221import type NATIVE_PATH from "node:path" ;
23- import { Attachment } from '../models/attachment'
24- import { AttachmentEncoding } from '../enums/attachmentEncoding'
22+
2523import { getMimeForLicenseFile } from '../_helpers/mime'
24+ import { AttachmentEncoding } from '../enums/attachmentEncoding'
25+ import { Attachment } from '../models/attachment'
2626
2727
2828interface FsUtils {
@@ -45,6 +45,9 @@ const LICENSE_FILENAME_PATTERN = /^(?:UN)?LICEN[CS]E|.\.LICEN[CS]E$|^NOTICE$/i
4545
4646type ErrorReporter = ( e :Error ) => void
4747
48+ /* eslint-disable-next-line @typescript-eslint/no-empty-function -- ack */
49+ function noop ( ) :void { }
50+
4851export class LicenseEvidenceFetcher {
4952 readonly #fs: FsUtils
5053 readonly #path: PathUtils
@@ -56,11 +59,13 @@ export class LicenseEvidenceFetcher {
5659 * @param options.path - If omitted, the native `node:path` is used.
5760 */
5861 constructor ( options : { fs ?: FsUtils , path ?: PathUtils } = { } ) {
62+ /* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-require-imports -- needed */
5963 this . #fs = options . fs ?? require ( 'node:fs' )
6064 this . #path = options . path ?? require ( 'node:path' )
65+ /* eslint-enable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-require-imports */
6166 }
6267
63- public * fetch ( prefixPath : string , onError : ErrorReporter = function ( ) { } ) : Generator < FetchResult > {
68+ * fetch ( prefixPath : string , onError : ErrorReporter = noop ) : Generator < FetchResult > {
6469 const files = this . #fs. readdirSync ( prefixPath )
6570 for ( const file of files ) {
6671 if ( ! LICENSE_FILENAME_PATTERN . test ( file ) ) {
@@ -88,7 +93,9 @@ export class LicenseEvidenceFetcher {
8893 }
8994 )
9095 }
91- } catch ( e ) {
96+ }
97+ /* c8 ignore next 3 */
98+ catch ( e ) {
9299 onError ( new Error ( `skipped license file ${ filePath } ` , { cause : e } ) )
93100 }
94101 }
0 commit comments