From 4f65b57225a42f9deb010f8dbfeb06eb94c0dd69 Mon Sep 17 00:00:00 2001 From: RahulGautamSingh Date: Wed, 29 Dec 2021 12:11:13 +0545 Subject: [PATCH] refactor: refactor static regex out of for loops (#13065) --- lib/config/decrypt.ts | 4 +-- lib/config/migration.ts | 35 ++++++++----------- lib/config/validation.ts | 6 ++-- lib/datasource/artifactory/index.ts | 2 +- lib/datasource/github-releases/digest.ts | 2 +- lib/datasource/maven/index.ts | 3 +- lib/datasource/pod/index.ts | 1 - lib/datasource/pypi/index.ts | 2 +- lib/datasource/sbt-package/index.ts | 8 ++--- lib/datasource/sbt-plugin/index.ts | 3 +- lib/manager/ansible-galaxy/extract.ts | 2 -- lib/manager/buildkite/extract.ts | 6 ++-- lib/manager/bundler/extract.ts | 29 ++++++++------- lib/manager/circleci/extract.ts | 8 ++--- lib/manager/cocoapods/extract.ts | 4 +-- lib/manager/composer/extract.ts | 4 +-- lib/manager/droneci/extract.ts | 2 +- lib/manager/git-submodules/extract.ts | 6 ++-- lib/manager/gitlabci-include/extract.ts | 2 +- lib/manager/gitlabci/extract.ts | 2 +- lib/manager/gomod/extract.ts | 6 ++-- .../gradle/deep/gradle-updates-report.ts | 3 +- lib/manager/kubernetes/extract.ts | 2 +- lib/manager/meteor/extract.ts | 2 +- lib/manager/npm/extract/index.ts | 4 ++- lib/manager/npm/post-update/index.ts | 8 ++--- lib/manager/npm/post-update/rules.ts | 2 +- lib/manager/nuget/util.ts | 2 +- lib/manager/pip_requirements/extract.ts | 6 ++-- lib/manager/sbt/extract.ts | 2 +- lib/manager/setup-cfg/extract.ts | 8 ++--- lib/manager/terraform/lockfile/hash.ts | 2 +- lib/manager/terraform/providers.ts | 4 +-- lib/platform/github/index.ts | 2 +- lib/util/git/index.ts | 6 ++-- lib/util/git/url.ts | 2 +- lib/util/markdown.ts | 18 +++++----- lib/util/package-rules.ts | 4 +-- lib/util/regex.ts | 2 +- lib/versioning/hashicorp/index.ts | 4 +-- lib/versioning/hex/index.ts | 8 ++--- lib/versioning/pep440/range.ts | 4 +-- lib/versioning/rez/transform.ts | 2 +- lib/versioning/ruby/index.ts | 13 ++++--- lib/workers/branch/schedule.ts | 6 +--- lib/workers/pr/body/index.ts | 3 +- lib/workers/pr/body/updates-table.ts | 4 +-- lib/workers/pr/changelog/release-notes.ts | 22 ++++++------ lib/workers/pr/code-owners.ts | 2 +- lib/workers/repository/init/vulnerability.ts | 2 +- .../repository/onboarding/pr/pr-list.ts | 2 +- lib/workers/repository/updates/flatten.ts | 8 ++--- lib/workers/repository/updates/generate.ts | 8 ++--- test/exec-util.ts | 2 +- tools/generate-imports.mjs | 2 +- 55 files changed, 149 insertions(+), 159 deletions(-) diff --git a/lib/config/decrypt.ts b/lib/config/decrypt.ts index 3d06a171f..c79e7ba92 100644 --- a/lib/config/decrypt.ts +++ b/lib/config/decrypt.ts @@ -174,7 +174,7 @@ export async function decryptConfig( } logger.debug(`Decrypted ${eKey}`); if (eKey === 'npmToken') { - const token = decryptedStr.replace(regEx(/\n$/), ''); // TODO #12071 + const token = decryptedStr.replace(regEx(/\n$/), ''); add(token); logger.debug( { decryptedToken: maskToken(token) }, @@ -191,7 +191,7 @@ export async function decryptConfig( } else { logger.debug('Appending _authToken= to end of existing npmrc'); decryptedConfig.npmrc = decryptedConfig.npmrc.replace( - regEx(/\n?$/), // TODO #12071 + regEx(/\n?$/), `\n_authToken=${token}\n` ); } diff --git a/lib/config/migration.ts b/lib/config/migration.ts index c2c4015e0..89fc7a49b 100644 --- a/lib/config/migration.ts +++ b/lib/config/migration.ts @@ -17,9 +17,11 @@ import type { import { mergeChildConfig } from './utils'; const options = getOptions(); +export function fixShortHours(input: string): string { + return input.replace(regEx(/( \d?\d)((a|p)m)/g), '$1:00$2'); +} let optionTypes: Record; - // Returns a migrated config export function migrateConfig( config: RenovateConfig, @@ -157,12 +159,12 @@ export function migrateConfig( } } else if (is.string(val) && val.includes('{{baseDir}}')) { migratedConfig[key] = val.replace( - regEx(/{{baseDir}}/g), // TODO #12071 + regEx(/{{baseDir}}/g), '{{packageFileDir}}' ); } else if (is.string(val) && val.includes('{{depNameShort}}')) { migratedConfig[key] = val.replace( - regEx(/{{depNameShort}}/g), // TODO #12071 + regEx(/{{depNameShort}}/g), '{{depName}}' ); } else if (key === 'gitFs') { @@ -340,6 +342,9 @@ export function migrateConfig( const schedules = is.string(val) ? [val] : [...(val as string[])]; // split 'and' const schedulesLength = schedules.length; + const afterBeforeRe = regEx( + /^(.*?)(after|before) (.*?) and (after|before) (.*?)( |$)(.*)/ + ); for (let i = 0; i < schedulesLength; i += 1) { if ( schedules[i].includes(' and ') && @@ -348,28 +353,16 @@ export function migrateConfig( ) { const parsedSchedule = later.parse.text( // We need to massage short hours first before we can parse it - schedules[i].replace(regEx(/( \d?\d)((a|p)m)/g), '$1:00$2') // TODO #12071 + fixShortHours(schedules[i]) ).schedules[0]; // Only migrate if the after time is greater than before, e.g. "after 10pm and before 5am" if (parsedSchedule?.t_a?.[0] > parsedSchedule?.t_b?.[0]) { const toSplit = schedules[i]; schedules[i] = toSplit - .replace( - regEx( - /^(.*?)(after|before) (.*?) and (after|before) (.*?)( |$)(.*)/ - ), // TODO #12071 - '$1$2 $3 $7' - ) + .replace(afterBeforeRe, '$1$2 $3 $7') .trim(); schedules.push( - toSplit - .replace( - regEx( - /^(.*?)(after|before) (.*?) and (after|before) (.*?)( |$)(.*)/ - ), // TODO #12071 - '$1$4 $5 $7' - ) - .trim() + toSplit.replace(afterBeforeRe, '$1$4 $5 $7').trim() ); } } @@ -393,10 +386,10 @@ export function migrateConfig( if ( regEx(/every (mon|tues|wednes|thurs|fri|satur|sun)day$/).test( schedules[i] - ) // TODO #12071 + ) ) { schedules[i] = schedules[i].replace( - regEx(/every ([a-z]*day)$/), // TODO #12071 + regEx(/every ([a-z]*day)$/), 'on $1' ); } @@ -514,7 +507,7 @@ export function migrateConfig( if (is.string(migratedConfig[key])) { for (const [from, to] of Object.entries(migratedTemplates)) { migratedConfig[key] = (migratedConfig[key] as string).replace( - regEx(from, 'g'), // TODO #12071 + regEx(from, 'g'), to ); } diff --git a/lib/config/validation.ts b/lib/config/validation.ts index a33a909d4..98d7750ce 100644 --- a/lib/config/validation.ts +++ b/lib/config/validation.ts @@ -37,7 +37,8 @@ const ignoredNodes = [ 'prBody', // deprecated 'minimumConfidence', // undocumented feature flag ]; - +const tzRe = regEx(/^:timezone\((.+)\)$/); +const rulesRe = regEx(/p.*Rules\[\d+\]$/); function isManagerPath(parentPath: string): boolean { return ( regEx(/^regexManagers\[[0-9]+]$/).test(parentPath) || @@ -253,7 +254,6 @@ export async function validateConfig( } } if (key === 'extends') { - const tzRe = regEx(/^:timezone\((.+)\)$/); // TODO #12071 for (const subval of val) { if (is.string(subval)) { if ( @@ -488,7 +488,7 @@ export async function validateConfig( } if ( (selectors.includes(key) || key === 'matchCurrentVersion') && - !regEx(/p.*Rules\[\d+\]$/).test(parentPath) && // Inside a packageRule // TODO #12071 + !rulesRe.test(parentPath) && // Inside a packageRule (parentPath || !isPreset) // top level in a preset ) { errors.push({ diff --git a/lib/datasource/artifactory/index.ts b/lib/datasource/artifactory/index.ts index 95744dcb2..1b1047aa0 100644 --- a/lib/datasource/artifactory/index.ts +++ b/lib/datasource/artifactory/index.ts @@ -109,6 +109,6 @@ export class ArtifactoryDatasource extends Datasource { } private static parseReleaseTimestamp(rawText: string): string { - return rawText.trim().replace(regEx(/ ?-$/), '') + 'Z'; // TODO #12071 + return rawText.trim().replace(regEx(/ ?-$/), '') + 'Z'; } } diff --git a/lib/datasource/github-releases/digest.ts b/lib/datasource/github-releases/digest.ts index 21b669998..3401f8507 100644 --- a/lib/datasource/github-releases/digest.ts +++ b/lib/datasource/github-releases/digest.ts @@ -14,7 +14,7 @@ async function findDigestFile( for (const asset of smallAssets) { const res = await http.get(asset.browser_download_url); for (const line of res.body.split('\n')) { - const [lineDigest, lineFn] = line.split(regEx(/\s+/), 2); // TODO #12071 + const [lineDigest, lineFn] = line.split(regEx(/\s+/), 2); if (lineDigest === digest) { return { assetName: asset.name, diff --git a/lib/datasource/maven/index.ts b/lib/datasource/maven/index.ts index 468ee1b15..7ad19360f 100644 --- a/lib/datasource/maven/index.ts +++ b/lib/datasource/maven/index.ts @@ -5,6 +5,7 @@ import { XmlDocument } from 'xmldoc'; import { logger } from '../../logger'; import * as packageCache from '../../util/cache/package'; import { regEx } from '../../util/regex'; +import { ensureTrailingSlash } from '../../util/url'; import mavenVersion from '../../versioning/maven'; import * as mavenVersioning from '../../versioning/maven'; import { compare } from '../../versioning/maven/compare'; @@ -306,7 +307,7 @@ export async function getReleases({ registryUrl, }: GetReleasesConfig): Promise { const dependency = getDependencyParts(lookupName); - const repoUrl = registryUrl.replace(/\/?$/, '/'); // TODO #12071 + const repoUrl = ensureTrailingSlash(registryUrl); logger.debug(`Looking up ${dependency.display} in repository ${repoUrl}`); diff --git a/lib/datasource/pod/index.ts b/lib/datasource/pod/index.ts index 32a3d5ef4..55ea2b369 100644 --- a/lib/datasource/pod/index.ts +++ b/lib/datasource/pod/index.ts @@ -183,7 +183,6 @@ async function getReleasesFromCDN( const line = lines[idx]; const [name, ...versions] = line.split('/'); if (name === lookupName.replace(regEx(/\/.*$/), '')) { - // TODO #12071 const releases = versions.map((version) => ({ version })); return { releases }; } diff --git a/lib/datasource/pypi/index.ts b/lib/datasource/pypi/index.ts index e27056866..c587e460c 100644 --- a/lib/datasource/pypi/index.ts +++ b/lib/datasource/pypi/index.ts @@ -176,7 +176,7 @@ export class PypiDatasource extends Datasource { const srcPrefix = `${packageName}-`; const srcSuffix = '.tar.gz'; if (srcText.startsWith(srcPrefix) && srcText.endsWith(srcSuffix)) { - return srcText.replace(srcPrefix, '').replace(regEx(/\.tar\.gz$/), ''); // TODO #12071 + return srcText.replace(srcPrefix, '').replace(regEx(/\.tar\.gz$/), ''); } // pep-0427 wheel packages diff --git a/lib/datasource/sbt-package/index.ts b/lib/datasource/sbt-package/index.ts index bd34c2d1d..5c889fa48 100644 --- a/lib/datasource/sbt-package/index.ts +++ b/lib/datasource/sbt-package/index.ts @@ -123,10 +123,10 @@ export async function getUrls( const sourceUrl = pomXml.valueWithPath('scm.url'); if (sourceUrl) { result.sourceUrl = sourceUrl - .replace(regEx(/^scm:/), '') // TODO #12071 - .replace(regEx(/^git:/), '') // TODO #12071 - .replace(regEx(/^git@github.com:/), 'https://github.com/') // TODO #12071 - .replace(regEx(/\.git$/), ''); // TODO #12071 + .replace(regEx(/^scm:/), '') + .replace(regEx(/^git:/), '') + .replace(regEx(/^git@github.com:/), 'https://github.com/') + .replace(regEx(/\.git$/), ''); } return result; diff --git a/lib/datasource/sbt-plugin/index.ts b/lib/datasource/sbt-plugin/index.ts index c069dd07d..807e33c87 100644 --- a/lib/datasource/sbt-plugin/index.ts +++ b/lib/datasource/sbt-plugin/index.ts @@ -1,5 +1,6 @@ import { logger } from '../../logger'; import { regEx } from '../../util/regex'; +import { ensureTrailingSlash } from '../../util/url'; import * as ivyVersioning from '../../versioning/ivy'; import { compare } from '../../versioning/maven/compare'; import { downloadHttpProtocol } from '../maven/util'; @@ -18,8 +19,6 @@ export const defaultRegistryUrls = [SBT_PLUGINS_REPO]; export const defaultVersioning = ivyVersioning.id; export const registryStrategy = 'hunt'; -const ensureTrailingSlash = (str: string): string => str.replace(/\/?$/, '/'); // TODO #12071 - async function resolvePluginReleases( rootUrl: string, artifact: string, diff --git a/lib/manager/ansible-galaxy/extract.ts b/lib/manager/ansible-galaxy/extract.ts index bd010432a..b1ac37cc4 100644 --- a/lib/manager/ansible-galaxy/extract.ts +++ b/lib/manager/ansible-galaxy/extract.ts @@ -46,11 +46,9 @@ export default function extractPackageFile( // find role and collection block lines.forEach((line, index) => { if (regEx(/^collections:/).exec(line)) { - // TODO #12071 positions.collections = index; } if (regEx(/^roles:/).exec(line)) { - // TODO #12071 positions.roles = index; } }); diff --git a/lib/manager/buildkite/extract.ts b/lib/manager/buildkite/extract.ts index 6e008b5db..ee60c0828 100644 --- a/lib/manager/buildkite/extract.ts +++ b/lib/manager/buildkite/extract.ts @@ -16,7 +16,7 @@ export function extractPackageFile(content: string): PackageFile | null { const line = lines[lineIdx]; const pluginsSection = regEx( /^(?\s*)(-?\s*)plugins:/ - ).exec(line); // TODO #12071 + ).exec(line); if (pluginsSection) { logger.trace(`Matched plugins on line ${lineNumber}`); isPluginsSection = true; @@ -25,10 +25,10 @@ export function extractPackageFile(content: string): PackageFile | null { logger.debug(`serviceImageLine: "${line}"`); const { currentIndent } = regEx(/^(?\s*)/).exec( line - ).groups; // TODO #12071 + ).groups; const depLineMatch = regEx( /^\s+(?:-\s+)?(?[^#]+)#(?[^:]+)/ - ).exec(line); // TODO #12071 + ).exec(line); if (currentIndent.length <= pluginsIndent.length) { isPluginsSection = false; pluginsIndent = ''; diff --git a/lib/manager/bundler/extract.ts b/lib/manager/bundler/extract.ts index 2d8ccd655..22a676d6b 100644 --- a/lib/manager/bundler/extract.ts +++ b/lib/manager/bundler/extract.ts @@ -5,6 +5,10 @@ import { regEx } from '../../util/regex'; import type { PackageDependency, PackageFile } from '../types'; import { extractLockFileEntries } from './locked-version'; +function formatContent(input: string): string { + return input.replace(regEx(/^ {2}/), '') + '\n'; //remove leading witespace and add a new line at the end +} + export async function extractPackageFile( content: string, fileName?: string @@ -22,7 +26,6 @@ export async function extractPackageFile( sourceMatch = sourceMatch || regEx(`^source ${delimiter}([^${delimiter}]+)${delimiter}\\s*$`).exec( - // TODO #12071 line ); } @@ -33,14 +36,14 @@ export async function extractPackageFile( for (const delimiter of delimiters) { rubyMatch = rubyMatch || - regEx(`^ruby ${delimiter}([^${delimiter}]+)${delimiter}`).exec(line); // TODO #12071 + regEx(`^ruby ${delimiter}([^${delimiter}]+)${delimiter}`).exec(line); } if (rubyMatch) { res.constraints = { ruby: rubyMatch[1] }; } const gemMatchRegex = regEx( `^\\s*gem\\s+(['"])(?[^'"]+)(['"])(\\s*,\\s*(?(['"])[^'"]+['"](\\s*,\\s*['"][^'"]+['"])?))?` - ); // TODO #12071 + ); const gemMatch = gemMatchRegex.exec(line); if (gemMatch) { const dep: PackageDependency = { @@ -49,19 +52,19 @@ export async function extractPackageFile( }; if (gemMatch.groups.currentValue) { const currentValue = gemMatch.groups.currentValue; - dep.currentValue = regEx(/\s*,\s*/).test(currentValue) // TODO #12071 + dep.currentValue = regEx(/\s*,\s*/).test(currentValue) ? currentValue : currentValue.slice(1, -1); } dep.datasource = RubyGemsDatasource.id; res.deps.push(dep); } - const groupMatch = regEx(/^group\s+(.*?)\s+do/).exec(line); // TODO #12071 + const groupMatch = regEx(/^group\s+(.*?)\s+do/).exec(line); if (groupMatch) { const depTypes = groupMatch[1] .split(',') .map((group) => group.trim()) - .map((group) => group.replace(regEx(/^:/), '')); // TODO #12071 + .map((group) => group.replace(regEx(/^:/), '')); const groupLineNumber = lineNumber; let groupContent = ''; let groupLine = ''; @@ -69,7 +72,7 @@ export async function extractPackageFile( lineNumber += 1; groupLine = lines[lineNumber]; if (groupLine !== 'end') { - groupContent += (groupLine || '').replace(regEx(/^ {2}/), '') + '\n'; // TODO #12071 + groupContent += formatContent(groupLine || ''); } } const groupRes = await extractPackageFile(groupContent); @@ -88,7 +91,7 @@ export async function extractPackageFile( } for (const delimiter of delimiters) { const sourceBlockMatch = regEx( - `^source\\s+${delimiter}(.*?)${delimiter}\\s+do` // TODO #12071 + `^source\\s+${delimiter}(.*?)${delimiter}\\s+do` ).exec(line); if (sourceBlockMatch) { const repositoryUrl = sourceBlockMatch[1]; @@ -104,7 +107,7 @@ export async function extractPackageFile( sourceLine = 'end'; } if (sourceLine !== 'end') { - sourceContent += sourceLine.replace(regEx(/^ {2}/), '') + '\n'; // TODO #12071 + sourceContent += formatContent(sourceLine); } } const sourceRes = await extractPackageFile(sourceContent); @@ -122,7 +125,7 @@ export async function extractPackageFile( } } } - const platformsMatch = regEx(/^platforms\s+(.*?)\s+do/).test(line); // TODO #12071 + const platformsMatch = regEx(/^platforms\s+(.*?)\s+do/).test(line); if (platformsMatch) { const platformsLineNumber = lineNumber; let platformsContent = ''; @@ -131,7 +134,7 @@ export async function extractPackageFile( lineNumber += 1; platformsLine = lines[lineNumber]; if (platformsLine !== 'end') { - platformsContent += platformsLine.replace(regEx(/^ {2}/), '') + '\n'; // TODO #12071 + platformsContent += formatContent(platformsLine); } } const platformsRes = await extractPackageFile(platformsContent); @@ -147,7 +150,7 @@ export async function extractPackageFile( ); } } - const ifMatch = regEx(/^if\s+(.*?)/).test(line); // TODO #12071 + const ifMatch = regEx(/^if\s+(.*?)/).test(line); if (ifMatch) { const ifLineNumber = lineNumber; let ifContent = ''; @@ -156,7 +159,7 @@ export async function extractPackageFile( lineNumber += 1; ifLine = lines[lineNumber]; if (ifLine !== 'end') { - ifContent += ifLine.replace(regEx(/^ {2}/), '') + '\n'; // TODO #12071 + ifContent += formatContent(ifLine); } } const ifRes = await extractPackageFile(ifContent); diff --git a/lib/manager/circleci/extract.ts b/lib/manager/circleci/extract.ts index 800c1eafd..8f44a9850 100644 --- a/lib/manager/circleci/extract.ts +++ b/lib/manager/circleci/extract.ts @@ -11,7 +11,7 @@ export function extractPackageFile(content: string): PackageFile | null { const lines = content.split('\n'); for (let lineNumber = 0; lineNumber < lines.length; lineNumber += 1) { const line = lines[lineNumber]; - const orbs = regEx(/^\s*orbs:\s*$/).exec(line); // TODO #12071 + const orbs = regEx(/^\s*orbs:\s*$/).exec(line); if (orbs) { logger.trace(`Matched orbs on line ${lineNumber}`); let foundOrbOrNoop: boolean; @@ -19,14 +19,14 @@ export function extractPackageFile(content: string): PackageFile | null { foundOrbOrNoop = false; const orbLine = lines[lineNumber + 1]; logger.trace(`orbLine: "${orbLine}"`); - const yamlNoop = regEx(/^\s*(#|$)/).exec(orbLine); // TODO #12071 + const yamlNoop = regEx(/^\s*(#|$)/).exec(orbLine); if (yamlNoop) { logger.debug('orbNoop'); foundOrbOrNoop = true; lineNumber += 1; continue; } - const orbMatch = regEx(/^\s+([^:]+):\s(.+)$/).exec(orbLine); // TODO #12071 + const orbMatch = regEx(/^\s+([^:]+):\s(.+)$/).exec(orbLine); if (orbMatch) { logger.trace('orbMatch'); foundOrbOrNoop = true; @@ -47,7 +47,7 @@ export function extractPackageFile(content: string): PackageFile | null { } } while (foundOrbOrNoop); } - const match = regEx(/^\s*-? image:\s*'?"?([^\s'"]+)'?"?\s*$/).exec(line); // TODO #12071 + const match = regEx(/^\s*-? image:\s*'?"?([^\s'"]+)'?"?\s*$/).exec(line); if (match) { const currentFrom = match[1]; const dep = getDep(currentFrom); diff --git a/lib/manager/cocoapods/extract.ts b/lib/manager/cocoapods/extract.ts index 84306227b..7bea8620e 100644 --- a/lib/manager/cocoapods/extract.ts +++ b/lib/manager/cocoapods/extract.ts @@ -26,7 +26,7 @@ export function parseLine(line: string): ParsedLine { return result; } for (const regex of Object.values(regexMappings)) { - const match = regex.exec(line.replace(regEx(/#.*$/), '')); // TODO #12071 + const match = regex.exec(line.replace(regEx(/#.*$/), '')); if (match?.groups) { result = { ...result, ...match.groups }; } @@ -105,7 +105,7 @@ export async function extractPackageFile( }: ParsedLine = parsedLine; if (source) { - registryUrls.push(source.replace(regEx(/\/*$/), '')); // TODO #12071 + registryUrls.push(source.replace(regEx(/\/*$/), '')); } if (depName) { diff --git a/lib/manager/composer/extract.ts b/lib/manager/composer/extract.ts index 8eb3c6a4e..e1982f887 100644 --- a/lib/manager/composer/extract.ts +++ b/lib/manager/composer/extract.ts @@ -22,7 +22,7 @@ import type { * See https://github.com/composer/composer/blob/750a92b4b7aecda0e5b2f9b963f1cb1421900675/src/Composer/Repository/ComposerRepository.php#L815 */ function transformRegUrl(url: string): string { - return url.replace(regEx(/(\/packages\.json)$/), ''); // TODO #12071 + return url.replace(regEx(/(\/packages\.json)$/), ''); } /** @@ -159,7 +159,7 @@ export async function extractPackageFile( (item) => item.name === dep.depName ); if (lockedDep && semverComposer.isVersion(lockedDep.version)) { - dep.lockedVersion = lockedDep.version.replace(regEx(/^v/i), ''); // TODO #12071 + dep.lockedVersion = lockedDep.version.replace(regEx(/^v/i), ''); } } deps.push(dep); diff --git a/lib/manager/droneci/extract.ts b/lib/manager/droneci/extract.ts index b02dffd55..6dc15f47d 100644 --- a/lib/manager/droneci/extract.ts +++ b/lib/manager/droneci/extract.ts @@ -9,7 +9,7 @@ export function extractPackageFile(content: string): PackageFile | null { const lines = content.split('\n'); for (let lineNumber = 0; lineNumber < lines.length; lineNumber += 1) { const line = lines[lineNumber]; - const match = regEx(/^\s* image:\s*'?"?([^\s'"]+)'?"?\s*$/).exec(line); // TODO #12071 + const match = regEx(/^\s* image:\s*'?"?([^\s'"]+)'?"?\s*$/).exec(line); if (match) { const currentFrom = match[1]; const dep = getDep(currentFrom); diff --git a/lib/manager/git-submodules/extract.ts b/lib/manager/git-submodules/extract.ts index f67c0b46a..201682508 100644 --- a/lib/manager/git-submodules/extract.ts +++ b/lib/manager/git-submodules/extract.ts @@ -76,7 +76,7 @@ async function getModules( .filter((s) => !!s); for (const line of modules) { - const [, name, path] = line.split(regEx(/submodule\.(.+?)\.path\s(.+)/)); // TODO #12071 + const [, name, path] = line.split(regEx(/submodule\.(.+?)\.path\s(.+)/)); res.push({ name, path }); } } catch (err) /* istanbul ignore next */ { @@ -105,8 +105,8 @@ export default async function extractPackageFile( try { const [currentDigest] = (await git.subModule(['status', path])) .trim() - .replace(regEx(/^[-+]/), '') // TODO #12071 - .split(regEx(/\s/)); // TODO #12071 + .replace(regEx(/^[-+]/), '') + .split(regEx(/\s/)); const subModuleUrl = await getUrl(git, gitModulesPath, name); // hostRules only understands HTTP URLs // Find HTTP URL, then apply token diff --git a/lib/manager/gitlabci-include/extract.ts b/lib/manager/gitlabci-include/extract.ts index cd5c5a739..7e0c8306a 100644 --- a/lib/manager/gitlabci-include/extract.ts +++ b/lib/manager/gitlabci-include/extract.ts @@ -48,7 +48,7 @@ export function extractPackageFile( if (config.endpoint) { dep.registryUrls = [ config.endpoint.replace(regEx(/\/api\/v4\/?/), ''), - ]; // TODO #12071 + ]; } deps.push(dep); } diff --git a/lib/manager/gitlabci/extract.ts b/lib/manager/gitlabci/extract.ts index 14a478b45..7fe6b8561 100644 --- a/lib/manager/gitlabci/extract.ts +++ b/lib/manager/gitlabci/extract.ts @@ -65,7 +65,7 @@ export function extractPackageFile(content: string): PackageFile | null { } } } - const services = regEx(/^\s*services:\s*$/).test(line); // TODO #12071 + const services = regEx(/^\s*services:\s*$/).test(line); if (services) { logger.trace(`Matched services on line ${lineNumber}`); let foundImage: boolean; diff --git a/lib/manager/gomod/extract.ts b/lib/manager/gomod/extract.ts index 8627020e8..d266cf2d7 100644 --- a/lib/manager/gomod/extract.ts +++ b/lib/manager/gomod/extract.ts @@ -51,12 +51,12 @@ export function extractPackageFile(content: string): PackageFile | null { } const replaceMatch = regEx( /^replace\s+[^\s]+[\s]+[=][>]\s+([^\s]+)\s+([^\s]+)/ - ).exec(line); // TODO #12071 + ).exec(line); if (replaceMatch) { const dep = getDep(lineNumber, replaceMatch, 'replace'); deps.push(dep); } - const requireMatch = regEx(/^require\s+([^\s]+)\s+([^\s]+)/).exec(line); // TODO #12071 + const requireMatch = regEx(/^require\s+([^\s]+)\s+([^\s]+)/).exec(line); if (requireMatch && !line.endsWith('// indirect')) { logger.trace({ lineNumber }, `require line: "${line}"`); const dep = getDep(lineNumber, requireMatch, 'require'); @@ -67,7 +67,7 @@ export function extractPackageFile(content: string): PackageFile | null { do { lineNumber += 1; line = lines[lineNumber]; - const multiMatch = regEx(/^\s+([^\s]+)\s+([^\s]+)/).exec(line); // TODO #12071 + const multiMatch = regEx(/^\s+([^\s]+)\s+([^\s]+)/).exec(line); logger.trace(`reqLine: "${line}"`); if (multiMatch && !line.endsWith('// indirect')) { logger.trace({ lineNumber }, `require line: "${line}"`); diff --git a/lib/manager/gradle/deep/gradle-updates-report.ts b/lib/manager/gradle/deep/gradle-updates-report.ts index d3a64069e..c8567eee4 100644 --- a/lib/manager/gradle/deep/gradle-updates-report.ts +++ b/lib/manager/gradle/deep/gradle-updates-report.ts @@ -145,12 +145,11 @@ export async function extractDependenciesFromUpdatesReport( if (depName.endsWith('_%%')) { return { ...dep, - depName: depName.replace(regEx(/_%%/), ''), // TODO #12071 + depName: depName.replace(regEx(/_%%/), ''), datasource: datasourceSbtPackage.id, }; } if (regEx(/^%.*%$/).test(currentValue)) { - // TODO #12071 return { ...dep, skipReason: 'version-placeholder' }; } return dep; diff --git a/lib/manager/kubernetes/extract.ts b/lib/manager/kubernetes/extract.ts index 1eb9b20c2..f537f5dad 100644 --- a/lib/manager/kubernetes/extract.ts +++ b/lib/manager/kubernetes/extract.ts @@ -15,7 +15,7 @@ export function extractPackageFile(content: string): PackageFile | null { } for (const line of content.split('\n')) { - const match = regEx(/^\s*-?\s*image:\s*'?"?([^\s'"]+)'?"?\s*$/).exec(line); // TODO #12071 + const match = regEx(/^\s*-?\s*image:\s*'?"?([^\s'"]+)'?"?\s*$/).exec(line); if (match) { const currentFrom = match[1]; const dep = getDep(currentFrom); diff --git a/lib/manager/meteor/extract.ts b/lib/manager/meteor/extract.ts index 943842d90..d5dde1701 100644 --- a/lib/manager/meteor/extract.ts +++ b/lib/manager/meteor/extract.ts @@ -15,7 +15,7 @@ export function extractPackageFile(content: string): PackageFile | null { .split(',') .map((dep) => dep.trim()) .filter((dep) => dep.length) - .map((dep) => dep.split(regEx(/:(.*)/))) // TODO #12071 + .map((dep) => dep.split(regEx(/:(.*)/))) .map((arr) => { const [depName, currentValue] = arr; // istanbul ignore if diff --git a/lib/manager/npm/extract/index.ts b/lib/manager/npm/extract/index.ts index 6504c3e49..6a7d85acb 100644 --- a/lib/manager/npm/extract/index.ts +++ b/lib/manager/npm/extract/index.ts @@ -108,7 +108,9 @@ export async function extractPackageFile( } else { npmrc = config.npmrc || ''; if (npmrc.length) { - npmrc = npmrc.replace(/\n?$/, '\n'); // TODO #12875 add \n to front when used with re2 + if (!npmrc.endsWith('\n')) { + npmrc += '\n'; + } } if (repoNpmrc?.includes('package-lock')) { logger.debug('Stripping package-lock setting from .npmrc'); diff --git a/lib/manager/npm/post-update/index.ts b/lib/manager/npm/post-update/index.ts index 0af01617d..260b0c192 100644 --- a/lib/manager/npm/post-update/index.ts +++ b/lib/manager/npm/post-update/index.ts @@ -25,6 +25,7 @@ import { import { branchExists, getFile, getRepoStatus } from '../../../util/git'; import * as hostRules from '../../../util/host-rules'; import { regEx } from '../../../util/regex'; +import { ensureTrailingSlash } from '../../../util/url'; import type { PackageFile, PostUpdateConfig, Upgrade } from '../../types'; import { getZeroInstallPaths } from '../extract/yarn'; import * as lerna from './lerna'; @@ -376,10 +377,9 @@ async function updateYarnOffline( .split('\n') .find((line) => line.startsWith('yarn-offline-mirror ')); if (mirrorLine) { - const mirrorPath = mirrorLine - .split(' ')[1] - .replace(regEx(/"/g), '') - .replace(regEx(/\/?$/), '/'); + const mirrorPath = ensureTrailingSlash( + mirrorLine.split(' ')[1].replace(regEx(/"/g), '') + ); resolvedPaths.push(upath.join(lockFileDir, mirrorPath)); } } diff --git a/lib/manager/npm/post-update/rules.ts b/lib/manager/npm/post-update/rules.ts index 0b7cc70bd..c3b8daddd 100644 --- a/lib/manager/npm/post-update/rules.ts +++ b/lib/manager/npm/post-update/rules.ts @@ -19,7 +19,7 @@ export function processHostRules(): HostRulesResult { for (const hostRule of npmHostRules) { if (hostRule.resolvedHost) { let uri = hostRule.matchHost; - uri = validateUrl(uri) ? uri.replace(regEx(/^https?:/), '') : `//${uri}/`; // TODO #12071 + 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/nuget/util.ts b/lib/manager/nuget/util.ts index 51fbb26d8..1f7365b8e 100644 --- a/lib/manager/nuget/util.ts +++ b/lib/manager/nuget/util.ts @@ -69,7 +69,7 @@ export async function getConfiguredRegistries( logger.debug(`clearing registry URLs`); registries.length = 0; } else if (child.name === 'add') { - const isHttpUrl = regEx(/^https?:\/\//i).test(child.attr.value); // TODO #12071 + const isHttpUrl = regEx(/^https?:\/\//i).test(child.attr.value); if (isHttpUrl) { let registryUrl = child.attr.value; if (child.attr.protocolVersion) { diff --git a/lib/manager/pip_requirements/extract.ts b/lib/manager/pip_requirements/extract.ts index ca34d85b9..5ca09fe42 100644 --- a/lib/manager/pip_requirements/extract.ts +++ b/lib/manager/pip_requirements/extract.ts @@ -90,18 +90,18 @@ export function extractPackageFile( if (registryUrls.length > 0) { res.registryUrls = registryUrls.map((url) => { // handle the optional quotes in eg. `--extra-index-url "https://foo.bar"` - const cleaned = url.replace(regEx(/^"/), '').replace(regEx(/"$/), ''); // TODO #12071 + const cleaned = url.replace(regEx(/^"/), '').replace(regEx(/"$/), ''); if (!GlobalConfig.get('exposeAllEnv')) { return cleaned; } // interpolate any environment variables return cleaned.replace( - regEx(/(\$[A-Za-z\d_]+)|(\${[A-Za-z\d_]+})/g), // TODO #12071 + regEx(/(\$[A-Za-z\d_]+)|(\${[A-Za-z\d_]+})/g), (match) => { const envvar = match .substring(1) .replace(regEx(/^{/), '') - .replace(regEx(/}$/), ''); // TODO #12071 + .replace(regEx(/}$/), ''); const sub = process.env[envvar]; return sub || match; } diff --git a/lib/manager/sbt/extract.ts b/lib/manager/sbt/extract.ts index 65dd05a6e..7c5e17672 100644 --- a/lib/manager/sbt/extract.ts +++ b/lib/manager/sbt/extract.ts @@ -142,7 +142,7 @@ function parseDepExpr( const tokens = expr .trim() .split(regEx(/("[^"]*")/g)) - .map((x) => (regEx(/"[^"]*"/).test(x) ? x : x.replace(regEx(/[()]+/g), ''))) // TODO #12071 + .map((x) => (regEx(/"[^"]*"/).test(x) ? x : x.replace(regEx(/[()]+/g), ''))) .join('') .split(regEx(/\s*(%%?)\s*|\s*classifier\s*/)); diff --git a/lib/manager/setup-cfg/extract.ts b/lib/manager/setup-cfg/extract.ts index 7ab666964..d4eec8278 100644 --- a/lib/manager/setup-cfg/extract.ts +++ b/lib/manager/setup-cfg/extract.ts @@ -4,12 +4,12 @@ import pep440 from '../../versioning/pep440'; import type { PackageDependency, PackageFile, Result } from '../types'; function getSectionName(str: string): string { - const [, sectionName] = regEx(/^\[\s*([^\s]+)\s*]\s*$/).exec(str) || []; // TODO #12071 + const [, sectionName] = regEx(/^\[\s*([^\s]+)\s*]\s*$/).exec(str) || []; return sectionName; } function getSectionRecord(str: string): string { - const [, sectionRecord] = regEx(/^([^\s]+)\s+=/).exec(str) || []; // TODO #12071 + const [, sectionRecord] = regEx(/^([^\s]+)\s+=/).exec(str) || []; return sectionRecord; } @@ -65,7 +65,7 @@ export function extractPackageFile( const deps: PackageDependency[] = []; content .split('\n') - .map((line) => line.replace(regEx(/[;#].*$/), '').trimRight()) // TODO #12071 + .map((line) => line.replace(regEx(/[;#].*$/), '').trimRight()) .forEach((rawLine) => { let line = rawLine; const newSectionName = getSectionName(line); @@ -75,7 +75,7 @@ export function extractPackageFile( } else { if (newSectionRecord) { sectionRecord = newSectionRecord; - line = rawLine.replace(regEx(/^[^=]*=\s*/), '\t'); // TODO #12071 + line = rawLine.replace(regEx(/^[^=]*=\s*/), '\t'); } const dep = parseDep(line, sectionName, sectionRecord); if (dep) { diff --git a/lib/manager/terraform/lockfile/hash.ts b/lib/manager/terraform/lockfile/hash.ts index 1918148a9..f6b0b33d5 100644 --- a/lib/manager/terraform/lockfile/hash.ts +++ b/lib/manager/terraform/lockfile/hash.ts @@ -32,7 +32,7 @@ export class TerraformProviderHash { // add double space, the filename and a new line char rootHash.update(' '); - const fileName = file.replace(regEx(/^.*[\\/]/), ''); // TODO #12071 + const fileName = file.replace(regEx(/^.*[\\/]/), ''); rootHash.update(fileName); rootHash.update('\n'); } diff --git a/lib/manager/terraform/providers.ts b/lib/manager/terraform/providers.ts index e742b8837..50ee59488 100644 --- a/lib/manager/terraform/providers.ts +++ b/lib/manager/terraform/providers.ts @@ -42,8 +42,8 @@ export function extractTerraformProvider( // istanbul ignore else if (is.string(line)) { // `{` will be counted wit +1 and `}` with -1. Therefore if we reach braceCounter == 0. We have found the end of the terraform block - const openBrackets = (line.match(regEx(/\{/g)) || []).length; // TODO #12071 - const closedBrackets = (line.match(regEx(/\}/g)) || []).length; // TODO #12071 + const openBrackets = (line.match(regEx(/\{/g)) || []).length; + const closedBrackets = (line.match(regEx(/\}/g)) || []).length; braceCounter = braceCounter + openBrackets - closedBrackets; // only update fields inside the root block diff --git a/lib/platform/github/index.ts b/lib/platform/github/index.ts index c038c9d55..9168f725e 100644 --- a/lib/platform/github/index.ts +++ b/lib/platform/github/index.ts @@ -1244,7 +1244,7 @@ export async function addReviewers( const userReviewers = reviewers.filter((e) => !e.startsWith('team:')); const teamReviewers = reviewers .filter((e) => e.startsWith('team:')) - .map((e) => e.replace(regEx(/^team:/), '')); // TODO #12071 + .map((e) => e.replace(regEx(/^team:/), '')); try { await githubApi.postJson( `repos/${ diff --git a/lib/util/git/index.ts b/lib/util/git/index.ts index 010beaadb..b6dd617c6 100644 --- a/lib/util/git/index.ts +++ b/lib/util/git/index.ts @@ -108,7 +108,7 @@ function checkForPlatformFailure(err: Error): void { } function localName(branchName: string): string { - return branchName.replace(regEx(/^origin\//), ''); // TODO #12071 + return branchName.replace(regEx(/^origin\//), ''); } async function isDirectory(dir: string): Promise { @@ -196,7 +196,7 @@ async function fetchBranchCommits(): Promise { (await git.raw(opts)) .split('\n') .filter(Boolean) - .map((line) => line.trim().split(regEx(/\s+/))) // TODO #12071 + .map((line) => line.trim().split(regEx(/\s+/))) .forEach(([sha, ref]) => { config.branchCommits[ref.replace('refs/heads/', '')] = sha; }); @@ -488,7 +488,7 @@ export async function getFileList(): Promise { .split('\n') .filter(Boolean) .filter((line) => line.startsWith('100')) - .map((line) => line.split(regEx(/\t/)).pop()) // TODO #12071 + .map((line) => line.split(regEx(/\t/)).pop()) .filter((file: string) => submodules.every((submodule: string) => !file.startsWith(submodule)) ); diff --git a/lib/util/git/url.ts b/lib/util/git/url.ts index e7a6ef0d3..9dff260a5 100644 --- a/lib/util/git/url.ts +++ b/lib/util/git/url.ts @@ -8,7 +8,7 @@ export function getHttpUrl(url: string, token?: string): string { parsedUrl.token = token; - const protocol = regEx(/^https?$/).exec(parsedUrl.protocol) // TODO #12071 + const protocol = regEx(/^https?$/).exec(parsedUrl.protocol) ? parsedUrl.protocol : 'https'; return parsedUrl.toString(protocol); diff --git a/lib/util/markdown.ts b/lib/util/markdown.ts index 962f0cf11..8f869c1af 100644 --- a/lib/util/markdown.ts +++ b/lib/util/markdown.ts @@ -6,18 +6,18 @@ import { regEx } from './regex'; export function sanitizeMarkdown(markdown: string): string { let res = markdown; // Put a zero width space after every # followed by a digit - res = res.replace(regEx(/#(\d)/gi), '#​$1'); // TODO #12071 + res = res.replace(regEx(/#(\d)/gi), '#​$1'); // Put a zero width space after every @ symbol to prevent unintended hyperlinking - res = res.replace(regEx(/@/g), '@​'); // TODO #12071 - res = res.replace(regEx(/(`\[?@)​/g), '$1'); // TODO #12071 - res = res.replace(regEx(/([a-z]@)​/gi), '$1'); // TODO #12071 - res = res.replace(regEx(/\/compare\/@​/g), '/compare/@'); // TODO #12071 - res = res.replace(regEx(/(\(https:\/\/[^)]*?)\.\.\.@​/g), '$1...@'); // TODO #12071 - res = res.replace(regEx(/([\s(])#(\d+)([)\s]?)/g), '$1#​$2$3'); // TODO #12071 + res = res.replace(regEx(/@/g), '@​'); + res = res.replace(regEx(/(`\[?@)​/g), '$1'); + res = res.replace(regEx(/([a-z]@)​/gi), '$1'); + res = res.replace(regEx(/\/compare\/@​/g), '/compare/@'); + res = res.replace(regEx(/(\(https:\/\/[^)]*?)\.\.\.@​/g), '$1...@'); + res = res.replace(regEx(/([\s(])#(\d+)([)\s]?)/g), '$1#​$2$3'); // convert escaped backticks back to ` - const backTickRe = regEx(/`([^/]*?)`/g); // TODO #12071 + const backTickRe = regEx(/`([^/]*?)`/g); res = res.replace(backTickRe, '`$1`'); - res = res.replace(regEx(/`#​(\d+)`/g), '`#$1`'); // TODO #12071 + res = res.replace(regEx(/`#​(\d+)`/g), '`#$1`'); return res; } diff --git a/lib/util/package-rules.ts b/lib/util/package-rules.ts index 487738be0..92228a94f 100644 --- a/lib/util/package-rules.ts +++ b/lib/util/package-rules.ts @@ -143,7 +143,7 @@ function matchesRule( packagePattern === '^*$' || packagePattern === '*' ? '.*' : packagePattern - ); // TODO #12071 + ); if (packageRegex.test(depName)) { logger.trace(`${depName} matches against ${String(packageRegex)}`); isMatch = true; @@ -173,7 +173,7 @@ function matchesRule( for (const pattern of excludePackagePatterns) { const packageRegex = regEx( pattern === '^*$' || pattern === '*' ? '.*' : pattern - ); // TODO #12071 + ); if (packageRegex.test(depName)) { logger.trace(`${depName} matches against ${String(packageRegex)}`); isMatch = true; diff --git a/lib/util/regex.ts b/lib/util/regex.ts index 612a4a1ae..d1da43bea 100644 --- a/lib/util/regex.ts +++ b/lib/util/regex.ts @@ -46,7 +46,7 @@ export function regEx( } export function escapeRegExp(input: string): string { - return input.replace(regEx(/[.*+\-?^${}()|[\]\\]/g), '\\$&'); // $& means the whole matched string // TODO #12071 + return input.replace(regEx(/[.*+\-?^${}()|[\]\\]/g), '\\$&'); // $& means the whole matched string } const configValStart = regEx(/^!?\//); diff --git a/lib/versioning/hashicorp/index.ts b/lib/versioning/hashicorp/index.ts index 62c1e99f4..d71645853 100644 --- a/lib/versioning/hashicorp/index.ts +++ b/lib/versioning/hashicorp/index.ts @@ -49,14 +49,14 @@ function getNewValue({ replaceValue = `$${npm.getMinor(newVersion)}$`; } return currentValue.replace( - regEx(`(?~>\\s*0\\.)\\d+(?.*)$`), // TODO #12071 + regEx(`(?~>\\s*0\\.)\\d+(?.*)$`), replaceValue ); } // handle special ~> 1.2 case if (regEx(/(~>\s*)\d+\.\d+$/).test(currentValue)) { return currentValue.replace( - regEx(`(?~>\\s*)\\d+\\.\\d+$`), // TODO #12071 + regEx(`(?~>\\s*)\\d+\\.\\d+$`), `$${npm.getMajor(newVersion)}.0` ); } diff --git a/lib/versioning/hex/index.ts b/lib/versioning/hex/index.ts index 828837720..161c276bf 100644 --- a/lib/versioning/hex/index.ts +++ b/lib/versioning/hex/index.ts @@ -10,11 +10,11 @@ export const supportedRangeStrategies = ['bump', 'extend', 'pin', 'replace']; function hex2npm(input: string): string { return input - .replace(regEx(/~>\s*(\d+\.\d+)$/), '^$1') // TODO #12071 - .replace(regEx(/~>\s*(\d+\.\d+\.\d+)/), '~$1') // TODO #12071 - .replace(regEx(/==|and/), '') // TODO #12071 + .replace(regEx(/~>\s*(\d+\.\d+)$/), '^$1') + .replace(regEx(/~>\s*(\d+\.\d+\.\d+)/), '~$1') + .replace(regEx(/==|and/), '') .replace('or', '||') - .replace(regEx(/!=\s*(\d+\.\d+(\.\d+.*)?)/), '>$1 <$1') // TODO #12071 + .replace(regEx(/!=\s*(\d+\.\d+(\.\d+.*)?)/), '>$1 <$1') .trim(); } diff --git a/lib/versioning/pep440/range.ts b/lib/versioning/pep440/range.ts index e2c840ba7..80d584661 100644 --- a/lib/versioning/pep440/range.ts +++ b/lib/versioning/pep440/range.ts @@ -167,8 +167,8 @@ export function isLessThanRange(input: string, range: string): boolean { .split(',') .map((x) => x - .replace(regEx(/\s*/g), '') // TODO #12071 - .split(regEx(/(~=|==|!=|<=|>=|<|>|===)/)) // TODO #12071 + .replace(regEx(/\s*/g), '') + .split(regEx(/(~=|==|!=|<=|>=|<|>|===)/)) .slice(1) ) .map(([op, version]) => { diff --git a/lib/versioning/rez/transform.ts b/lib/versioning/rez/transform.ts index 9b1cb5556..10c2a3155 100644 --- a/lib/versioning/rez/transform.ts +++ b/lib/versioning/rez/transform.ts @@ -105,7 +105,7 @@ export function rez2pep440(input: string): string { export function pep4402rezInclusiveBound(input: string): string { return input .split(',') - .map((v) => v.trim().replace(regEx(/[<>=]/g), '')) // TODO #12071 + .map((v) => v.trim().replace(regEx(/[<>=]/g), '')) .join('..'); } diff --git a/lib/versioning/ruby/index.ts b/lib/versioning/ruby/index.ts index ce03799f0..e0566af07 100644 --- a/lib/versioning/ruby/index.ts +++ b/lib/versioning/ruby/index.ts @@ -127,16 +127,15 @@ const getNewValue = ({ const delimiter = currentValue[0]; return newValue .split(',') - .map( - (element) => - element.replace( - regEx(`^(?\\s*)`), - `$${delimiter}` - ) // TODO #12071 + .map((element) => + element.replace( + regEx(`^(?\\s*)`), + `$${delimiter}` + ) ) .map( (element) => - element.replace(/(?\s*)$/, `${delimiter}$`) // TODO #12071 #12875 adds ' at front when re2 is used + element.replace(/(?\s*)$/, `${delimiter}$`) // TODO #12875 adds ' at front when re2 is used ) .join(','); } diff --git a/lib/workers/branch/schedule.ts b/lib/workers/branch/schedule.ts index 71696d72f..a84d7ed83 100644 --- a/lib/workers/branch/schedule.ts +++ b/lib/workers/branch/schedule.ts @@ -1,19 +1,15 @@ import later from '@breejs/later'; import is from '@sindresorhus/is'; import { DateTime } from 'luxon'; +import { fixShortHours } from '../../config/migration'; import type { RenovateConfig } from '../../config/types'; import { logger } from '../../logger'; -import { regEx } from '../../util/regex'; const scheduleMappings: Record = { 'every month': 'before 3am on the first day of the month', monthly: 'before 3am on the first day of the month', }; -function fixShortHours(input: string): string { - return input.replace(regEx(/( \d?\d)((a|p)m)/g), '$1:00$2'); -} - export function hasValidTimezone( timezone: string ): [boolean] | [boolean, string] { diff --git a/lib/workers/pr/body/index.ts b/lib/workers/pr/body/index.ts index 0a3f509fc..b67ec8896 100644 --- a/lib/workers/pr/body/index.ts +++ b/lib/workers/pr/body/index.ts @@ -1,6 +1,7 @@ import { platform } from '../../../platform'; import { regEx } from '../../../util/regex'; import * as template from '../../../util/template'; +import { ensureTrailingSlash } from '../../../util/url'; import type { BranchConfig } from '../../types'; import { getChangelogs } from './changelogs'; import { getPrConfigDescription } from './config-description'; @@ -43,7 +44,7 @@ function massageUpdateMetadata(config: BranchConfig): void { let fullUrl = sourceUrl; if (sourceDirectory) { fullUrl = - sourceUrl.replace(regEx(/\/?$/), '/') + + ensureTrailingSlash(sourceUrl) + 'tree/HEAD/' + sourceDirectory.replace('^/?/', ''); } diff --git a/lib/workers/pr/body/updates-table.ts b/lib/workers/pr/body/updates-table.ts index 173fe873c..bb4aebe8d 100644 --- a/lib/workers/pr/body/updates-table.ts +++ b/lib/workers/pr/body/updates-table.ts @@ -46,7 +46,7 @@ export function getPrUpdatesTable(config: BranchConfig): string { if (value) { res[header] = template .compile(value, upgrade) - .replace(regEx(/^``$/), ''); // TODO #12071 + .replace(regEx(/^``$/), ''); } else { res[header] = ''; } @@ -67,7 +67,7 @@ export function getPrUpdatesTable(config: BranchConfig): string { const content = row[column] ? row[column] .replace(regEx(/^@/), '@​') - .replace(regEx(/\|/g), '\\|') // TODO #12071 + .replace(regEx(/\|/g), '\\|') : ''; val += ` ${content} |`; } diff --git a/lib/workers/pr/changelog/release-notes.ts b/lib/workers/pr/changelog/release-notes.ts index ac3395296..192785bb2 100644 --- a/lib/workers/pr/changelog/release-notes.ts +++ b/lib/workers/pr/changelog/release-notes.ts @@ -68,9 +68,9 @@ export function massageBody( ): string { let body = input || ''; // Convert line returns - body = body.replace(regEx(/\r\n/g), '\n'); // TODO #12071 + body = body.replace(regEx(/\r\n/g), '\n'); // semantic-release cleanup - body = body.replace(regEx(/^<\/a>\n/), ''); // TODO #12071 + body = body.replace(regEx(/^<\/a>\n/), ''); body = body.replace( regEx( `^##? \\[[^\\]]*\\]\\(${baseUrl}[^/]*\\/[^/]*\\/compare\\/.*?\\n`, @@ -78,17 +78,17 @@ export function massageBody( false ), '' - ); // TODO #12071 + ); // Clean-up unnecessary commits link body = `\n${body}\n`.replace( regEx(`\\n${baseUrl}[^/]+\\/[^/]+\\/compare\\/[^\\n]+(\\n|$)`), '\n' - ); // TODO #12071 + ); // Reduce headings size body = body - .replace(regEx(/\n\s*####? /g), '\n##### ') // TODO #12071 - .replace(regEx(/\n\s*## /g), '\n#### ') // TODO #12071 - .replace(regEx(/\n\s*# /g), '\n### '); // TODO #12071 + .replace(regEx(/\n\s*####? /g), '\n##### ') + .replace(regEx(/\n\s*## /g), '\n#### ') + .replace(regEx(/\n\s*# /g), '\n### '); // Trim whitespace return body.trim(); } @@ -253,13 +253,13 @@ export async function getReleaseNotesMd( const deParenthesizedSection = section.replace( regEx(/[[\]()]/g), ' ' - ); // TODO #12071 + ); const [heading] = deParenthesizedSection.split('\n'); const title = heading - .replace(regEx(/^\s*#*\s*/), '') // TODO #12071 + .replace(regEx(/^\s*#*\s*/), '') .split(' ') .filter(Boolean); - let body = section.replace(regEx(/.*?\n(-{3,}\n)?/), '').trim(); // TODO #12071 + let body = section.replace(regEx(/.*?\n(-{3,}\n)?/), '').trim(); for (const word of title) { if (word.includes(version) && !isUrl(word)) { logger.trace({ body }, 'Found release notes for v' + version); @@ -268,7 +268,7 @@ export async function getReleaseNotesMd( const url = notesSourceUrl + '#' + - title.join('-').replace(regEx(/[^A-Za-z0-9-]/g), ''); // TODO #12071 + title.join('-').replace(regEx(/[^A-Za-z0-9-]/g), ''); body = massageBody(body, baseUrl); if (body?.length) { try { diff --git a/lib/workers/pr/code-owners.ts b/lib/workers/pr/code-owners.ts index 22f7681ad..8fcdbfe70 100644 --- a/lib/workers/pr/code-owners.ts +++ b/lib/workers/pr/code-owners.ts @@ -27,7 +27,7 @@ export async function codeOwnersForPr(pr: Pr): Promise { .map((line) => line.trim()) .filter((line) => line && !line.startsWith('#')) .map((line) => { - const [pattern, ...usernames] = line.split(regEx(/\s+/)); // TODO #12071 + const [pattern, ...usernames] = line.split(regEx(/\s+/)); return { usernames, match: (path: string) => { diff --git a/lib/workers/repository/init/vulnerability.ts b/lib/workers/repository/init/vulnerability.ts index 321ddf5bb..eb259a32a 100644 --- a/lib/workers/repository/init/vulnerability.ts +++ b/lib/workers/repository/init/vulnerability.ts @@ -114,7 +114,7 @@ export async function detectVulnerabilityAlerts( vulnerableRequirements = vulnerableRequirements.replace( regEx(/^= /), '== ' - ); // TODO #12071 + ); } combinedAlerts[fileName] ||= {}; combinedAlerts[fileName][datasource] ||= {}; diff --git a/lib/workers/repository/onboarding/pr/pr-list.ts b/lib/workers/repository/onboarding/pr/pr-list.ts index b381c9f48..519b4f7ec 100644 --- a/lib/workers/repository/onboarding/pr/pr-list.ts +++ b/lib/workers/repository/onboarding/pr/pr-list.ts @@ -18,7 +18,7 @@ export function getPrList( prDesc += branches.length > 1 ? `s:\n\n` : `:\n\n`; for (const branch of branches) { - const prTitleRe = regEx(/@([a-z]+\/[a-z]+)/); // TODO #12071 + const prTitleRe = regEx(/@([a-z]+\/[a-z]+)/); prDesc += `
\n${branch.prTitle.replace( prTitleRe, '@​$1' diff --git a/lib/workers/repository/updates/flatten.ts b/lib/workers/repository/updates/flatten.ts index 5f3bf1e64..36cd14114 100644 --- a/lib/workers/repository/updates/flatten.ts +++ b/lib/workers/repository/updates/flatten.ts @@ -19,8 +19,8 @@ function sanitizeDepName(depName: string): string { return depName .replace('@types/', '') .replace('@', '') - .replace(regEx(/\//g), '-') // TODO #12071 - .replace(regEx(/\s+/g), '-') // TODO #12071 + .replace(regEx(/\//g), '-') + .replace(regEx(/\s+/g), '-') .replace(regEx(/-+/), '-') .toLowerCase(); } @@ -39,8 +39,8 @@ export function applyUpdateConfig(input: BranchUpgradeConfig): any { const parsedSourceUrl = parseUrl(updateConfig.sourceUrl); if (parsedSourceUrl?.pathname) { updateConfig.sourceRepoSlug = parsedSourceUrl.pathname - .replace(regEx(/^\//), '') // remove leading slash // TODO #12071 - .replace(regEx(/\//g), '-') // change slashes to hyphens // TODO #12071 + .replace(regEx(/^\//), '') // remove leading slash + .replace(regEx(/\//g), '-') // change slashes to hyphens .replace(regEx(/-+/g), '-'); // remove multiple hyphens } } diff --git a/lib/workers/repository/updates/generate.ts b/lib/workers/repository/updates/generate.ts index 49c9570f2..56d86aff2 100644 --- a/lib/workers/repository/updates/generate.ts +++ b/lib/workers/repository/updates/generate.ts @@ -160,7 +160,7 @@ export function generateBranchConfig( } upgrade.commitMessagePrefix = CommitMessage.formatPrefix(semanticPrefix); upgrade.toLowerCase = - regEx(/[A-Z]/).exec(upgrade.semanticCommitType) === null && // TODO #12071 + regEx(/[A-Z]/).exec(upgrade.semanticCommitType) === null && !upgrade.semanticCommitType.startsWith(':'); } // Compile a few times in case there are nested templates @@ -179,9 +179,9 @@ export function generateBranchConfig( throw new Error(CONFIG_SECRETS_EXPOSED); } upgrade.commitMessage = upgrade.commitMessage.trim(); // Trim exterior whitespace - upgrade.commitMessage = upgrade.commitMessage.replace(regEx(/\s+/g), ' '); // Trim extra whitespace inside string // TODO #12071 + upgrade.commitMessage = upgrade.commitMessage.replace(regEx(/\s+/g), ' '); // Trim extra whitespace inside string upgrade.commitMessage = upgrade.commitMessage.replace( - regEx(/to vv(\d)/), // TODO #12071 + regEx(/to vv(\d)/), 'to v$1' ); if (upgrade.toLowerCase) { @@ -203,7 +203,7 @@ export function generateBranchConfig( upgrade.prTitle = template .compile(upgrade.prTitle, upgrade) .trim() - .replace(regEx(/\s+/g), ' '); // TODO #12071 + .replace(regEx(/\s+/g), ' '); // istanbul ignore if if (upgrade.prTitle !== sanitize(upgrade.prTitle)) { logger.debug( diff --git a/test/exec-util.ts b/test/exec-util.ts index d6cecc504..2f00637e7 100644 --- a/test/exec-util.ts +++ b/test/exec-util.ts @@ -31,7 +31,7 @@ export function execSnapshot(cmd: string, options?: CallOptions): ExecSnapshot { if (is.string(v)) { const val = v .replace(regEx(/\\(\w)/g), '/$1') - .replace(cwd, '/root/project'); // TODO #12071 + .replace(cwd, '/root/project'); this.update(val); } }); diff --git a/tools/generate-imports.mjs b/tools/generate-imports.mjs index e9508e158..4633a0d09 100644 --- a/tools/generate-imports.mjs +++ b/tools/generate-imports.mjs @@ -73,7 +73,7 @@ async function generateData() { /** @type {string[]} */ const contentMapAssignments = []; for (const file of files) { - const key = file.replace(/\\/g, '/'); // TODO #12071 + const key = file.replace(/\\/g, '/'); const rawFileContent = await fs.readFile(file, 'utf8'); const value = JSON.stringify(rawFileContent);