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

77 lines
2.0 KiB
TypeScript

import {
isEmptyArray,
isNonEmptyArray,
isNonEmptyStringAndNotWhitespace,
} from '@sindresorhus/is';
import { RegExpVersioningApi } from '../regex/index.ts';
import type { RegExpVersion } from '../regex/types.ts';
import type { VersioningApiConstructor } from '../types.ts';
export const id = 'nixpkgs';
export const displayName = 'Nixpkgs';
export const urls = ['[Nixpkgs repository](https://github.com/NixOS/nixpkgs)'];
export const supportsRanges = false;
export class NixPkgsVersioning extends RegExpVersioningApi {
private static readonly versionRegex =
'^(?<prefix>(nixos|nixpkgs|release))-((?<major>\\d{2})\\.(?<minor>\\d{2})|unstable)(-(?<suffix>(small|aarch64|darwin)))?$';
constructor() {
super(NixPkgsVersioning.versionRegex);
}
protected override _parse(version: string): RegExpVersion | null {
const groups = this._config?.exec(version)?.groups;
if (!groups) {
return null;
}
const { prefix, major, minor, suffix } = groups;
const release = [];
if (major) {
release.push(Number.parseInt(major, 10));
}
if (minor) {
release.push(Number.parseInt(minor, 10));
}
const compatibility = isNonEmptyStringAndNotWhitespace(suffix)
? `${prefix}-${suffix}`
: prefix;
return {
release,
compatibility,
};
}
override isStable(version: string): boolean {
const parsed = this._parse(version);
return isNonEmptyArray(parsed?.release);
}
protected override _compare(version: string, other: string): number {
const left = this._parse(version);
const right = this._parse(other);
// empty version is equal to 'unstable'
if (isEmptyArray(left?.release) && isEmptyArray(right?.release)) {
return 0;
}
if (isEmptyArray(left?.release)) {
return 1;
}
if (isEmptyArray(right?.release)) {
return -1;
}
return super._compare(version, other);
}
}
export const api: VersioningApiConstructor = NixPkgsVersioning;
export default api;