mirror of
https://github.com/renovatebot/renovate.git
synced 2026-11-01 10:09:50 +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>
203 lines
6.6 KiB
TypeScript
203 lines
6.6 KiB
TypeScript
// TODO #22198
|
|
|
|
import { Fixtures } from '~test/fixtures.ts';
|
|
import { fs } from '~test/util.ts';
|
|
import type { PackageDependency, PackageFileContent } from '../types.ts';
|
|
import {
|
|
extractAllPackageFiles,
|
|
extractPackage,
|
|
resolveParents,
|
|
} from './extract.ts';
|
|
import { updateDependency } from './update.ts';
|
|
|
|
vi.mock('../../../util/fs/index.ts');
|
|
|
|
const simpleContent = Fixtures.get('simple.pom.xml');
|
|
const parentPomContent = Fixtures.get('parent.pom.xml');
|
|
const childPomContent = Fixtures.get('child.pom.xml');
|
|
const groupingContent = Fixtures.get('grouping.pom.xml');
|
|
|
|
function selectDep(deps: PackageDependency[], name = 'org.example:quuz') {
|
|
return deps.find((dep) => dep.depName === name);
|
|
}
|
|
|
|
describe('modules/manager/maven/index', () => {
|
|
describe('updateDependency', () => {
|
|
it('should update an existing dependency', () => {
|
|
const newValue = '9.9.9.9-final';
|
|
|
|
const { deps } = extractPackage(simpleContent, 'some-file', {})!;
|
|
const dep = selectDep(deps);
|
|
const updatedContent = updateDependency({
|
|
fileContent: simpleContent,
|
|
packageFile: 'pom.xml',
|
|
upgrade: { ...dep, newValue },
|
|
})!;
|
|
|
|
const updatedDep = selectDep(
|
|
extractPackage(updatedContent, 'some-file', {})!.deps,
|
|
);
|
|
expect(updatedDep?.currentValue).toEqual(newValue);
|
|
});
|
|
|
|
it('should update existing dependency defined via properties', () => {
|
|
const newValue = '9.9.9.9-final';
|
|
|
|
const packages = resolveParents([
|
|
extractPackage(parentPomContent, 'parent.pom.xml', {})!,
|
|
extractPackage(childPomContent, 'child.pom.xml', {})!,
|
|
]);
|
|
const [{ deps }] = packages;
|
|
const dep = selectDep(deps, 'org.example:quux');
|
|
const updatedContent = updateDependency({
|
|
fileContent: parentPomContent,
|
|
packageFile: 'pom.xml',
|
|
upgrade: { ...dep, newValue },
|
|
})!;
|
|
|
|
const [updatedPkg] = resolveParents([
|
|
extractPackage(updatedContent, 'parent.pom.xml', {})!,
|
|
extractPackage(childPomContent, 'child.pom.xml', {})!,
|
|
]);
|
|
const updatedDep = selectDep(updatedPkg.deps, 'org.example:quux');
|
|
expect(updatedDep?.registryUrls).toContain('http://example.com/');
|
|
expect(updatedDep?.currentValue).toEqual(newValue);
|
|
});
|
|
|
|
it('should not touch content if new and old versions are equal', () => {
|
|
const { deps } = extractPackage(simpleContent, 'some-file', {})!;
|
|
const dep = selectDep(deps);
|
|
const updatedContent = updateDependency({
|
|
fileContent: simpleContent,
|
|
packageFile: 'pom.xml',
|
|
upgrade: { ...dep, newValue: '1.2.3' },
|
|
});
|
|
|
|
expect(simpleContent).toBe(updatedContent);
|
|
});
|
|
|
|
it('should update to version of the latest dep in implicit group', async () => {
|
|
fs.readLocalFile.mockResolvedValueOnce(groupingContent);
|
|
const [{ deps }] = await extractAllPackageFiles({}, ['pom.xml']);
|
|
|
|
const dep1 = selectDep(deps, 'org.example:foo-1');
|
|
const upgrade1 = { ...dep1, newValue: '1.0.2' };
|
|
const dep2 = selectDep(deps, 'org.example:foo-2');
|
|
const upgrade2 = { ...dep2, newValue: '1.0.3' };
|
|
const updatedOutside = groupingContent.replace('1.0.0', '1.0.1');
|
|
|
|
expect(
|
|
updateDependency({
|
|
fileContent: groupingContent,
|
|
packageFile: 'pom.xml',
|
|
upgrade: upgrade1,
|
|
}),
|
|
).toEqual(groupingContent.replace('1.0.0', '1.0.2'));
|
|
expect(
|
|
updateDependency({
|
|
fileContent: updatedOutside,
|
|
packageFile: 'pom.xml',
|
|
|
|
upgrade: upgrade1,
|
|
}),
|
|
).toEqual(groupingContent.replace('1.0.0', '1.0.2'));
|
|
|
|
const updatedByPrevious = updateDependency({
|
|
fileContent: groupingContent,
|
|
packageFile: 'pom.xml',
|
|
upgrade: upgrade1,
|
|
})!;
|
|
|
|
expect(
|
|
updateDependency({
|
|
fileContent: updatedByPrevious,
|
|
packageFile: 'pom.xml',
|
|
upgrade: upgrade2,
|
|
}),
|
|
).toEqual(groupingContent.replace('1.0.0', '1.0.3'));
|
|
expect(
|
|
updateDependency({
|
|
fileContent: updatedOutside,
|
|
packageFile: 'pom.xml',
|
|
upgrade: upgrade2,
|
|
}),
|
|
).toEqual(groupingContent.replace('1.0.0', '1.0.3'));
|
|
|
|
expect(
|
|
updateDependency({
|
|
fileContent: groupingContent,
|
|
packageFile: 'pom.xml',
|
|
upgrade: upgrade2,
|
|
}),
|
|
).toEqual(groupingContent.replace('1.0.0', '1.0.3'));
|
|
});
|
|
|
|
it('should return null for ungrouped deps if content was updated outside', async () => {
|
|
fs.readLocalFile.mockResolvedValueOnce(groupingContent);
|
|
const [{ deps }] = await extractAllPackageFiles({}, ['pom.xml']);
|
|
|
|
const dep = selectDep(deps, 'org.example:bar');
|
|
const updatedOutside = groupingContent.replace('2.0.0', '2.0.1');
|
|
|
|
const updatedContent = updateDependency({
|
|
fileContent: updatedOutside,
|
|
packageFile: 'pom.xml',
|
|
upgrade: { ...dep, newValue: '2.0.2' },
|
|
});
|
|
expect(updatedContent).toBeNull();
|
|
});
|
|
|
|
it('should return null if current versions in content and upgrade are not same', () => {
|
|
const { deps } = extractPackage(simpleContent, 'some-file', {})!;
|
|
const dep = selectDep(deps);
|
|
|
|
const updatedContent = updateDependency({
|
|
fileContent: simpleContent,
|
|
packageFile: 'pom.xml',
|
|
upgrade: { ...dep, currentValue: '1.2.2', newValue: '1.2.4' },
|
|
});
|
|
expect(updatedContent).toBeNull();
|
|
});
|
|
|
|
it('should update ranges', () => {
|
|
const newValue = '[1.2.3]';
|
|
function select(depSet: PackageFileContent) {
|
|
return selectDep(depSet.deps, 'org.example:hard-range');
|
|
}
|
|
const oldContent = extractPackage(simpleContent, 'some-file', {});
|
|
const dep = select(oldContent!);
|
|
const newContent = extractPackage(
|
|
updateDependency({
|
|
fileContent: simpleContent,
|
|
packageFile: 'pom.xml',
|
|
upgrade: { ...dep, newValue },
|
|
})!,
|
|
'some-file',
|
|
{},
|
|
);
|
|
const newDep = select(newContent!);
|
|
expect(newDep?.currentValue).toEqual(newValue);
|
|
});
|
|
|
|
it('should preserve ranges', () => {
|
|
function select(depSet: PackageFileContent) {
|
|
return depSet?.deps
|
|
? selectDep(depSet.deps, 'org.example:hard-range')
|
|
: null;
|
|
}
|
|
const oldContent = extractPackage(simpleContent, 'some-file', {});
|
|
const dep = select(oldContent!);
|
|
expect(dep).not.toBeNull();
|
|
|
|
const upgrade = { ...dep, newValue: '[1.0.0]' };
|
|
expect(
|
|
updateDependency({
|
|
fileContent: simpleContent,
|
|
packageFile: 'pom.xml',
|
|
upgrade,
|
|
}),
|
|
).toEqual(simpleContent);
|
|
});
|
|
});
|
|
});
|