mirror of
https://github.com/renovatebot/renovate.git
synced 2026-11-01 18:19:51 +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>
188 lines
4.1 KiB
TypeScript
188 lines
4.1 KiB
TypeScript
import type { RangeStrategy } from '../../../types/versioning.ts';
|
|
import { coerceString } from '../../../util/string.ts';
|
|
import type { NewValueConfig, VersioningApi } from '../types.ts';
|
|
import {
|
|
EXCLUDING_POINT,
|
|
QualifierTypes,
|
|
TYPE_NUMBER,
|
|
TYPE_QUALIFIER,
|
|
autoExtendMavenRange,
|
|
compare,
|
|
isSingleVersion,
|
|
isValid,
|
|
isVersion,
|
|
parseRange,
|
|
qualifierType,
|
|
tokenize,
|
|
} from './compare.ts';
|
|
|
|
export const id = 'maven';
|
|
export const displayName = 'Maven';
|
|
export const urls = [
|
|
'[Maven POM - Dependency version requirements](https://maven.apache.org/pom.html#Dependency_Version_Requirement_Specification)',
|
|
'[Maven versioning explained](https://octopus.com/blog/maven-versioning-explained)',
|
|
'[Maven Enforcer - Version ranges](https://maven.apache.org/enforcer/enforcer-rules/versionRanges.html)',
|
|
];
|
|
export const supportsRanges = true;
|
|
export const supportedRangeStrategies: RangeStrategy[] = [
|
|
'bump',
|
|
'widen',
|
|
'pin',
|
|
'replace',
|
|
];
|
|
|
|
function equals(a: string, b: string): boolean {
|
|
return compare(a, b) === 0;
|
|
}
|
|
|
|
function matches(a: string, b: string): boolean {
|
|
if (!b) {
|
|
return false;
|
|
}
|
|
if (isVersion(b)) {
|
|
return equals(a, b);
|
|
}
|
|
const ranges = parseRange(b);
|
|
if (!ranges) {
|
|
return false;
|
|
}
|
|
return ranges.reduce((result, range): any => {
|
|
if (result) {
|
|
return result;
|
|
}
|
|
|
|
const { leftType, leftValue, rightType, rightValue } = range;
|
|
|
|
let leftResult = true;
|
|
let rightResult = true;
|
|
|
|
if (leftValue) {
|
|
leftResult =
|
|
leftType === EXCLUDING_POINT
|
|
? compare(leftValue, a) === -1
|
|
: compare(leftValue, a) !== 1;
|
|
}
|
|
|
|
if (rightValue) {
|
|
rightResult =
|
|
rightType === EXCLUDING_POINT
|
|
? compare(a, rightValue) === -1
|
|
: compare(a, rightValue) !== 1;
|
|
}
|
|
|
|
return leftResult && rightResult;
|
|
}, false);
|
|
}
|
|
|
|
function getMajor(version: string): number | null {
|
|
if (isVersion(version)) {
|
|
const tokens = tokenize(version);
|
|
const majorToken = tokens[0];
|
|
return +majorToken.val;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function getMinor(version: string): number | null {
|
|
if (isVersion(version)) {
|
|
const tokens = tokenize(version);
|
|
const minorToken = tokens[1];
|
|
if (minorToken?.type === TYPE_NUMBER) {
|
|
return +minorToken.val;
|
|
}
|
|
return 0;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function getPatch(version: string): number | null {
|
|
if (isVersion(version)) {
|
|
const tokens = tokenize(version);
|
|
const minorToken = tokens[1];
|
|
const patchToken = tokens[2];
|
|
if (
|
|
patchToken &&
|
|
minorToken.type === TYPE_NUMBER &&
|
|
patchToken.type === TYPE_NUMBER
|
|
) {
|
|
return +patchToken.val;
|
|
}
|
|
return 0;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function isGreaterThan(a: string, b: string): boolean {
|
|
return compare(a, b) === 1;
|
|
}
|
|
|
|
function isStable(version: string): boolean {
|
|
if (isVersion(version)) {
|
|
const tokens = tokenize(version);
|
|
for (const token of tokens) {
|
|
if (token.type === TYPE_QUALIFIER) {
|
|
const qualType = qualifierType(token);
|
|
if (qualType && qualType < QualifierTypes.Release) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// istanbul ignore next
|
|
function getSatisfyingVersion(
|
|
versions: string[],
|
|
range: string,
|
|
): string | null {
|
|
return versions.reduce((result: string | null, version) => {
|
|
if (matches(version, range)) {
|
|
if (!result) {
|
|
return version;
|
|
}
|
|
if (isGreaterThan(version, result)) {
|
|
return version;
|
|
}
|
|
}
|
|
return result;
|
|
}, null);
|
|
}
|
|
|
|
function getNewValue({
|
|
currentValue,
|
|
rangeStrategy,
|
|
newVersion,
|
|
}: NewValueConfig): string {
|
|
if (isVersion(currentValue) || rangeStrategy === 'pin') {
|
|
return newVersion;
|
|
}
|
|
return coerceString(
|
|
autoExtendMavenRange(currentValue, newVersion),
|
|
currentValue,
|
|
);
|
|
}
|
|
|
|
export { isValid };
|
|
|
|
export const api: VersioningApi = {
|
|
equals,
|
|
getMajor,
|
|
getMinor,
|
|
getPatch,
|
|
isCompatible: isVersion,
|
|
isGreaterThan,
|
|
isSingleVersion,
|
|
isStable,
|
|
isValid,
|
|
isVersion,
|
|
matches,
|
|
getSatisfyingVersion,
|
|
minSatisfyingVersion: getSatisfyingVersion,
|
|
getNewValue,
|
|
sortVersions: compare,
|
|
};
|
|
|
|
export default api;
|