mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-24 22:48:06 +00:00
e0cec3dc95
feat(lint): add `types-location` rule and enable it for `lib/modules`
Reviewers consistently ask for exported types to be moved into a
colocated `types.ts`. Add a `renovate/types-location` oxlint rule that
reports `export interface` / `export type` declarations outside such a
file, and turn it on across `lib/modules`.
Re-exports (`export type { X }`, `export type *`), file-local types, and
values (enums, classes, functions) are left alone. `schema.ts` files and
`schema/` directories are excluded via config, matching how
`zod-schema-location` is configured — inferred types belong next to the
schema they are derived from.
Relocating the 87 existing violations means:
- new `types.ts` files for the modules that had none
- `terragrunt/common.ts` folded into its `types.ts`, as it held nothing
else
- `RangeBound` in `versioning/gradle/compare.ts` un-exported, since only
a file-local interface referenced it
- `bazel-module/parser/fragments.ts` split from its inferred types, which
now live in `parser/types.ts` and infer through a namespace import so
each schema keeps its merged name
122 lines
3.0 KiB
TypeScript
122 lines
3.0 KiB
TypeScript
import { DateTime } from 'luxon';
|
|
import { logger } from '../../../logger/index.ts';
|
|
import { regEx } from '../../../util/regex.ts';
|
|
import type { DistroInfo } from '../distro.ts';
|
|
import type { DistroInfoRecordWithVersion } from '../types.ts';
|
|
|
|
const refreshInterval = { days: 1 };
|
|
|
|
const datedRegex = regEx(
|
|
/^(?<codename>\w+)-(?<date>\d{8})(?<suffix>\.\d{1,2})?$/,
|
|
);
|
|
|
|
export function isDatedCodeName(
|
|
input: string,
|
|
distroInfo: DistroInfo,
|
|
): boolean {
|
|
const match = datedRegex.exec(input);
|
|
if (!match?.groups) {
|
|
return false;
|
|
}
|
|
const codename = match.groups.codename;
|
|
return distroInfo.isCodename(codename);
|
|
}
|
|
|
|
export function getDatedContainerImageCodename(version: string): null | string {
|
|
const match = datedRegex.exec(version);
|
|
if (!match?.groups) {
|
|
return null;
|
|
}
|
|
return match.groups.codename;
|
|
}
|
|
|
|
export function getDatedContainerImageVersion(version: string): null | number {
|
|
const match = datedRegex.exec(version);
|
|
if (!match?.groups) {
|
|
return null;
|
|
}
|
|
|
|
return parseInt(match.groups.date, 10);
|
|
}
|
|
|
|
export function getDatedContainerImageSuffix(version: string): null | string {
|
|
const match = datedRegex.exec(version);
|
|
if (!match?.groups?.suffix) {
|
|
return null;
|
|
}
|
|
|
|
return match.groups.suffix;
|
|
}
|
|
|
|
export class RollingReleasesData {
|
|
private ltsToVer = new Map<string, DistroInfoRecordWithVersion>();
|
|
private verToLts = new Map<string, DistroInfoRecordWithVersion>();
|
|
private timestamp = DateTime.fromMillis(0).toUTC(); // start of epoch
|
|
private distroInfo: DistroInfo;
|
|
|
|
constructor(distroInfo: DistroInfo) {
|
|
this.distroInfo = distroInfo;
|
|
}
|
|
|
|
getVersionByLts(input: string): string {
|
|
this.build();
|
|
const schedule = this.ltsToVer.get(input);
|
|
if (schedule) {
|
|
return schedule.version;
|
|
}
|
|
return input;
|
|
}
|
|
|
|
getLtsByVersion(input: string): string {
|
|
this.build();
|
|
const di = this.verToLts.get(input);
|
|
if (di) {
|
|
return di.series;
|
|
}
|
|
return input;
|
|
}
|
|
|
|
has(version: string): boolean {
|
|
this.build();
|
|
return this.ltsToVer.has(version);
|
|
}
|
|
|
|
schedule(version: string): DistroInfoRecordWithVersion | undefined {
|
|
this.build();
|
|
let schedule: DistroInfoRecordWithVersion | undefined = undefined;
|
|
if (this.verToLts.has(version)) {
|
|
schedule = this.verToLts.get(version);
|
|
}
|
|
if (this.ltsToVer.has(version)) {
|
|
schedule = this.ltsToVer.get(version);
|
|
}
|
|
return schedule;
|
|
}
|
|
|
|
private build(): void {
|
|
const now = DateTime.now().toUTC();
|
|
if (now < this.timestamp.plus(refreshInterval)) {
|
|
return;
|
|
}
|
|
logger.debug('RollingReleasesData - data written');
|
|
this.timestamp = now;
|
|
for (let i = 0; i < 3; i++) {
|
|
const di = this.distroInfo.getNLatest(i);
|
|
|
|
// should never happen, just for type checking
|
|
if (!di) {
|
|
return;
|
|
}
|
|
|
|
let prefix = '';
|
|
for (let j = 0; j < i; j++) {
|
|
prefix += 'old';
|
|
}
|
|
di.series = `${prefix}stable`;
|
|
|
|
this.ltsToVer.set(di.series, di);
|
|
this.verToLts.set(di.version, di);
|
|
}
|
|
}
|
|
}
|