Files
Sebastian Poxhofer e0cec3dc95 refactor(lint): add types-location rule and enable it for lib/modules (#45497)
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
2026-08-27 19:52:09 +00:00

64 lines
2.1 KiB
TypeScript

import { logger } from '../../../../logger/index.ts';
import { EQUAL, GT, GTE, LT, LTE, NOT_EQUAL, PGTE } from '../operator.ts';
import { parseRanges, satisfiesRange, stringifyRanges } from '../range.ts';
import type { Range } from '../types.ts';
import { adapt, decrement, floor, increment } from '../version.ts';
// Common logic for replace, widen, and bump strategies
// It basically makes the range stick to the new version.
export function replacePart(part: Range, to: string): Range {
const { operator, version: ver, companion } = part;
switch (operator) {
case LT:
return { ...part, version: increment(ver, to) };
case LTE:
return { ...part, version: to };
case PGTE:
if (companion) {
return {
...part,
version: floor(adapt(to, ver)),
companion: { ...companion, version: to },
};
}
return { ...part, version: floor(adapt(to, ver)) };
case GT:
return { ...part, version: decrement(to) };
case GTE:
case EQUAL:
return { ...part, version: to };
case NOT_EQUAL:
return part;
// istanbul ignore next
default:
logger.warn({ operator }, `Unsupported ruby versioning operator`);
return { operator: '', delimiter: ' ', version: '' };
}
}
export default ({ range, to }: { range: string; to: string }): string => {
const parts = parseRanges(range).map((part): Range => {
if (satisfiesRange(to, part)) {
// The new version satisfies the range. Keep it as-is.
// Note that consecutive `~>` and `>=` parts are combined into one Range object,
// therefore both parts are updated if the new version violates one of them.
return part;
}
if (part.version.split('.').length > to.split('.').length) {
const diff = part.version.split('.').length - to.split('.').length;
const versionToReplace = [to, ...Array(diff).fill('0')].join('.');
const replacement = replacePart(part, versionToReplace);
return {
...replacement,
version: replacement.version.split('.').slice(0, -diff).join('.'),
};
}
return replacePart(part, to);
});
return stringifyRanges(parts);
};