mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-27 07:50:47 +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>
96 lines
2.7 KiB
TypeScript
96 lines
2.7 KiB
TypeScript
import { isArray, isNonEmptyObject } from '@sindresorhus/is';
|
|
import { HttpBase, type InternalJsonUnsafeOptions } from './http.ts';
|
|
import type { HttpMethod, HttpOptions, HttpResponse } from './types.ts';
|
|
|
|
const MAX_LIMIT = 100;
|
|
const MAX_PAGES = 100;
|
|
|
|
let baseUrl: string;
|
|
export function setBaseUrl(url: string): void {
|
|
baseUrl = url;
|
|
}
|
|
|
|
export interface BitbucketServerHttpOptions extends HttpOptions {
|
|
paginate?: boolean;
|
|
limit?: number;
|
|
maxPages?: number;
|
|
}
|
|
|
|
interface PagedResult<T = unknown> {
|
|
nextPageStart?: number;
|
|
values: T[];
|
|
}
|
|
|
|
export class BitbucketServerHttp extends HttpBase<BitbucketServerHttpOptions> {
|
|
protected override get baseUrl(): string | undefined {
|
|
return baseUrl;
|
|
}
|
|
|
|
constructor(type = 'bitbucket-server', options?: BitbucketServerHttpOptions) {
|
|
super(type, options);
|
|
}
|
|
|
|
protected override extraOptions(): readonly string[] {
|
|
return super
|
|
.extraOptions()
|
|
.concat([
|
|
'paginate',
|
|
'limit',
|
|
'maxPages',
|
|
] as (keyof BitbucketServerHttpOptions)[]);
|
|
}
|
|
|
|
protected override async requestJsonUnsafe<T>(
|
|
method: HttpMethod,
|
|
options: InternalJsonUnsafeOptions<BitbucketServerHttpOptions>,
|
|
): Promise<HttpResponse<T>> {
|
|
const resolvedUrl = this.resolveUrl(options.url, options.httpOptions);
|
|
const opts = { ...options, url: resolvedUrl };
|
|
opts.httpOptions ??= {};
|
|
opts.httpOptions.headers ??= {};
|
|
opts.httpOptions.headers['X-Atlassian-Token'] = 'no-check';
|
|
|
|
const paginate = opts.httpOptions.paginate;
|
|
if (paginate) {
|
|
const limit = opts.httpOptions.limit ?? MAX_LIMIT;
|
|
resolvedUrl.searchParams.set('limit', limit.toString());
|
|
}
|
|
|
|
const result = await super.requestJsonUnsafe<T | PagedResult<T>>(
|
|
method,
|
|
opts,
|
|
);
|
|
|
|
if (paginate && isPagedResult(result.body)) {
|
|
// v8 ignore else -- TODO: add test #40625
|
|
if (opts.httpOptions) {
|
|
delete opts.httpOptions.cacheProvider;
|
|
opts.httpOptions.memCache = false;
|
|
}
|
|
|
|
const collectedValues = [...result.body.values];
|
|
let nextPageStart = result.body.nextPageStart;
|
|
|
|
let maxPages = opts.httpOptions.maxPages ?? MAX_PAGES;
|
|
while (nextPageStart && --maxPages > 0) {
|
|
resolvedUrl.searchParams.set('start', nextPageStart.toString());
|
|
|
|
const nextResult = await super.requestJsonUnsafe<PagedResult<T>>(
|
|
method,
|
|
opts,
|
|
);
|
|
collectedValues.push(...nextResult.body.values);
|
|
nextPageStart = nextResult.body.nextPageStart;
|
|
}
|
|
|
|
return { ...result, body: collectedValues as T };
|
|
}
|
|
|
|
return result as HttpResponse<T>;
|
|
}
|
|
}
|
|
|
|
function isPagedResult(obj: unknown): obj is PagedResult {
|
|
return isNonEmptyObject(obj) && isArray(obj.values);
|
|
}
|