Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
"no-regex-spaces": "error",
"no-var": "error",
"prefer-const": "error",
"prefer-named-capture-group": "error",
"prefer-rest-params": "error",
"prefer-spread": "error",
"typescript/ban-ts-comment": "error",
Expand Down
5 changes: 4 additions & 1 deletion lib/config/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import { mergeChildConfig } from './utils.ts';

const options = getOptions();
export function fixShortHours(input: string): string {
return input.replace(regEx(/( \d?\d)((a|p)m)/g), '$1:00$2');
return input.replace(
regEx(/(?<hours> \d?\d)(?<meridiem>(?:a|p)m)/g),
'$<hours>:00$<meridiem>',
);
}

let optionTypes: Record<string, RenovateOptions['type']>;
Expand Down
24 changes: 16 additions & 8 deletions lib/config/migrations/custom/schedule-migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { isArray, isString } from '@sindresorhus/is';
import { regEx } from '../../../util/regex.ts';
import { AbstractMigration } from '../base/abstract-migration.ts';

const shortHoursRegex = regEx(/( \d?\d)((a|p)m)/g);
const shortHoursRegex = regEx(/(?<hours> \d?\d)(?<meridiem>(?:a|p)m)/g);
const afterBeforeRegex = regEx(
/^(.*?)(after|before) (.*?) and (after|before) (.*?)( |$)(.*)/,
/^(?<pre>.*?)(?<afterBefore1>after|before) (?<mid1>.*?) and (?<afterBefore2>after|before) (?<mid2>.*?)(?: |$)(?<rest>.*)/,
);
const dayRegex1 = regEx(/every (mon|tues|wednes|thurs|fri|satur|sun)day$/);
const dayRegex2 = regEx(/every ([a-z]*day)$/);
const dayRegex1 = regEx(/every (?:mon|tues|wednes|thurs|fri|satur|sun)day$/);
const dayRegex2 = regEx(/every (?<day>[a-z]*day)$/);
export class ScheduleMigration extends AbstractMigration {
override readonly propertyName = 'schedule';

Expand All @@ -32,7 +32,7 @@ export class ScheduleMigration extends AbstractMigration {
) {
const parsedSchedule = later.parse.text(
// We need to massage short hours first before we can parse it
schedules[i].replace(shortHoursRegex, '$1:00$2'),
schedules[i].replace(shortHoursRegex, '$<hours>:00$<meridiem>'),
).schedules[0];
// Only migrate if the after time is greater than before, e.g. "after 10pm and before 5am"
if (!parsedSchedule?.t_a || !parsedSchedule.t_b) {
Expand All @@ -42,10 +42,18 @@ export class ScheduleMigration extends AbstractMigration {
if (parsedSchedule.t_a[0] > parsedSchedule.t_b[0]) {
const toSplit = schedules[i];
schedules[i] = toSplit
.replace(afterBeforeRegex, '$1$2 $3 $7')
.replace(
afterBeforeRegex,
'$<pre>$<afterBefore1> $<mid1> $<rest>',
)
.trim();
schedules.push(
toSplit.replace(afterBeforeRegex, '$1$4 $5 $7').trim(),
toSplit
.replace(
afterBeforeRegex,
'$<pre>$<afterBefore2> $<mid2> $<rest>',
)
.trim(),
);
}
}
Expand All @@ -67,7 +75,7 @@ export class ScheduleMigration extends AbstractMigration {
schedules[i] = schedules[i].replace(' every day', '');
}
if (dayRegex1.test(schedules[i])) {
schedules[i] = schedules[i].replace(dayRegex2, 'on $1');
schedules[i] = schedules[i].replace(dayRegex2, 'on $<day>');
}
if (schedules[i].endsWith('days')) {
schedules[i] = schedules[i].replace('days', 'day');
Expand Down
5 changes: 4 additions & 1 deletion lib/config/options/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export function getEnvName(option: EnvNameOption): string {
if (option.env) {
return option.env;
}
const nameWithUnderscores = option.name.replace(regEx(/([A-Z])/g), '_$1');
const nameWithUnderscores = option.name.replace(
regEx(/(?<upper>[A-Z])/g),
'_$<upper>',
);
return `RENOVATE_${nameWithUnderscores.toUpperCase()}`;
}
4 changes: 2 additions & 2 deletions lib/config/options/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ describe('config/options/index', () => {
).flat();

const directPattern =
/(?<![.\w])(?:template\.)?compile\(\s*(?:config|update|upgrade|upg|toApply)\??\.(\w+)/g;
/(?<![.\w])(?:template\.)?compile\(\s*(?:config|update|upgrade|upg|toApply)\??\.(?<name>\w+)/g;
const detectedOptions = new Set<string>();

for (const file of sourceFiles) {
const content = await readFile(file, 'utf-8');
let match;
while ((match = directPattern.exec(content)) !== null) {
const name = match[1];
const name = match.groups!.name;
const option = allOptions.find((o) => o.name === name);
// Only include string or array-of-string options (not objects like userStrings)
if (
Expand Down
4 changes: 2 additions & 2 deletions lib/config/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export function parseFileConfig(
// strip them before validation. The actual parsing is handled by a lenient
// JSONC parser which tolerates trailing commas.
const jsonString = stripJsonComments(fileContents).replace(
regEx(/,(\s*[}\]])/g),
'$1',
regEx(/,(?<trailing>\s*[}\]])/g),
'$<trailing>',
);
let allowDuplicateKeys = true;
let jsonValidationError = jsonValidator.validate(
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export function parsePreset(input: string): ParsedPreset {
presetName = str.slice(1);
} else if (str.startsWith('@')) {
// scoped namespace
[, repo] = regEx(/(@.*?)(:|$)/).exec(str)!;
repo = regEx(/(?<scope>@.*?)(?::|$)/).exec(str)!.groups!.scope;
str = str.slice(repo.length);
if (!repo.includes('/')) {
repo += '/renovate-config';
Expand Down
2 changes: 1 addition & 1 deletion lib/config/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const ignoredNodes = [
'prBody', // deprecated
'minimumConfidence', // undocumented feature flag
];
const tzRe = regEx(/^:timezone\((.+)\)$/);
const tzRe = regEx(/^:timezone\((?<timezone>.+)\)$/);
const rulesRe = regEx(/p.*Rules\[\d+\]$/);
const repoEntryRe = regEx(/^repositories\[\d+\]$/);

Expand Down
4 changes: 2 additions & 2 deletions lib/logger/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,14 @@ export function sanitizeValue(

const urlRe = regEx(/[a-z]{3,9}:\/\/[^@/]+@[a-z0-9.-]+/gi);
const urlCredRe = regEx(/\/\/[^@]+@/g);
const dataUriCredRe = regEx(/^(data:[0-9a-z-]+\/[0-9a-z-]+;).+/i);
const dataUriCredRe = regEx(/^(?<prefix>data:[0-9a-z-]+\/[0-9a-z-]+;).+/i);

export function sanitizeUrls(text: string): string {
return text
.replace(urlRe, (url) => {
return url.replace(urlCredRe, '//**redacted**@');
})
.replace(dataUriCredRe, '$1**redacted**');
.replace(dataUriCredRe, '$<prefix>**redacted**');
}

export function getEnv(key: string): string | undefined {
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/datasource/deno/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class DenoDatasource extends Datasource {
const massagedRegistryUrl = registryUrl!;

const extractResult = regEx(
/^(https:\/\/deno.land\/)(?<rawPackageName>[^@\s]+)/,
/^(?:https:\/\/deno.land\/)(?<rawPackageName>[^@\s]+)/,
).exec(packageName);
const rawPackageName = extractResult?.groups?.rawPackageName;
if (isNullOrUndefined(rawPackageName)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/datasource/docker/ecr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { regEx } from '../../../util/regex.ts';
import { addSecretForSanitizing } from '../../../util/sanitize.ts';

export const ecrRegex = regEx(
/\d+\.(?:dkr\.ecr|dkr-ecr)(?:-fips)?\.([-a-z0-9]+)\.(?:amazonaws\.com|on\.aws|amazonaws\.com\.cn|on\.amazonwebservices\.com\.cn|amazonaws\.eu|on\.amazonwebservices\.eu|c2s\.ic\.gov|on\.aws\.ic\.gov|sc2s\.sgov\.gov|on\.aws\.scloud|scloud\.adc-e\.uk|on\.cloud-aws\.adc-e\.uk|csp\.hci\.ic\.gov|on\.aws\.hci\.ic\.gov|)/,
/\d+\.(?:dkr\.ecr|dkr-ecr)(?:-fips)?\.(?<region>[-a-z0-9]+)\.(?:amazonaws\.com|on\.aws|amazonaws\.com\.cn|on\.amazonwebservices\.com\.cn|amazonaws\.eu|on\.amazonwebservices\.eu|c2s\.ic\.gov|on\.aws\.ic\.gov|sc2s\.sgov\.gov|on\.aws\.scloud|scloud\.adc-e\.uk|on\.cloud-aws\.adc-e\.uk|csp\.hci\.ic\.gov|on\.aws\.hci\.ic\.gov|)/,
);
export const ecrPublicRegex = regEx(/public\.ecr\.aws|ecr-public\.aws\.com/);

Expand Down
2 changes: 1 addition & 1 deletion lib/modules/datasource/docker/google.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { regEx } from '../../../util/regex.ts';

export const googleRegex = regEx(
/(((eu|us|asia)\.)?gcr\.io|[a-z0-9-]+-docker\.pkg\.dev)/,
/(?:(?:(?:eu|us|asia)\.)?gcr\.io|[a-z0-9-]+-docker\.pkg\.dev)/,
);
2 changes: 1 addition & 1 deletion lib/modules/datasource/go/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class BaseGoDatasource {
private static async goGetDatasource(
goModule: string,
): Promise<DataSource | null> {
const goModuleUrl = goModule.replace(regEx(/\.git(\/[a-z0-9/]*)?$/), '');
const goModuleUrl = goModule.replace(regEx(/\.git(?:\/[a-z0-9/]*)?$/), '');
const pkgUrl = `https://${goModuleUrl}?go-get=1`;
const { body: html } = await BaseGoDatasource.http.getText(pkgUrl);

Expand Down
4 changes: 2 additions & 2 deletions lib/modules/datasource/go/goproxy-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ export function parseGoproxy(
}

const result: GoproxyItem[] = input
.split(regEx(/([^,|]*(?:,|\|))/))
.split(regEx(/(?<segment>[^,|]*(?:,|\|))/))
.filter(isTruthy)
.map((s) => s.split(regEx(/(,|\|)/)))
.map((s) => s.split(regEx(/(?<separator>,|\|)/)))
// Empty segments (`a||b`, `,a`) carry no url to query, and keeping them
// would apply their separator as the fallback strategy for a bogus request
.filter(([url]) => isTruthy(url))
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/datasource/go/releases-goproxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export class GoProxyDatasource extends Datasource {
* @see https://golang.org/ref/mod#goproxy-protocol
*/
encodeCase(input: string): string {
return input.replace(regEx(/([A-Z])/g), (x) => `!${x.toLowerCase()}`);
return input.replace(regEx(/(?:[A-Z])/g), (x) => `!${x.toLowerCase()}`);
}

async listVersions(baseUrl: string, packageName: string): Promise<Release[]> {
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/datasource/gradle-version/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class GradleVersionDatasource extends Datasource {
*/
private static getGitRef(version: string): string {
const [versionPart, typePart, unstablePart] = version.split(
regEx(/-([a-z]+)-/),
regEx(/-(?<type>[a-z]+)-/),
);

let suffix = '';
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/datasource/helm/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ function isPossibleChartRepo(url: string): boolean {
}

const githubRelease = regEx(
/^(https:\/\/github\.com\/[^/]+\/[^/]+)\/releases\//,
/^(?<repoUrl>https:\/\/github\.com\/[^/]+\/[^/]+)\/releases\//,
);

function getSourceUrl(release: HelmRelease): string | undefined {
// it's a github release :)
const [githubUrl] = release.urls;
const releaseMatch = githubRelease.exec(githubUrl);
if (releaseMatch) {
return releaseMatch[1];
return releaseMatch.groups!.repoUrl;
}

if (release.home && isPossibleChartRepo(release.home)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/datasource/hexpm-bob/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class HexpmBobDatasource extends Datasource {
private static isStable(version: string, packageType: PackageType): boolean {
switch (packageType) {
case 'elixir':
return regEx(/^v\d+\.\d+\.\d+($|-otp)/).test(version);
return regEx(/^v\d+\.\d+\.\d+(?:$|-otp)/).test(version);
case 'erlang':
return version.startsWith('OTP-');
}
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/datasource/npm/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { defaultRegistryUrl } from './common.ts';
import { CachedPackument, NpmResponse } from './schema.ts';

const SHORT_REPO_REGEX = regEx(
/^((?<platform>bitbucket|github|gitlab):)?(?<shortRepo>[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+)$/,
/^(?:(?<platform>bitbucket|github|gitlab):)?(?<shortRepo>[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+)$/,
);

const platformMapping: Record<string, string> = {
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/datasource/npm/npmrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function envReplace(value: any, env = getEnv()): any {
return value;
}

const ENV_EXPR = regEx(/(\\*)\$\{([^}]+)\}/g);
const ENV_EXPR = regEx(/(?<esc>\\*)\$\{(?<envVarName>[^}]+)\}/g);

return value.replace(ENV_EXPR, (match, _esc, envVarName) => {
if (env[envVarName] === undefined) {
Expand Down
6 changes: 4 additions & 2 deletions lib/modules/datasource/pypi/common.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { regEx } from '../../../util/regex.ts';

const githubRepoPattern = regEx(/^https?:\/\/github\.com\/([^/]+)\/[^/]+$/);
const githubRepoPattern = regEx(
/^https?:\/\/github\.com\/(?<owner>[^/]+)\/[^/]+$/,
);

export function isGitHubRepo(url: string): boolean {
const m = url.match(githubRepoPattern);
return !!m && m[1] !== 'sponsors';
return !!m && m.groups!.owner !== 'sponsors';
}

// https://packaging.python.org/en/latest/specifications/name-normalization/
Expand Down
8 changes: 4 additions & 4 deletions lib/modules/datasource/pypi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,12 @@ export class PypiDatasource extends Datasource {
.replace(regEx(/<\/?pre>/), '')
// Certain simple repositories like artifactory don't escape > and <
.replace(
regEx(/data-requires-python="([^"]*?)>([^"]*?)"/g),
'data-requires-python="$1&gt;$2"',
regEx(/data-requires-python="(?<before>[^"]*?)>(?<after>[^"]*?)"/g),
'data-requires-python="$<before>&gt;$<after>"',
)
.replace(
regEx(/data-requires-python="([^"]*?)<([^"]*?)"/g),
'data-requires-python="$1&lt;$2"',
regEx(/data-requires-python="(?<before>[^"]*?)<(?<after>[^"]*?)"/g),
'data-requires-python="$<before>&lt;$<after>"',
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/datasource/unity3d/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ describe('modules/datasource/unity3d/index', () => {
}),
]),
homepage: 'https://unity.com/',
registryUrl: expect.stringMatching(/(releases|lts)/),
registryUrl: expect.stringMatching(/(?:releases|lts)/),
}),
);
});
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/manager/ansible-galaxy/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function interpretLine(
dependency: AnsibleGalaxyPackageDependency,
): void {
const localDependency = dependency;
const key = lineMatch[2];
const value = lineMatch[3].replace(regEx(/["']/g), '');
const key = lineMatch.groups!.key;
const value = lineMatch.groups!.value.replace(regEx(/["']/g), '');
switch (key) {
case 'name': {
localDependency.managerData.name = value;
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/manager/ansible-galaxy/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ function interpretLine(
dependency: AnsibleGalaxyPackageDependency,
): AnsibleGalaxyPackageDependency | null {
const localDependency = dependency;
const key = lineMatch[2];
const value = lineMatch[3].replace(regEx(/["']/g), '');
const key = lineMatch.groups!.key;
const value = lineMatch.groups!.value.replace(regEx(/["']/g), '');
switch (key) {
case 'name': {
localDependency.managerData.name = value;
Expand Down
8 changes: 4 additions & 4 deletions lib/modules/manager/ansible-galaxy/util.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { regEx } from '../../../util/regex.ts';

export const newBlockRegEx = regEx(/^\s*-\s*((\w+):\s*(.*))$/);
export const blockLineRegEx = regEx(/^\s*((\w+):\s*(\S+))\s*$/);
export const newBlockRegEx = regEx(/^\s*-\s*(?:(?<key>\w+):\s*(?<value>.*))$/);
export const blockLineRegEx = regEx(/^\s*(?:(?<key>\w+):\s*(?<value>\S+))\s*$/);
export const galaxyDepRegex = regEx(/[\w-]+\.[\w-]+/);
export const dependencyRegex = regEx(/^dependencies:/);
export const galaxyRegEx = regEx(
/^\s+["']?(?<packageName>[\w.]+)["']?:\s*["']?(?<version>.+?)["']?\s*(\s#.*)?$/,
/^\s+["']?(?<packageName>[\w.]+)["']?:\s*["']?(?<version>.+?)["']?\s*(?:\s#.*)?$/,
);
export const nameMatchRegex = regEx(
/(?<source>((git\+)?(?:(git|ssh|https?):\/\/)?(.*@)?(?<hostname>[\w.-]+)(?:(:\d+)?\/|:))(?<depName>[\w./-]+)(?:\.git)?)(,(?<version>[\w.]*))?/,
/(?<source>(?:(?:git\+)?(?:(?:git|ssh|https?):\/\/)?(?:.*@)?(?<hostname>[\w.-]+)(?:(?::\d+)?\/|:))(?<depName>[\w./-]+)(?:\.git)?)(?:,(?<version>[\w.]*))?/,
);
4 changes: 2 additions & 2 deletions lib/modules/manager/ansible/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ export function extractPackageFile(
): PackageFileContent | null {
logger.trace(`ansible.extractPackageFile(${packageFile})`);
let deps: PackageDependency[] = [];
const re = regEx(/^\s*image:\s*'?"?([^\s'"]+)'?"?\s*$/);
const re = regEx(/^\s*image:\s*'?"?(?<image>[^\s'"]+)'?"?\s*$/);
for (const line of content.split(newlineRegex)) {
const match = re.exec(line);
if (match) {
const currentFrom = match[1];
const currentFrom = match.groups!.image;
const dep = getDep(currentFrom, true, config.registryAliases);
logger.debug(
{
Expand Down
Loading