mirror of
https://github.com/renovatebot/renovate.git
synced 2026-11-02 10:33:39 +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
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { GTE, LT, PGTE } from '../operator.ts';
|
|
import { parseRanges, satisfiesRange, stringifyRanges } from '../range.ts';
|
|
import type { Range } from '../types.ts';
|
|
import { increment, pgteUpperBound } from '../version.ts';
|
|
import { replacePart } from './replace.ts';
|
|
|
|
export default ({ range, to }: { range: string; to: string }): string => {
|
|
const parts = parseRanges(range).flatMap((part): Range[] => {
|
|
if (satisfiesRange(to, part)) {
|
|
return [part];
|
|
}
|
|
|
|
const { operator, version: ver, companion } = part;
|
|
switch (operator) {
|
|
// `~>` works as both lower bound and upper bound.
|
|
// We need to decompose it to get wider range.
|
|
case PGTE: {
|
|
// Prefer constraints from `>=`
|
|
const baseVersion = companion ? companion.version : ver;
|
|
const limit = increment(pgteUpperBound(ver), to);
|
|
return [
|
|
{ operator: GTE, delimiter: ' ', version: baseVersion },
|
|
{ operator: LT, delimiter: ' ', version: limit },
|
|
];
|
|
}
|
|
default:
|
|
return [replacePart(part, to)];
|
|
}
|
|
});
|
|
|
|
return stringifyRanges(parts);
|
|
};
|