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

56 lines
1.3 KiB
TypeScript

import { isNonEmptyStringAndNotWhitespace } from '@sindresorhus/is';
import { logger } from '../../../logger/index.ts';
import type { PackageDependency } from '../types.ts';
export const validMatchFields = [
'depName',
'packageName',
'currentValue',
'currentDigest',
'datasource',
'versioning',
'extractVersion',
'registryUrl',
'depType',
'indentation',
] as const;
export function isValidDependency({
depName,
currentValue,
currentDigest,
packageName,
datasource,
}: PackageDependency): boolean {
// check if all the fields are set
return (
(isNonEmptyStringAndNotWhitespace(depName) ||
isNonEmptyStringAndNotWhitespace(packageName)) &&
(isNonEmptyStringAndNotWhitespace(currentDigest) ||
isNonEmptyStringAndNotWhitespace(currentValue)) &&
isNonEmptyStringAndNotWhitespace(datasource)
);
}
export function checkIsValidDependency(
dep: PackageDependency,
packageFile: string,
manager: string,
): boolean {
const isValid = isValidDependency(dep);
if (!isValid) {
const meta = {
packageDependency: dep,
packageFile,
manager,
};
logger.trace(
meta,
'Discovered a package dependency, but it did not pass validation. Discarding',
);
return isValid;
}
return isValid;
}