diff --git a/lib/datasource/metadata.spec.ts b/lib/datasource/metadata.spec.ts index fff49ac554366dcbee50f3ad879aa00329d1f2cb..1e77729530e3e8a7801c0dad6d5d183347e0c8c8 100644 --- a/lib/datasource/metadata.spec.ts +++ b/lib/datasource/metadata.spec.ts @@ -5,10 +5,6 @@ import { PypiDatasource } from './pypi'; import type { ReleaseResult } from './types'; describe('datasource/metadata', () => { - it('Should do nothing if dep is not specified', () => { - expect(addMetaData()).toBeUndefined(); - }); - it('Should handle manualChangelogUrls', () => { const dep: ReleaseResult = { releases: [ diff --git a/lib/datasource/metadata.ts b/lib/datasource/metadata.ts index 35cc8d50e2ff81583d61d492e90b5fafb5e51a90..3cbc1c1e9843e12bf31758d420070d856389eb83 100644 --- a/lib/datasource/metadata.ts +++ b/lib/datasource/metadata.ts @@ -9,7 +9,7 @@ import type { ReleaseResult } from './types'; // Use this object to define changelog URLs for packages // Only necessary when the changelog data cannot be found in the package's source repository -const manualChangelogUrls = { +const manualChangelogUrls: Record<string, Record<string, string>> = { npm: { 'babel-preset-react-app': 'https://github.com/facebook/create-react-app/releases', @@ -66,7 +66,7 @@ const manualChangelogUrls = { // Use this object to define manual source URLs for packages // Only necessary if the datasource is unable to locate the source URL itself -const manualSourceUrls = { +const manualSourceUrls: Record<string, Record<string, string>> = { orb: { 'cypress-io/cypress': 'https://github.com/cypress-io/circleci-orb', 'hutson/library-release-workflows': @@ -189,22 +189,22 @@ function massageTimestamps(dep: ReleaseResult): void { } export function addMetaData( - dep?: ReleaseResult, - datasource?: string, - lookupName?: string + dep: ReleaseResult, + datasource: string, + lookupName: string ): void { - if (!dep) { - return; - } - massageTimestamps(dep); - const lookupNameLowercase = lookupName ? lookupName.toLowerCase() : null; - if (manualChangelogUrls[datasource]?.[lookupNameLowercase]) { - dep.changelogUrl = manualChangelogUrls[datasource][lookupNameLowercase]; + const lookupNameLowercase = lookupName.toLowerCase(); + const manualChangelogUrl = + manualChangelogUrls[datasource]?.[lookupNameLowercase]; + if (manualChangelogUrl) { + dep.changelogUrl = manualChangelogUrl; } - if (manualSourceUrls[datasource]?.[lookupNameLowercase]) { - dep.sourceUrl = manualSourceUrls[datasource][lookupNameLowercase]; + + const manualSourceUrl = manualSourceUrls[datasource]?.[lookupNameLowercase]; + if (manualSourceUrl) { + dep.sourceUrl = manualSourceUrl; } if ( @@ -246,12 +246,18 @@ export function addMetaData( } // Clean up any empty urls - const urls = ['homepage', 'sourceUrl', 'changelogUrl', 'dependencyUrl']; - for (const url of urls) { - if (is.string(dep[url]) && validateUrl(dep[url].trim())) { - dep[url] = dep[url].trim(); + const urlKeys: (keyof ReleaseResult)[] = [ + 'homepage', + 'sourceUrl', + 'changelogUrl', + 'dependencyUrl', + ]; + for (const urlKey of urlKeys) { + const urlVal = dep[urlKey]; + if (is.string(urlVal) && validateUrl(urlVal.trim())) { + dep[urlKey] = urlVal.trim() as never; } else { - delete dep[url]; + delete dep[urlKey]; } } } diff --git a/lib/manager/gradle/shallow/utils.ts b/lib/manager/gradle/shallow/utils.ts index cd1a562ccbcd6d598ad259c36568f9ef50dee3b3..d2fbc951bf681778b86cbf3f355ca9754a9eaa6c 100644 --- a/lib/manager/gradle/shallow/utils.ts +++ b/lib/manager/gradle/shallow/utils.ts @@ -15,7 +15,7 @@ const versionLikeRegex = regEx('^(?<version>[-.\\[\\](),a-zA-Z0-9+]+)'); // from the beginning of input export function versionLikeSubstring(input: string): string | null { const match = input ? versionLikeRegex.exec(input) : null; - return match ? match.groups.version : null; + return match?.groups?.version ?? null; } export function isDependencyString(input: string): boolean { @@ -40,7 +40,7 @@ export function isDependencyString(input: string): boolean { tempArtifactId, tempVersionPart, ]; - return ( + return !!( groupId && artifactId && versionPart && diff --git a/lib/manager/helm-values/util.ts b/lib/manager/helm-values/util.ts index d435b451c31134d9d2a16867d96df941e1574c2c..c8eb15e28c1a8684267039d5d3fc85fd8c79293b 100644 --- a/lib/manager/helm-values/util.ts +++ b/lib/manager/helm-values/util.ts @@ -23,7 +23,7 @@ export function matchesHelmValuesDockerHeuristic( parentKey: string, data: unknown ): data is HelmDockerImageDependency { - return ( + return !!( parentKeyRe.test(parentKey) && data && typeof data === 'object' && @@ -36,5 +36,5 @@ export function matchesHelmValuesInlineImage( parentKey: string, data: unknown ): data is string { - return parentKeyRe.test(parentKey) && data && typeof data === 'string'; + return !!(parentKeyRe.test(parentKey) && data && typeof data === 'string'); } diff --git a/lib/manager/npm/post-update/rules.ts b/lib/manager/npm/post-update/rules.ts index c3b8daddd98eb1cd6ccd10c76b8c598c58d4a547..a38b3cddb7404e37f421eedc5a707804d49b438b 100644 --- a/lib/manager/npm/post-update/rules.ts +++ b/lib/manager/npm/post-update/rules.ts @@ -19,7 +19,10 @@ export function processHostRules(): HostRulesResult { for (const hostRule of npmHostRules) { if (hostRule.resolvedHost) { let uri = hostRule.matchHost; - uri = validateUrl(uri) ? uri.replace(regEx(/^https?:/), '') : `//${uri}/`; + uri = + is.string(uri) && validateUrl(uri) + ? uri.replace(regEx(/^https?:/), '') + : `//${uri}/`; if (hostRule.token) { const key = hostRule.authType === 'Basic' ? '_auth' : '_authToken'; additionalNpmrcContent.push(`${uri}:${key}=${hostRule.token}`); diff --git a/lib/manager/pre-commit/parsing.ts b/lib/manager/pre-commit/parsing.ts index 642ba64354610c9326afaee32d4ef9e40ae4b912..25a2d3102cd3a190cb82e913649ff779bd44b3c2 100644 --- a/lib/manager/pre-commit/parsing.ts +++ b/lib/manager/pre-commit/parsing.ts @@ -12,7 +12,7 @@ import { PreCommitConfig, PreCommitDependency } from './types'; export function matchesPrecommitConfigHeuristic( data: unknown ): data is PreCommitConfig { - return data && typeof data === 'object' && hasKey('repos', data); + return !!(data && typeof data === 'object' && hasKey('repos', data)); } /** @@ -25,7 +25,7 @@ export function matchesPrecommitConfigHeuristic( export function matchesPrecommitDependencyHeuristic( data: unknown ): data is PreCommitDependency { - return ( + return !!( data && typeof data === 'object' && hasKey('repo', data) && diff --git a/lib/versioning/ruby/version.ts b/lib/versioning/ruby/version.ts index ff9cc717f50a43afe4f708a0122a02d98717d97c..fa90896076a77307f6f3cbae3bd1e22429268997 100644 --- a/lib/versioning/ruby/version.ts +++ b/lib/versioning/ruby/version.ts @@ -74,13 +74,13 @@ const increment = (from: string, to: string): string => { const isStable = (x: string): boolean => regEx(/^[0-9.-/]+$/).test(x); if (major(from) !== major(adapted)) { - nextVersion = [incrementMajor(maj, min, ptch, pre || []), 0, 0].join('.'); + nextVersion = [incrementMajor(maj, min, ptch, pre ?? []), 0, 0].join('.'); } else if (minor(from) !== minor(adapted)) { - nextVersion = [maj, incrementMinor(min, ptch, pre || []), 0].join('.'); + nextVersion = [maj, incrementMinor(min, ptch, pre ?? []), 0].join('.'); } else if (patch(from) !== patch(adapted)) { - nextVersion = [maj, min, incrementPatch(ptch, pre || [])].join('.'); + nextVersion = [maj, min, incrementPatch(ptch, pre ?? [])].join('.'); } else if (isStable(from) && isStable(adapted)) { - nextVersion = [maj, min, incrementPatch(ptch, pre || [])].join('.'); + nextVersion = [maj, min, incrementPatch(ptch, pre ?? [])].join('.'); } else { nextVersion = [maj, min, ptch].join('.'); } diff --git a/tsconfig.strict.json b/tsconfig.strict.json index f2c9059d43a16d157c605fd909c37489c510e0a8..1cda9093b7a1699a44015d0e73add6c3a42cbf5e 100644 --- a/tsconfig.strict.json +++ b/tsconfig.strict.json @@ -15,10 +15,20 @@ "lib/datasource/**/common.ts", "lib/datasource/**/types.ts", "lib/datasource/gitlab-tags/util.ts", + "lib/datasource/metadata.ts", + "lib/datasource/sbt-plugin/util.ts", "lib/globals.d.ts", "lib/logger/**/*.ts", "lib/manager/**/common.ts", "lib/manager/**/types.ts", + "lib/manager/ansible-galaxy/util.ts", + "lib/manager/argocd/util.ts", + "lib/manager/gitlabci/utils.ts", + "lib/manager/gradle/shallow/utils.ts", + "lib/manager/helm-values/util.ts", + "lib/manager/homebrew/util.ts", + "lib/manager/npm/post-update/rules.ts", + "lib/manager/terragrunt/util.ts", "lib/platform/**/types.ts", "lib/platform/github/graphql.ts", "lib/platform/utils/pr-body.ts", @@ -37,10 +47,12 @@ "lib/util/http/legacy.ts", "lib/util/http/types.ts", "lib/util/index.ts", + "lib/util/json-writer/code-format.ts", "lib/util/json-writer/indentation-type.ts", "lib/util/markdown.ts", "lib/util/mask.spec.ts", "lib/util/mask.ts", + "lib/util/modules.ts", "lib/util/object.ts", "lib/util/regex.spec.ts", "lib/util/regex.ts", @@ -48,6 +60,8 @@ "lib/util/split.ts", "lib/util/url.ts", "lib/versioning/maven/**/*.ts", + "lib/versioning/ruby/operator.ts", + "lib/versioning/ruby/version.ts", "lib/versioning/semver-coerced/**/*.ts", "lib/versioning/semver/**/*.ts", "lib/versioning/swift/**/*.ts",