From 3357e6333deb46c279937c705dfc85c574de5170 Mon Sep 17 00:00:00 2001 From: Rhys Arkins Date: Thu, 11 Mar 2021 08:03:37 +0100 Subject: [PATCH] refactor: Object.assign -> object spread (#9076) --- lib/config/index.ts | 4 ++-- lib/config/massage.ts | 4 ++-- lib/config/types.ts | 2 +- lib/config/utils.ts | 10 +++++----- lib/datasource/packagist/index.ts | 4 ++-- lib/manager/cocoapods/extract.ts | 4 ++-- lib/manager/gradle-lite/parser.ts | 4 ++-- lib/manager/npm/extract/index.ts | 4 ++-- lib/platform/bitbucket/index.ts | 5 +++-- lib/util/exec/env.ts | 2 +- lib/workers/branch/get-updated.ts | 4 ++-- lib/workers/branch/index.ts | 6 +++--- lib/workers/repository/init/vulnerability.ts | 7 ++++--- lib/workers/repository/process/fetch.ts | 7 +++++-- lib/workers/repository/updates/generate.ts | 10 ++++++---- lib/workers/types.ts | 3 +-- 16 files changed, 43 insertions(+), 37 deletions(-) diff --git a/lib/config/index.ts b/lib/config/index.ts index bce88b454c..df118c916d 100644 --- a/lib/config/index.ts +++ b/lib/config/index.ts @@ -57,7 +57,7 @@ export async function parseConfigs( const cliConfig = await resolveConfigPresets(cliParser.getConfig(argv)); const envConfig = await resolveConfigPresets(envParser.getConfig(env)); - let config = mergeChildConfig(fileConfig, envConfig); + let config: GlobalConfig = mergeChildConfig(fileConfig, envConfig); config = mergeChildConfig(config, cliConfig); const combinedConfig = config; @@ -73,7 +73,7 @@ export async function parseConfigs( delete forcedCli.token; delete forcedCli.hostRules; if (config.force) { - config.force = Object.assign(config.force, forcedCli); + config.force = { ...config.force, ...forcedCli }; } else { config.force = forcedCli; } diff --git a/lib/config/massage.ts b/lib/config/massage.ts index 414bab6124..6d205d86ad 100644 --- a/lib/config/massage.ts +++ b/lib/config/massage.ts @@ -57,10 +57,10 @@ export function massageConfig(config: RenovateConfig): RenovateConfig { PackageRule ][]) { if (updateTypes.includes(key)) { - const newRule = clone(rule); + let newRule = clone(rule); newRule.matchUpdateTypes = rule.matchUpdateTypes || []; newRule.matchUpdateTypes.push(key); - Object.assign(newRule, val); + newRule = { ...newRule, ...val }; newRules.push(newRule); } } diff --git a/lib/config/types.ts b/lib/config/types.ts index 3cfb9d7052..882266c56a 100644 --- a/lib/config/types.ts +++ b/lib/config/types.ts @@ -151,7 +151,7 @@ export interface RenovateConfig defaultBranch?: string; branchList?: string[]; description?: string | string[]; - + force?: RenovateConfig; errors?: ValidationMessage[]; gitAuthor?: string; diff --git a/lib/config/utils.ts b/lib/config/utils.ts index 51216d1062..5f08e216c3 100644 --- a/lib/config/utils.ts +++ b/lib/config/utils.ts @@ -22,10 +22,10 @@ export function mergeChildConfig( ) { logger.trace(`mergeable option: ${option.name}`); if (option.name === 'constraints') { - config[option.name] = Object.assign( - parentConfig[option.name], - childConfig[option.name] - ); + config[option.name] = { + ...parentConfig[option.name], + ...childConfig[option.name], + }; } else if (option.type === 'array') { config[option.name] = (parentConfig[option.name] as unknown[]).concat( config[option.name] @@ -42,5 +42,5 @@ export function mergeChildConfig( ); } } - return Object.assign(config, config.force); + return { ...config, ...config.force }; } diff --git a/lib/datasource/packagist/index.ts b/lib/datasource/packagist/index.ts index 2114d44392..654854a3a7 100644 --- a/lib/datasource/packagist/index.ts +++ b/lib/datasource/packagist/index.ts @@ -19,13 +19,13 @@ const http = new Http(id); // We calculate auth at this datasource layer so that we can know whether it's safe to cache or not function getHostOpts(url: string): HttpOptions { - const opts: HttpOptions = {}; + let opts: HttpOptions = {}; const { username, password } = hostRules.find({ hostType: id, url, }); if (username && password) { - Object.assign(opts, { username, password }); + opts = { ...opts, username, password }; } return opts; } diff --git a/lib/manager/cocoapods/extract.ts b/lib/manager/cocoapods/extract.ts index bb37d716f7..c6f88feba6 100644 --- a/lib/manager/cocoapods/extract.ts +++ b/lib/manager/cocoapods/extract.ts @@ -27,14 +27,14 @@ export interface ParsedLine { } export function parseLine(line: string): ParsedLine { - const result: ParsedLine = {}; + let result: ParsedLine = {}; if (!line) { return result; } for (const regex of Object.values(regexMappings)) { const match = regex.exec(line.replace(/#.*$/, '')); if (match?.groups) { - Object.assign(result, match.groups); + result = { ...result, ...match.groups }; } } diff --git a/lib/manager/gradle-lite/parser.ts b/lib/manager/gradle-lite/parser.ts index e428347bbe..ace0340482 100644 --- a/lib/manager/gradle-lite/parser.ts +++ b/lib/manager/gradle-lite/parser.ts @@ -469,7 +469,7 @@ export function parseGradle( initVars: PackageVariables = {}, packageFile?: string ): ParseGradleResult { - const vars: PackageVariables = { ...initVars }; + let vars: PackageVariables = { ...initVars }; const deps: PackageDependency[] = []; const urls = []; @@ -481,7 +481,7 @@ export function parseGradle( deps.push(...matchResult.deps); } if (matchResult?.vars) { - Object.assign(vars, matchResult.vars); + vars = { ...vars, ...matchResult.vars }; } if (matchResult?.urls) { urls.push(...matchResult.urls); diff --git a/lib/manager/npm/extract/index.ts b/lib/manager/npm/extract/index.ts index 88adf5139d..3b6893eedc 100644 --- a/lib/manager/npm/extract/index.ts +++ b/lib/manager/npm/extract/index.ts @@ -307,14 +307,14 @@ export async function extractPackageFile( packageJson[depType] as NpmPackageDependency )) { const depName = parseDepName(depType, key); - const dep: PackageDependency = { + let dep: PackageDependency = { depType, depName, }; if (depName !== key) { dep.managerData = { key }; } - Object.assign(dep, extractDependency(depType, depName, val)); + dep = { ...dep, ...extractDependency(depType, depName, val) }; if (depName === 'node') { // This is a special case for Node.js to group it together with other managers dep.commitMessageTopic = 'Node.js'; diff --git a/lib/platform/bitbucket/index.ts b/lib/platform/bitbucket/index.ts index 558f02e563..c434d3244f 100644 --- a/lib/platform/bitbucket/index.ts +++ b/lib/platform/bitbucket/index.ts @@ -139,11 +139,12 @@ export async function initRepo({ ); config.defaultBranch = info.mainbranch; - Object.assign(config, { + config = { + ...config, owner: info.owner, mergeMethod: info.mergeMethod, has_issues: info.has_issues, - }); + }; logger.debug(`${repository} owner = ${config.owner}`); } catch (err) /* istanbul ignore next */ { diff --git a/lib/util/exec/env.ts b/lib/util/exec/env.ts index a01d136305..13ff2975a5 100644 --- a/lib/util/exec/env.ts +++ b/lib/util/exec/env.ts @@ -16,7 +16,7 @@ export function getChildProcessEnv( ): NodeJS.ProcessEnv { const env: NodeJS.ProcessEnv = {}; if (getAdminConfig().trustLevel === 'high') { - return Object.assign(env, process.env); + return { ...env, ...process.env }; } const envVars = [...basicEnvVars, ...customEnvVars]; envVars.forEach((envVar) => { diff --git a/lib/workers/branch/get-updated.ts b/lib/workers/branch/get-updated.ts index 53c0bc10cc..b3bc9d3f2d 100644 --- a/lib/workers/branch/get-updated.ts +++ b/lib/workers/branch/get-updated.ts @@ -23,7 +23,7 @@ export async function getUpdatedPackageFiles( logger.debug( `manager.getUpdatedPackageFiles() reuseExistinbranch=${reuseExistingBranch}` ); - const updatedFileContents: Record = {}; + let updatedFileContents: Record = {}; const nonUpdatedFileContents: Record = {}; const packageFileManagers: Record = {}; const packageFileUpdatedDeps: Record = {}; @@ -91,7 +91,7 @@ export async function getUpdatedPackageFiles( reuseExistingBranch: false, }); } - Object.assign(updatedFileContents, files); + updatedFileContents = { ...updatedFileContents, ...files }; } } else { const bumpPackageVersion = get(manager, 'bumpPackageVersion'); diff --git a/lib/workers/branch/index.ts b/lib/workers/branch/index.ts index e4be96c286..34df7533ba 100644 --- a/lib/workers/branch/index.ts +++ b/lib/workers/branch/index.ts @@ -67,7 +67,7 @@ async function deleteBranchSilently(branchName: string): Promise { export async function processBranch( branchConfig: BranchConfig ): Promise { - const config: BranchConfig = { ...branchConfig }; + let config: BranchConfig = { ...branchConfig }; const dependencies = config.upgrades .map((upgrade) => upgrade.depName) .filter((v) => v) // remove nulls (happens for lock file maintenance) @@ -310,7 +310,7 @@ export async function processBranch( logger.debug('Manual rebase requested via Dependency Dashboard'); config.reuseExistingBranch = false; } else { - Object.assign(config, await shouldReuseExistingBranch(config)); + config = { ...config, ...(await shouldReuseExistingBranch(config)) }; } logger.debug(`Using reuseExistingBranch: ${config.reuseExistingBranch}`); const res = await getUpdatedPackageFiles(config); @@ -318,7 +318,7 @@ export async function processBranch( if (res.artifactErrors && config.artifactErrors) { res.artifactErrors = config.artifactErrors.concat(res.artifactErrors); } - Object.assign(config, res); + config = { ...config, ...res }; if (config.updatedPackageFiles?.length) { logger.debug( `Updated ${config.updatedPackageFiles.length} package files` diff --git a/lib/workers/repository/init/vulnerability.ts b/lib/workers/repository/init/vulnerability.ts index 6e63c73e13..30f97da2b0 100644 --- a/lib/workers/repository/init/vulnerability.ts +++ b/lib/workers/repository/init/vulnerability.ts @@ -176,7 +176,7 @@ export async function detectVulnerabilityAlerts( datasource === datasourcePypi.id ? `==${val.firstPatchedVersion}` : val.firstPatchedVersion; - const matchRule: PackageRule = { + let matchRule: PackageRule = { matchDatasources: [datasource], matchPackageNames: [depName], matchCurrentVersion, @@ -202,14 +202,15 @@ export async function detectVulnerabilityAlerts( matchRule.enabled = false; } else { // Remediate only direct dependencies - Object.assign(matchRule, { + matchRule = { + ...matchRule, allowedVersions, prBodyNotes, isVulnerabilityAlert: true, force: { ...config.vulnerabilityAlerts, }, - }); + }; } alertPackageRules.push(matchRule); } diff --git a/lib/workers/repository/process/fetch.ts b/lib/workers/repository/process/fetch.ts index e7fd4e6244..860b269546 100644 --- a/lib/workers/repository/process/fetch.ts +++ b/lib/workers/repository/process/fetch.ts @@ -19,7 +19,7 @@ async function fetchDepUpdates( packageFileConfig: ManagerConfig & PackageFile, indep: PackageDependency ): Promise { - const dep = clone(indep); + let dep = clone(indep); dep.updates = []; if (dep.skipReason) { return dep; @@ -39,7 +39,10 @@ async function fetchDepUpdates( dep.skipReason = SkipReason.Disabled; } else { if (depConfig.datasource) { - Object.assign(dep, await lookupUpdates(depConfig as LookupUpdateConfig)); + dep = { + ...dep, + ...(await lookupUpdates(depConfig as LookupUpdateConfig)), + }; } else { dep.updates = await getPackageUpdates(manager, depConfig); } diff --git a/lib/workers/repository/updates/generate.ts b/lib/workers/repository/updates/generate.ts index 894959f668..fb4ef3cd6b 100644 --- a/lib/workers/repository/updates/generate.ts +++ b/lib/workers/repository/updates/generate.ts @@ -326,10 +326,12 @@ export function generateBranchConfig( config.blockedByPin = config.upgrades.every( (upgrade) => upgrade.blockedByPin ); - config.constraints = Object.assign( - {}, - ...config.upgrades.map((upgrade) => upgrade.constraints) - ); + config.constraints = {}; + for (const upgrade of config.upgrades || []) { + if (upgrade.constraints) { + config.constraints = { ...config.constraints, ...upgrade.constraints }; + } + } const tableRows = config.upgrades .map((upgrade) => getTableValues(upgrade)) .filter(Boolean); diff --git a/lib/workers/types.ts b/lib/workers/types.ts index 8ba5e8bba0..27141cc31c 100644 --- a/lib/workers/types.ts +++ b/lib/workers/types.ts @@ -35,7 +35,7 @@ export interface BranchUpgradeConfig excludeCommitPaths?: string[]; githubName?: string; group?: GroupConfig; - + constraints?: Record; groupName?: string; groupSlug?: string; language?: string; @@ -110,7 +110,6 @@ export interface BranchConfig releaseTimestamp?: string; forceCommit?: boolean; rebaseRequested?: boolean; - res?: ProcessBranchResult; upgrades: BranchUpgradeConfig[]; packageFiles?: Record;