mirror of
https://github.com/renovatebot/renovate.git
synced 2026-11-03 11:03:39 +00:00
58771bb183
* refactor(oxlint): enable func-style Enable the built-in func-style rule as ["warn", "declaration"] so that named functions are written as function declarations instead of arrow or function expressions assigned to variables, matching the convention in docs/development/best-practices.md (Functions section). Inline arrow callbacks are unaffected; prefer-arrow-callback continues to cover the callback direction. Severity is "warn" instead of "error" as a fallback: a repo-wide run found 196 pre-existing violations (70 in spec files, 126 in production code), exceeding the 80-violation fix threshold for this change, so no violations were fixed here. Follow-up work can convert the offenders (largest clusters: lib/modules/versioning/ruby, lib/util/cache/package, lib/modules/versioning/maven, lib/modules/versioning/gradle) and then raise the rule to "error". Note oxlint 1.72 also supports an allowTypeAnnotation option if typed consts should remain arrows. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * ci(linter): enforce func-style at error * refactor(func-style): convert const-arrow functions to declarations in with-cache spec and ruby versioning * refactor(func-style): convert const-arrow functions to declarations in maven/gradle modules * refactor(func-style): convert const-arrow functions to declarations in remaining versioning modules * refactor(func-style): convert const-arrow functions to declarations in platform modules Discriminated-union closures (ensureCommentRemoval byTopic/byContent helpers in github, gitlab, bitbucket, bitbucket-server) needed the narrowed field passed explicitly as a parameter, since function declarations are hoisted and lose the outer if-narrowing that inline arrow-function closures previously relied on. * refactor(func-style): convert const-arrow functions to declarations across util/manager/datasource modules One case (logger/renovate-logger.ts logOnceFn) is kept as an arrow function with a documented oxlint-disable: it is stored on this.logger.once[level] and relies on lexically-bound this, which a hoisted function declaration would not preserve. * refactor(func-style): convert remaining const-arrow test helpers to declarations get-updated.spec.ts: hoisted expectPipCompilePackageAndLockFile to module scope (it only closes over the module-level pipCompile mock) and added a documented oxlint-disable for vitest/expect-expect on its caller test, since oxlint's expect-expect check does not trace assertions through an externally-defined helper function. --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
110 lines
2.6 KiB
TypeScript
110 lines
2.6 KiB
TypeScript
import * as pep440 from '@renovatebot/pep440';
|
|
import type { RangeStrategy } from '../../../types/versioning.ts';
|
|
import type { VersioningApi } from '../types.ts';
|
|
import { getNewValue, getPinnedValue, isLessThanRange } from './range.ts';
|
|
|
|
export const id = 'pep440';
|
|
export const displayName = 'PEP440';
|
|
export const urls = [
|
|
'[PEP 440 - Version Identification](https://www.python.org/dev/peps/pep-0440/)',
|
|
];
|
|
export const supportsRanges = true;
|
|
export const supportedRangeStrategies: RangeStrategy[] = [
|
|
'bump',
|
|
'widen',
|
|
'replace',
|
|
];
|
|
|
|
const {
|
|
compare: sortVersions,
|
|
satisfies,
|
|
valid,
|
|
validRange,
|
|
explain,
|
|
gt: isGreaterThan,
|
|
major: getMajor,
|
|
minor: getMinor,
|
|
patch: getPatch,
|
|
eq,
|
|
} = pep440;
|
|
|
|
function isVersion(input: string | undefined | null): boolean {
|
|
// @renovatebot/pep440 isn't strict null save
|
|
// oxlint-disable-next-line typescript/no-unnecessary-type-assertion
|
|
return !!valid(input!);
|
|
}
|
|
|
|
function isStable(input: string): boolean {
|
|
const version = explain(input);
|
|
if (!version) {
|
|
return false;
|
|
}
|
|
return !version.is_prerelease;
|
|
}
|
|
|
|
// If this is left as an alias, inputs like "17.04.0" throw errors
|
|
export function isValid(input: string): boolean {
|
|
return validRange(input) || isVersion(input);
|
|
}
|
|
|
|
function getSatisfyingVersion(
|
|
versions: string[],
|
|
range: string,
|
|
): string | null {
|
|
const found = pep440.filter(versions, range).sort(sortVersions);
|
|
return found.length === 0 ? null : found.at(-1)!;
|
|
}
|
|
|
|
function minSatisfyingVersion(
|
|
versions: string[],
|
|
range: string,
|
|
): string | null {
|
|
const found = pep440.filter(versions, range).sort(sortVersions);
|
|
return found.length === 0 ? null : found[0];
|
|
}
|
|
|
|
export function isSingleVersion(constraint: string): boolean {
|
|
return (
|
|
isVersion(constraint) ||
|
|
(constraint?.startsWith('==') && isVersion(constraint.substring(2).trim()))
|
|
);
|
|
}
|
|
|
|
export { isVersion, matches };
|
|
|
|
function equals(version1: string, version2: string): boolean {
|
|
return isVersion(version1) && isVersion(version2) && eq(version1, version2);
|
|
}
|
|
|
|
function matches(version: string, range: string): boolean {
|
|
if (!isVersion(version)) {
|
|
return false;
|
|
}
|
|
if (isVersion(range)) {
|
|
return equals(version, range);
|
|
}
|
|
return isValid(range) && satisfies(version, range, { prereleases: true });
|
|
}
|
|
|
|
export const api: VersioningApi = {
|
|
equals,
|
|
getMajor,
|
|
getMinor,
|
|
getPatch,
|
|
isCompatible: isVersion,
|
|
isGreaterThan,
|
|
isSingleVersion,
|
|
isStable,
|
|
isValid,
|
|
isVersion,
|
|
matches,
|
|
getSatisfyingVersion,
|
|
minSatisfyingVersion,
|
|
getNewValue,
|
|
getPinnedValue,
|
|
sortVersions,
|
|
isLessThanRange,
|
|
};
|
|
|
|
export default api;
|