Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix types for linting #26695

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/modules/datasource/conan/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ export class ConanDatasource extends Datasource {
const res = await this.githubHttp.get(url, {
headers: { accept: 'application/vnd.github.v3.raw' },
});
const doc = parseSingleYaml(res.body, {
// TODO: use schema (#9610)
const doc = parseSingleYaml<ConanYAML>(res.body, {
json: true,
}) as ConanYAML;
});
return {
releases: Object.keys(doc?.versions ?? {}).map((version) => ({
version,
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/datasource/helm/common.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { findSourceUrl } from './common';
import type { HelmRepository } from './types';

// Truncated index.yaml file
const repo = parseSingleYaml(Fixtures.get('sample.yaml'), {
const repo = parseSingleYaml<HelmRepository>(Fixtures.get('sample.yaml'), {
json: true,
}) as HelmRepository;
});

describe('modules/datasource/helm/common', () => {
describe('findSourceUrl', () => {
Expand Down
5 changes: 3 additions & 2 deletions lib/modules/datasource/helm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ export class HelmDatasource extends Datasource {
this.handleGenericErrors(err);
}
try {
const doc = parseSingleYaml(res.body, {
// TODO: use schema (#9610)
const doc = parseSingleYaml<HelmRepository>(res.body, {
json: true,
}) as HelmRepository;
});
if (!is.plainObject<HelmRepository>(doc)) {
logger.warn(
{ helmRepository },
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/manager/argocd/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export function extractPackageFile(

let definitions: ApplicationDefinition[];
try {
definitions = parseYaml(content) as ApplicationDefinition[];
// TODO: use schema (#9610)
definitions = parseYaml(content);
} catch (err) {
logger.debug({ err, packageFile }, 'Failed to parse ArgoCD definition.');
return null;
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/manager/docker-compose/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export function extractPackageFile(
logger.debug(`docker-compose.extractPackageFile(${packageFile})`);
let config: DockerComposeConfig;
try {
// TODO: fix me (#9610)
config = parseSingleYaml(content, { json: true }) as DockerComposeConfig;
// TODO: use schema (#9610)
config = parseSingleYaml(content, { json: true });
if (!config) {
logger.debug(
{ packageFile },
Expand Down
12 changes: 8 additions & 4 deletions lib/modules/manager/fleet/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,20 @@ export function extractPackageFile(

try {
if (regEx('fleet.ya?ml').test(packageFile)) {
// TODO: fix me (#9610)
const docs = parseYaml(content, null, { json: true }) as FleetFile[];
// TODO: use schema (#9610)
const docs = parseYaml<FleetFile>(content, null, {
json: true,
});
const fleetDeps = docs
.filter((doc) => is.truthy(doc?.helm))
.flatMap((doc) => extractFleetFile(doc));

deps.push(...fleetDeps);
} else {
// TODO: fix me (#9610)
const docs = parseYaml(content, null, { json: true }) as GitRepo[];
// TODO: use schema (#9610)
const docs = parseYaml<GitRepo>(content, null, {
json: true,
});
const gitRepoDeps = docs
.filter((doc) => doc.kind === 'GitRepo') // ensure only GitRepo manifests are processed
.flatMap((doc) => extractGitRepo(doc));
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/manager/flux/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ function readManifest(
};
let resources: FluxResource[];
try {
resources = parseYaml(content, null, { json: true }) as FluxResource[];
// TODO: use schema (#9610)
resources = parseYaml(content, null, { json: true });
} catch (err) {
logger.debug({ err, packageFile }, 'Failed to parse Flux manifest');
return null;
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/manager/github-actions/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ function extractWithYAMLParser(

let pkg: Workflow;
try {
pkg = parseSingleYaml(content, { json: true }) as Workflow;
// TODO: use schema (#9610)
pkg = parseSingleYaml(content, { json: true });
} catch (err) {
logger.debug(
{ packageFile, err },
Expand Down
5 changes: 3 additions & 2 deletions lib/modules/manager/gitlabci-include/common.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import {
} from './common';

const yamlFileMultiConfig = Fixtures.get('gitlab-ci.1.yaml');
const pipeline = parseSingleYaml(
// TODO: use schema (#9610)
const pipeline = parseSingleYaml<GitlabPipeline>(
replaceReferenceTags(yamlFileMultiConfig),
) as GitlabPipeline;
);
const includeLocal = { local: 'something' };
const includeProject = { project: 'something' };

Expand Down
5 changes: 3 additions & 2 deletions lib/modules/manager/gitlabci-include/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ export function extractPackageFile(
const platform = GlobalConfig.get('platform');
const endpoint = GlobalConfig.get('endpoint');
try {
const doc = parseSingleYaml(replaceReferenceTags(content), {
// TODO: use schema (#9610)
const doc = parseSingleYaml<GitlabPipeline>(replaceReferenceTags(content), {
json: true,
}) as GitlabPipeline;
});
const includes = getAllIncludeProjects(doc);
for (const includeObj of includes) {
const dep = extractDepFromIncludeFile(includeObj);
Expand Down
6 changes: 4 additions & 2 deletions lib/modules/manager/gitlabci/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ export function extractPackageFile(
): PackageFileContent | null {
let deps: PackageDependency[] = [];
try {
// TODO: use schema (#9610)
const doc = parseSingleYaml(replaceReferenceTags(content), {
json: true,
}) as Record<string, Image | Services | Job>;
});
if (is.object(doc)) {
for (const [property, value] of Object.entries(doc)) {
switch (property) {
Expand Down Expand Up @@ -146,9 +147,10 @@ export async function extractAllPackageFiles(
}
let doc: GitlabPipeline;
try {
// TODO: use schema (#9610)
doc = parseSingleYaml(replaceReferenceTags(content), {
json: true,
}) as GitlabPipeline;
});
} catch (err) {
logger.debug(
{ err, packageFile: file },
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/manager/helmfile/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ export async function extractPackageFile(
// Record kustomization usage for all deps, since updating artifacts is run on the helmfile.yaml as a whole.
let needKustomize = false;
try {
// TODO: use schema (#9610)
docs = parseYaml(content, null, {
removeTemplates: true,
json: true,
}) as Doc[];
});
} catch (err) {
logger.debug(
{ err, packageFile },
Expand Down
6 changes: 3 additions & 3 deletions lib/modules/manager/helmsman/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ export function extractPackageFile(
_config: ExtractConfig,
): PackageFileContent | null {
try {
// TODO: fix me (#9610)
const doc = parseSingleYaml(content, {
// TODO: use schema (#9610)
const doc = parseSingleYaml<HelmsmanDocument>(content, {
json: true,
}) as HelmsmanDocument;
});
if (!doc.apps) {
logger.debug({ packageFile }, `Missing apps keys`);
return null;
Expand Down
9 changes: 5 additions & 4 deletions lib/modules/manager/helmv3/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,13 @@ export async function updateArtifacts({
}
try {
// get repositories and registries defined in the package file
const packages = yaml.parseSingleYaml(
// TODO: use schema (#9610)
const packages = yaml.parseSingleYaml<ChartDefinition>(
newPackageFileContent,
) as ChartDefinition; //TODO #9610
);
const locks = existingLockFileContent
? (yaml.parseSingleYaml(existingLockFileContent) as ChartDefinition)
: { dependencies: [] }; //TODO #9610
? yaml.parseSingleYaml<ChartDefinition>(existingLockFileContent)
: { dependencies: [] };

const chartDefinitions: ChartDefinition[] = [];
// prioritize registryAlias naming for Helm repositories
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/manager/helmv3/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export async function extractPackageFile(
dependencies: Array<{ name: string; version: string; repository: string }>;
};
try {
// TODO: fix me (#9610)
chart = parseSingleYaml(content, { json: true }) as any;
// TODO: use schema (#9610)
chart = parseSingleYaml(content, { json: true });
if (!(chart?.apiVersion && chart.name && chart.version)) {
logger.debug(
{ packageFile },
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/manager/jenkins/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ function extractYaml(
const deps: PackageDependency[] = [];

try {
const doc = parseSingleYaml(content, { json: true }) as JenkinsPlugins;
// TODO: use schema (#9610)
const doc = parseSingleYaml<JenkinsPlugins>(content, { json: true });
if (is.nonEmptyArray(doc?.plugins)) {
for (const plugin of doc.plugins) {
if (plugin.artifactId) {
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/manager/kubernetes/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ function extractApis(
let doc: KubernetesConfiguration[];

try {
doc = parseYaml(content) as KubernetesConfiguration[];
// TODO: use schema (#9610)
doc = parseYaml(content);
} catch (err) {
logger.debug({ err, packageFile }, 'Failed to parse Kubernetes manifest.');
return [];
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/manager/kustomize/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ export function parseKustomize(
): Kustomize | null {
let pkg: Kustomize | null = null;
try {
pkg = parseSingleYaml(content, { json: true }) as Kustomize;
// TODO: use schema (#9610)
pkg = parseSingleYaml(content, { json: true });
} catch (e) /* istanbul ignore next */ {
logger.debug({ packageFile }, 'Error parsing kustomize file');
return null;
Expand Down
11 changes: 7 additions & 4 deletions lib/modules/manager/npm/extract/pnpm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ export async function extractPnpmFilters(
fileName: string,
): Promise<string[] | undefined> {
try {
// TODO #22198
const contents = parseSingleYaml((await readLocalFile(fileName, 'utf8'))!, {
json: true,
}) as PnpmWorkspaceFile;
// TODO: use schema (#9610,#22198)
const contents = parseSingleYaml<PnpmWorkspaceFile>(
(await readLocalFile(fileName, 'utf8'))!,
{
json: true,
},
);
if (
!Array.isArray(contents.packages) ||
!contents.packages.every((item) => is.string(item))
Expand Down
11 changes: 6 additions & 5 deletions lib/modules/manager/npm/post-update/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,9 @@ export async function updateYarnBinary(
return existingYarnrcYmlContent;
}

const oldYarnPath = (parseSingleYaml(yarnrcYml) as YarnRcYmlFile)?.yarnPath;
const newYarnPath = (parseSingleYaml(newYarnrcYml) as YarnRcYmlFile)
?.yarnPath;
// TODO: use schema (#9610)
const oldYarnPath = parseSingleYaml<YarnRcYmlFile>(yarnrcYml)?.yarnPath;
const newYarnPath = parseSingleYaml<YarnRcYmlFile>(newYarnrcYml)?.yarnPath;
if (
!is.nonEmptyStringAndNotWhitespace(oldYarnPath) ||
!is.nonEmptyStringAndNotWhitespace(newYarnPath)
Expand Down Expand Up @@ -569,9 +569,10 @@ export async function getAdditionalFiles(
existingYarnrcYmlContent = await readLocalFile(yarnRcYmlFilename, 'utf8');
if (existingYarnrcYmlContent) {
try {
const existingYarnrRcYml = parseSingleYaml(
// TODO: use schema (#9610)
const existingYarnrRcYml = parseSingleYaml<Record<string, unknown>>(
existingYarnrcYmlContent,
) as Record<string, unknown>;
);
const updatedYarnYrcYml = deepmerge(
existingYarnrRcYml,
additionalYarnRcYml,
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/manager/npm/post-update/pnpm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ export async function getConstraintFromLockFile(
if (!lockfileContent) {
return null;
}
const pnpmLock = parseSingleYaml(lockfileContent) as PnpmLockFile;
// TODO: use schema (#9610)
const pnpmLock = parseSingleYaml<PnpmLockFile>(lockfileContent);
if (!is.number(pnpmLock?.lockfileVersion)) {
return null;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/manager/pre-commit/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ export function extractPackageFile(
type ParsedContent = Record<string, unknown> | PreCommitConfig;
let parsedContent: ParsedContent;
try {
parsedContent = parseSingleYaml(content, { json: true }) as ParsedContent;
// TODO: use schema (#9610)
parsedContent = parseSingleYaml(content, { json: true });
} catch (err) {
logger.debug(
{ filename: packageFile, err },
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/manager/tekton/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export function extractPackageFile(
const deps: PackageDependency[] = [];
let docs: TektonResource[];
try {
docs = parseYaml(content) as TektonResource[];
// TODO: use schema (#9610)
docs = parseYaml(content);
} catch (err) {
logger.debug(
{ err, packageFile },
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/manager/travis/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ export function extractPackageFile(
): PackageFileContent | null {
let doc: TravisYaml;
try {
// TODO: use schema (#9610)
doc = parseSingleYaml(content, {
json: true,
}) as TravisYaml;
});
} catch (err) {
logger.debug({ err, packageFile }, 'Failed to parse .travis.yml file.');
return null;
Expand Down
5 changes: 3 additions & 2 deletions lib/modules/manager/velaci/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ export function extractPackageFile(
file: string,
packageFile?: string,
): PackageFileContent | null {
let doc: VelaPipelineConfiguration | undefined;
let doc: VelaPipelineConfiguration;

try {
doc = parseSingleYaml(file, { json: true }) as VelaPipelineConfiguration;
// TODO: use schema (#9610)
doc = parseSingleYaml(file, { json: true });
} catch (err) {
logger.debug({ err, packageFile }, 'Failed to parse Vela file.');
return null;
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/manager/woodpecker/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export function extractPackageFile(
logger.debug('woodpecker.extractPackageFile()');
let config: WoodpeckerConfig;
try {
// TODO: fix me (#9610)
config = parseSingleYaml(content, { json: true }) as WoodpeckerConfig;
// TODO: use schema (#9610)
config = parseSingleYaml(content, { json: true });
if (!config) {
logger.debug(
{ packageFile },
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/global/config/parse/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function getParsedContent(file: string): Promise<RenovateConfig> {
case '.yml':
return parseSingleYaml(await readSystemFile(file, 'utf8'), {
json: true,
}) as RenovateConfig;
});
case '.json5':
case '.json':
return parseJson(
Expand Down