diff --git a/lib/datasource/common.ts b/lib/datasource/common.ts index 47090ef8768a81ed6f02b9930bd6ad2e9194994a..c9355b9cbb73251d6f977bc380e4289ba2590b43 100644 --- a/lib/datasource/common.ts +++ b/lib/datasource/common.ts @@ -28,7 +28,7 @@ export interface GetPkgReleasesConfig extends ReleasesConfigBase { } export function isGetPkgReleasesConfig( - input: any + input: unknown ): input is GetPkgReleasesConfig { return ( (input as GetPkgReleasesConfig).datasource !== undefined && @@ -75,7 +75,7 @@ export interface DatasourceApi { getReleases(config: GetReleasesConfig): Promise<ReleaseResult | null>; defaultRegistryUrls?: string[]; appendRegistryUrls?: string[]; - defaultConfig?: object; + defaultConfig?: Record<string, unknown>; registryStrategy?: 'first' | 'hunt' | 'merge'; } diff --git a/lib/datasource/docker/index.spec.ts b/lib/datasource/docker/index.spec.ts index b6f5b38d80284a5d9d51b56013657f74406343c2..aeedd05c8042bc69080337f775b08792f239c2ba 100644 --- a/lib/datasource/docker/index.spec.ts +++ b/lib/datasource/docker/index.spec.ts @@ -230,7 +230,7 @@ describe(getName(__filename), () => { AWSMock.mock( 'ECR', 'getAuthorizationToken', - (params: {}, callback: Function) => { + (params: unknown, callback: (...unknown) => void) => { callback(null, { authorizationData: [{ authorizationToken: 'abcdef' }], }); @@ -262,7 +262,7 @@ describe(getName(__filename), () => { AWSMock.mock( 'ECR', 'getAuthorizationToken', - (params: {}, callback: Function) => { + (params: unknown, callback: (...unknown) => void) => { callback(null, {}); } ); @@ -291,7 +291,7 @@ describe(getName(__filename), () => { AWSMock.mock( 'ECR', 'getAuthorizationToken', - (params: {}, callback: Function) => { + (params: unknown, callback: (...unknown) => void) => { callback(Error('some error'), null); } ); diff --git a/lib/datasource/docker/index.ts b/lib/datasource/docker/index.ts index eed90202f88571db1f0ae6b4f0e3e27642b208db..a1ffbd65b147f584b6420119f6267bf449239e45 100644 --- a/lib/datasource/docker/index.ts +++ b/lib/datasource/docker/index.ts @@ -175,7 +175,7 @@ async function getAuthHeaders( } // prettier-ignore - const authUrl = `${authenticateHeader.parms.realm}?service=${authenticateHeader.parms.service}&scope=repository:${repository}:pull`; + const authUrl = `${String(authenticateHeader.parms.realm)}?service=${String(authenticateHeader.parms.service)}&scope=repository:${repository}:pull`; logger.trace( `Obtaining docker registry token for ${repository} using url ${authUrl}` ); @@ -497,7 +497,7 @@ async function getLabels( return {}; } let labels: Record<string, string> = {}; - const configDigest = manifest.config.digest; + const configDigest: string = manifest.config.digest; const headers = await getAuthHeaders(registry, repository); // istanbul ignore if: Should never be happen if (!headers) { diff --git a/lib/datasource/galaxy/index.ts b/lib/datasource/galaxy/index.ts index 48ef50b7c782dfc930ca84ee3fcd37a2ec9dd3f0..5f1e856d49e77886b9126ff4a421de995cb43c04 100644 --- a/lib/datasource/galaxy/index.ts +++ b/lib/datasource/galaxy/index.ts @@ -71,12 +71,9 @@ export async function getReleases({ }; result.dependencyUrl = galaxyProjectUrl; - if (resultObject.github_user && resultObject.github_repo) { - result.sourceUrl = - 'https://github.com/' + - resultObject.github_user + - '/' + - resultObject.github_repo; + const { github_user: user = null, github_repo: repo = null } = resultObject; + if (typeof user === 'string' && typeof repo === 'string') { + result.sourceUrl = `https://github.com/${user}/${repo}`; } result.releases = versions.map( diff --git a/lib/datasource/index.ts b/lib/datasource/index.ts index dbae11adc25d56cc680ec79ab3c85b123bb236c8..24fbc2d4d7938634b716b14e3f41147fec7fc53a 100644 --- a/lib/datasource/index.ts +++ b/lib/datasource/index.ts @@ -214,11 +214,10 @@ async function fetchReleases( function getRawReleases( config: GetReleasesInternalConfig ): Promise<ReleaseResult | null> { - const cacheKey = - cacheNamespace + - config.datasource + - config.lookupName + - config.registryUrls; + const { datasource, lookupName, registryUrls } = config; + const cacheKey = `${cacheNamespace}${datasource}${lookupName}${String( + registryUrls + )}`; // By returning a Promise and reusing it, we should only fetch each package at most once const cachedResult = memCache.get(cacheKey); // istanbul ignore if @@ -291,7 +290,9 @@ export function getDigest( ); } -export function getDefaultConfig(datasource: string): Promise<object> { +export function getDefaultConfig( + datasource: string +): Promise<Record<string, unknown>> { const loadedDatasource = load(datasource); - return Promise.resolve(loadedDatasource?.defaultConfig || {}); + return Promise.resolve(loadedDatasource?.defaultConfig || Object.create({})); } diff --git a/lib/datasource/npm/get.ts b/lib/datasource/npm/get.ts index 76e38c0ec8938bffdd150014753a2c6c93ff6a05..08ca613f5a8d93c0d5c00e932d86967303cd937a 100644 --- a/lib/datasource/npm/get.ts +++ b/lib/datasource/npm/get.ts @@ -45,6 +45,29 @@ export interface NpmDependency extends ReleaseResult { sourceDirectory?: string; } +interface NpmResponse { + _id: string; + name?: string; + versions?: Record< + string, + { + repository?: { + url: string; + directory: string; + }; + homepage?: string; + deprecated?: boolean; + gitHead?: string; + } + >; + repository?: { + url?: string; + directory?: string; + }; + homepage?: string; + time?: Record<string, string>; +} + export async function getDependency( packageName: string, retries = 3 @@ -135,8 +158,7 @@ export async function getDependency( headers, useCache, }; - // TODO: fix type - const raw = await http.getJson<any>(pkgUrl, opts); + const raw = await http.getJson<NpmResponse>(pkgUrl, opts); if (retries < 3) { logger.debug({ pkgUrl, retries }, 'Recovered from npm error'); } diff --git a/lib/datasource/npm/npmrc.ts b/lib/datasource/npm/npmrc.ts index c383519ae43523c60e0a51208e451870124296d1..dcc7e28c17d54270f64da43d009c979b2ef00b6d 100644 --- a/lib/datasource/npm/npmrc.ts +++ b/lib/datasource/npm/npmrc.ts @@ -39,7 +39,7 @@ function sanitize(key: string, val: string): void { add(val); const password = Buffer.from(val, 'base64').toString(); add(password); - const username = npmrc[key.replace(':_password', ':username')]; + const username: string = npmrc[key.replace(':_password', ':username')]; add(Buffer.from(`${username}:${password}`).toString('base64')); } } diff --git a/lib/datasource/nuget/v3.ts b/lib/datasource/nuget/v3.ts index d94c3c002e5a6fcf79e64b5d2e7d3b0e73ca6bd3..52db9e9d4a0c79cd12fb0d5036385b47b56c38bf 100644 --- a/lib/datasource/nuget/v3.ts +++ b/lib/datasource/nuget/v3.ts @@ -133,7 +133,7 @@ export async function getReleases( ).flat(); let homepage = null; - let latestStable = null; + let latestStable: string = null; const releases = catalogEntries.map( ({ version, published: releaseTimestamp, projectUrl }) => { const release: Release = { version }; diff --git a/lib/datasource/pypi/index.ts b/lib/datasource/pypi/index.ts index 76021275ad5fd90cae6640ba075df779e24e4690..d27b3f9d6f6f50916fe089be5d21147267b3870f 100644 --- a/lib/datasource/pypi/index.ts +++ b/lib/datasource/pypi/index.ts @@ -14,7 +14,7 @@ export const defaultRegistryUrls = [ ]; export const registryStrategy = 'merge'; -const github_repo_pattern = /^https?:\/\/github\.com\/[^\\/]+\/[^\\/]+$/; +const githubRepoPattern = /^https?:\/\/github\.com\/[^\\/]+\/[^\\/]+$/; const http = new Http(id); type PypiJSONRelease = { @@ -82,7 +82,7 @@ async function getDependency( if (dep.info?.home_page) { dependency.homepage = dep.info.home_page; - if (github_repo_pattern.exec(dep.info.home_page)) { + if (githubRepoPattern.exec(dep.info.home_page)) { dependency.sourceUrl = dep.info.home_page.replace('http://', 'https://'); } } @@ -96,7 +96,7 @@ async function getDependency( (lower.startsWith('repo') || lower === 'code' || lower === 'source' || - github_repo_pattern.exec(projectUrl)) + githubRepoPattern.exec(projectUrl)) ) { dependency.sourceUrl = projectUrl; } diff --git a/lib/datasource/repology/index.spec.ts b/lib/datasource/repology/index.spec.ts index bd08b9d04eb2237939ac6947622c8431e977a55e..844388c4c42112a649e675484c15c3311b8b1b1d 100644 --- a/lib/datasource/repology/index.spec.ts +++ b/lib/datasource/repology/index.spec.ts @@ -8,13 +8,13 @@ import { RepologyPackage, id as datasource } from '.'; const repologyApiHost = 'https://repology.org/'; -type mockResponse = { status: number; body?: string }; +type ResponseMock = { status: number; body?: string }; const mockProjectBy = ( repo: string, name: string, - binary: mockResponse, - source: mockResponse + binary: ResponseMock, + source: ResponseMock ) => { const endpoint = '/tools/project-by'; const defaultParams = { diff --git a/lib/datasource/rubygems/get-rubygems-org.ts b/lib/datasource/rubygems/get-rubygems-org.ts index 05dbf41e5abb1cd51005c8404a7506562bba943b..4bd78ff8bcf6eb1e002b9e1391c85d45962f0d8d 100644 --- a/lib/datasource/rubygems/get-rubygems-org.ts +++ b/lib/datasource/rubygems/get-rubygems-org.ts @@ -94,15 +94,15 @@ function isDataStale(): boolean { return minutesElapsed >= 5; } -let _updateRubyGemsVersions: Promise<void> | undefined; +let updateRubyGemsVersionsPromise: Promise<void> | undefined; async function syncVersions(): Promise<void> { if (isDataStale()) { - _updateRubyGemsVersions = + updateRubyGemsVersionsPromise = // eslint-disable-next-line @typescript-eslint/no-misused-promises - _updateRubyGemsVersions || updateRubyGemsVersions(); - await _updateRubyGemsVersions; - _updateRubyGemsVersions = null; + updateRubyGemsVersionsPromise || updateRubyGemsVersions(); + await updateRubyGemsVersionsPromise; + updateRubyGemsVersionsPromise = null; } }