mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-27 07:50:47 +00:00
e0cec3dc95
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
70 lines
1.7 KiB
TypeScript
70 lines
1.7 KiB
TypeScript
import { logger } from '../../../logger/index.ts';
|
|
import type { StaticTooling } from '../asdf/types.ts';
|
|
import type { PackageDependency, PackageFileContent } from '../types.ts';
|
|
import { ProtoToolsFile } from './schema.ts';
|
|
import { protoTooling } from './upgradeable-tooling.ts';
|
|
|
|
/**
|
|
* Version aliases that cannot be updated via semver.
|
|
*/
|
|
const versionAliases = new Set(['latest', 'stable', 'canary', 'nightly']);
|
|
|
|
export function extractPackageFile(
|
|
content: string,
|
|
packageFile: string,
|
|
): PackageFileContent | null {
|
|
logger.trace(`proto.extractPackageFile(${packageFile})`);
|
|
|
|
const parsed = ProtoToolsFile.safeParse(content);
|
|
if (!parsed.success) {
|
|
logger.debug(
|
|
{ err: parsed.error, packageFile },
|
|
'Error parsing proto .prototools file.',
|
|
);
|
|
return null;
|
|
}
|
|
|
|
const { versions } = parsed.data;
|
|
const deps: PackageDependency[] = [];
|
|
|
|
for (const [toolName, version] of Object.entries(versions)) {
|
|
deps.push(createDependency(toolName, version));
|
|
}
|
|
|
|
return deps.length ? { deps } : null;
|
|
}
|
|
|
|
function createDependency(name: string, version: string): PackageDependency {
|
|
if (versionAliases.has(version)) {
|
|
return {
|
|
depName: name,
|
|
currentValue: version,
|
|
skipReason: 'unsupported-version',
|
|
};
|
|
}
|
|
|
|
const config = getToolConfig(name);
|
|
if (!config) {
|
|
return {
|
|
depName: name,
|
|
currentValue: version,
|
|
skipReason: 'unsupported-datasource',
|
|
};
|
|
}
|
|
|
|
return {
|
|
depName: name,
|
|
currentValue: version,
|
|
...config,
|
|
};
|
|
}
|
|
|
|
function getToolConfig(toolName: string): StaticTooling | null {
|
|
const toolDefinition = protoTooling[toolName];
|
|
if (!toolDefinition) {
|
|
return null;
|
|
}
|
|
|
|
return toolDefinition.config;
|
|
}
|