Files
renovate/lib/modules/datasource/datasource.ts
T
Sebastian Poxhofer 9717259ffc refactor(oxlint): enable no-else-return and unicorn/no-lonely-if (#44553)
Enable no-else-return (with allowElseIf: false) and unicorn/no-lonely-if
as errors in .oxlintrc.json and fix all 131 pre-existing violations
(91 no-else-return, 40 unicorn/no-lonely-if) across 98 files.

The no-else-return violations were fixed with the oxlint autofix
(iterated to a fixpoint, plus two else-if chains that required
--fix-dangerously) followed by Prettier formatting. One comment dropped
by the autofix in lib/modules/manager/pub/artifacts.ts was restored
manually. The unicorn/no-lonely-if violations were merged by hand,
preserving comments and coverage-ignore hints.

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-14 12:11:21 +00:00

81 lines
1.9 KiB
TypeScript

import { ExternalHostError } from '../../types/errors/external-host-error.ts';
import { Http, HttpError } from '../../util/http/index.ts';
import type {
DatasourceApi,
DigestConfig,
GetReleasesConfig,
PostprocessReleaseConfig,
PostprocessReleaseResult,
RegistryStrategy,
Release,
ReleaseResult,
SourceUrlSupport,
} from './types.ts';
export abstract class Datasource implements DatasourceApi {
public readonly id: string;
protected constructor(id: string) {
this.id = id;
this.http = new Http(id);
}
caching: boolean | undefined;
customRegistrySupport = true;
defaultConfig: Record<string, unknown> | undefined;
defaultRegistryUrls?: string[] | (() => string[]);
defaultVersioning?: string | undefined;
registryStrategy: RegistryStrategy | undefined = 'first';
releaseTimestampSupport = false;
releaseTimestampNote?: string | undefined;
sourceUrlSupport: SourceUrlSupport = 'none';
sourceUrlNote?: string | undefined;
protected http: Http;
abstract getReleases(
getReleasesConfig: GetReleasesConfig,
): Promise<ReleaseResult | null>;
getDigest?(config: DigestConfig, newValue?: string): Promise<string | null>;
handleHttpErrors(_err: HttpError): void {
// intentionally empty
}
protected handleGenericErrors(err: Error): never {
if (err instanceof ExternalHostError) {
throw err;
}
if (err instanceof HttpError) {
this.handleHttpErrors(err);
const statusCode = err.response?.statusCode;
if (
statusCode &&
(statusCode === 429 || (statusCode >= 500 && statusCode < 600))
) {
throw new ExternalHostError(err);
}
}
throw err;
}
// istanbul ignore next: no-op implementation, never called
postprocessRelease(
_config: PostprocessReleaseConfig,
release: Release,
): Promise<PostprocessReleaseResult> {
return Promise.resolve(release);
}
}