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

46 lines
1.6 KiB
TypeScript

import { gt, gte, lt } from '@renovatebot/ruby-semver';
import { GTE, LT, LTE, NOT_EQUAL, PGTE } from '../operator.ts';
import { parseRanges, stringifyRanges } from '../range.ts';
import type { Range } from '../types.ts';
import { adapt, trimZeroes } from '../version.ts';
import { replacePart } from './replace.ts';
export default ({ range, to }: { range: string; to: string }): string => {
const parts = parseRanges(range).map((part): Range => {
const { operator, version: ver } = part;
switch (operator) {
// Update upper bound (`<` and `<=`) ranges only if the new version violates them
case LT:
return gte(to, ver) ? replacePart(part, to) : part;
case LTE:
return gt(to, ver) ? replacePart(part, to) : part;
// `~>` ranges.
case PGTE: {
// Try to add / remove extra `>=` constraint.
const trimmed = adapt(to, ver);
if (trimZeroes(trimmed) === trimZeroes(to)) {
// E.g. `'~> 5.2', '>= 5.2.0'`. In this case the latter is redundant.
return { ...part, version: trimmed, companion: undefined };
}
// E.g. `'~> 5.2', '>= 5.2.1'`.
return {
...part,
version: trimmed,
companion: { operator: GTE, delimiter: ' ', version: to },
};
}
case NOT_EQUAL:
if (lt(ver, to)) {
// The version to exclude is now out of range.
return { ...part, operator: GTE, version: to };
}
return part;
default:
// For `=` and lower bound ranges, always keep it stick to the new version.
return replacePart(part, to);
}
});
return stringifyRanges(parts);
};