Files
renovate/lib/modules/versioning/ivy/parse.ts
T
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

55 lines
1.2 KiB
TypeScript

import { regEx } from '../../../util/regex.ts';
import { isSingleVersion, parseRange, rangeToStr } from '../maven/compare.ts';
import type { Revision } from './types.ts';
const REV_TYPE_LATEST = 'REV_TYPE_LATEST';
const REV_TYPE_SUBREV = 'REV_TYPE_SUBREVISION';
const REV_TYPE_RANGE = 'REV_TYPE_RANGE';
export const LATEST_REGEX = regEx(/^latest\.|^latest$/i);
function parseDynamicRevision(str: string): Revision | null {
if (!str) {
return null;
}
if (LATEST_REGEX.test(str)) {
const value = str.replace(LATEST_REGEX, '').toLowerCase() || '';
return {
type: REV_TYPE_LATEST,
value: value === 'integration' ? '' : value,
};
}
const SUBREV_REGEX = regEx(/\.\+$/);
if (str.endsWith('.+')) {
const value = str.replace(SUBREV_REGEX, '');
if (isSingleVersion(value)) {
return {
type: REV_TYPE_SUBREV,
value,
};
}
}
const range = parseRange(str);
if (range?.length === 1) {
const rangeValue = rangeToStr(range);
if (rangeValue) {
return {
type: REV_TYPE_RANGE,
value: rangeValue,
};
}
}
return null;
}
export {
REV_TYPE_LATEST,
REV_TYPE_RANGE,
REV_TYPE_SUBREV,
parseDynamicRevision,
};