From 0a582d31c7bc72414cebb75471aea9f7489d0acd Mon Sep 17 00:00:00 2001
From: Michael Kriese <michael.kriese@visualon.de>
Date: Mon, 20 Jun 2022 18:15:40 +0200
Subject: [PATCH] refactor: fix nullable types (#16156)

* refactor: fix nullable types

* chore: revert changes

* chore: fix lint comments

* chore: revert changes
---
 lib/modules/manager/batect/extract.ts         |  4 ++-
 lib/modules/manager/bundler/artifacts.spec.ts | 14 ++++----
 lib/modules/manager/flux/extract.ts           |  6 ++--
 lib/modules/manager/gomod/artifacts.ts        |  3 +-
 lib/modules/manager/gradle/extract.ts         |  5 +--
 .../manager/jsonnet-bundler/artifacts.ts      | 12 +++++--
 lib/modules/manager/mix/artifacts.ts          |  2 +-
 lib/modules/manager/npm/extract/index.ts      |  7 ++--
 lib/modules/manager/npm/extract/npm.ts        |  3 +-
 lib/modules/manager/npm/extract/pnpm.ts       |  3 +-
 lib/modules/manager/npm/extract/yarn.ts       |  3 +-
 lib/modules/manager/npm/post-update/index.ts  | 34 ++++++++++++-------
 .../manager/npm/post-update/node-version.ts   |  7 ++--
 lib/modules/manager/npm/post-update/npm.ts    |  6 +++-
 lib/modules/manager/nuget/package-tree.ts     |  4 ++-
 lib/modules/manager/nuget/util.ts             |  3 +-
 lib/modules/manager/poetry/artifacts.ts       |  4 +--
 lib/modules/manager/poetry/extract.ts         |  5 +--
 .../manager/terraform/lockfile/util.ts        |  2 +-
 lib/util/fs/index.ts                          |  5 ++-
 lib/util/git/types.ts                         |  2 +-
 .../config-migration/branch/migrated-data.ts  |  4 ++-
 lib/workers/repository/init/merge.ts          | 16 +++++----
 .../repository/onboarding/branch/check.ts     |  3 +-
 .../branch/execute-post-upgrade-commands.ts   |  5 +--
 .../repository/update/branch/get-updated.ts   |  6 ++--
 26 files changed, 107 insertions(+), 61 deletions(-)

diff --git a/lib/modules/manager/batect/extract.ts b/lib/modules/manager/batect/extract.ts
index 7e2e587aa1..4b957d12ea 100644
--- a/lib/modules/manager/batect/extract.ts
+++ b/lib/modules/manager/batect/extract.ts
@@ -160,7 +160,9 @@ export async function extractAllPackageFiles(
     filesAlreadyExamined.add(packageFile);
 
     const content = await readLocalFile(packageFile, 'utf8');
-    const result = extractPackageFile(content, packageFile);
+    // TODO #7154
+    // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
+    const result = extractPackageFile(content!, packageFile);
 
     if (result !== null) {
       result.referencedConfigFiles.forEach((f) => {
diff --git a/lib/modules/manager/bundler/artifacts.spec.ts b/lib/modules/manager/bundler/artifacts.spec.ts
index 1e37781a2c..47807c32bb 100644
--- a/lib/modules/manager/bundler/artifacts.spec.ts
+++ b/lib/modules/manager/bundler/artifacts.spec.ts
@@ -70,7 +70,7 @@ describe('modules/manager/bundler/artifacts', () => {
 
   it('returns null if Gemfile.lock was not changed', async () => {
     fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock');
-    fs.writeLocalFile.mockResolvedValueOnce(null as never);
+    fs.writeLocalFile.mockResolvedValueOnce();
     const execSnapshots = mockExecAll(exec);
     git.getRepoStatus.mockResolvedValueOnce({
       modified: [] as string[],
@@ -89,13 +89,13 @@ describe('modules/manager/bundler/artifacts', () => {
 
   it('works for default binarySource', async () => {
     fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock');
-    fs.writeLocalFile.mockResolvedValueOnce(null as never);
-    fs.readLocalFile.mockResolvedValueOnce(null as never);
+    fs.writeLocalFile.mockResolvedValueOnce();
+    fs.readLocalFile.mockResolvedValueOnce(null);
     const execSnapshots = mockExecAll(exec);
     git.getRepoStatus.mockResolvedValueOnce({
       modified: ['Gemfile.lock'],
     } as StatusResult);
-    fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
+    fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock');
     expect(
       await updateArtifacts({
         packageFileName: 'Gemfile',
@@ -110,13 +110,13 @@ describe('modules/manager/bundler/artifacts', () => {
   it('works explicit global binarySource', async () => {
     GlobalConfig.set({ ...adminConfig, binarySource: 'global' });
     fs.readLocalFile.mockResolvedValueOnce('Current Gemfile.lock');
-    fs.writeLocalFile.mockResolvedValueOnce(null as never);
-    fs.readLocalFile.mockResolvedValueOnce(null as never);
+    fs.writeLocalFile.mockResolvedValueOnce();
+    fs.readLocalFile.mockResolvedValueOnce(null);
     const execSnapshots = mockExecAll(exec);
     git.getRepoStatus.mockResolvedValueOnce({
       modified: ['Gemfile.lock'],
     } as StatusResult);
-    fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock' as any);
+    fs.readLocalFile.mockResolvedValueOnce('Updated Gemfile.lock');
     expect(
       await updateArtifacts({
         packageFileName: 'Gemfile',
diff --git a/lib/modules/manager/flux/extract.ts b/lib/modules/manager/flux/extract.ts
index 8c2bee7494..52f0ec7eb3 100644
--- a/lib/modules/manager/flux/extract.ts
+++ b/lib/modules/manager/flux/extract.ts
@@ -102,7 +102,7 @@ function resolveManifest(
             rep.kind === release.spec.chart.spec.sourceRef?.kind &&
             rep.metadata.name === release.spec.chart.spec.sourceRef.name &&
             rep.metadata.namespace ===
-              (release.spec.chart.spec.sourceRef.namespace ||
+              (release.spec.chart.spec.sourceRef.namespace ??
                 release.metadata?.namespace)
         );
         if (matchingRepositories.length) {
@@ -140,7 +140,9 @@ export async function extractAllPackageFiles(
 
   for (const file of packageFiles) {
     const content = await readLocalFile(file, 'utf8');
-    const manifest = readManifest(content, file);
+    // TODO #7154
+    // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
+    const manifest = readManifest(content!, file);
     if (manifest) {
       manifests.push(manifest);
     }
diff --git a/lib/modules/manager/gomod/artifacts.ts b/lib/modules/manager/gomod/artifacts.ts
index f75349ef61..c1dd715184 100644
--- a/lib/modules/manager/gomod/artifacts.ts
+++ b/lib/modules/manager/gomod/artifacts.ts
@@ -351,7 +351,8 @@ export async function updateArtifacts({
       }
     }
 
-    const finalGoModContent = (await readLocalFile(goModFileName, 'utf8'))
+    // TODO #7154
+    const finalGoModContent = (await readLocalFile(goModFileName, 'utf8'))!
       .replace(regEx(/\/\/ renovate-replace /g), '')
       .replace(regEx(/renovate-replace-bracket/g), ')');
     if (finalGoModContent !== newGoModContent) {
diff --git a/lib/modules/manager/gradle/extract.ts b/lib/modules/manager/gradle/extract.ts
index 68822666dc..5078b6af86 100644
--- a/lib/modules/manager/gradle/extract.ts
+++ b/lib/modules/manager/gradle/extract.ts
@@ -52,7 +52,8 @@ export async function extractAllPackageFiles(
     };
 
     try {
-      const content = await readLocalFile(packageFile, 'utf8');
+      // TODO #7154
+      const content = (await readLocalFile(packageFile, 'utf8'))!;
       const dir = upath.dirname(toAbsolutePath(packageFile));
 
       const updateVars = (newVars: PackageVariables): void => {
@@ -106,7 +107,7 @@ export async function extractAllPackageFiles(
         registryUrls: [
           ...new Set([
             ...defaultRegistryUrls,
-            ...(dep.registryUrls || []),
+            ...(dep.registryUrls ?? []),
             ...registryUrls,
           ]),
         ],
diff --git a/lib/modules/manager/jsonnet-bundler/artifacts.ts b/lib/modules/manager/jsonnet-bundler/artifacts.ts
index 8a7346cd7e..703347bba2 100644
--- a/lib/modules/manager/jsonnet-bundler/artifacts.ts
+++ b/lib/modules/manager/jsonnet-bundler/artifacts.ts
@@ -71,12 +71,20 @@ export async function updateArtifacts(
 
     for (const f of status.modified ?? []) {
       res.push({
-        file: { type: 'addition', path: f, contents: await readLocalFile(f) },
+        file: {
+          type: 'addition',
+          path: f,
+          contents: await readLocalFile(f),
+        },
       });
     }
     for (const f of status.not_added ?? []) {
       res.push({
-        file: { type: 'addition', path: f, contents: await readLocalFile(f) },
+        file: {
+          type: 'addition',
+          path: f,
+          contents: await readLocalFile(f),
+        },
       });
     }
     for (const f of status.deleted ?? []) {
diff --git a/lib/modules/manager/mix/artifacts.ts b/lib/modules/manager/mix/artifacts.ts
index 9e5298130d..0eb2e6d303 100644
--- a/lib/modules/manager/mix/artifacts.ts
+++ b/lib/modules/manager/mix/artifacts.ts
@@ -27,7 +27,7 @@ export async function updateArtifacts({
   }
 
   const lockFileName =
-    (await findLocalSiblingOrParent(packageFileName, 'mix.lock')) || 'mix.lock';
+    (await findLocalSiblingOrParent(packageFileName, 'mix.lock')) ?? 'mix.lock';
   try {
     await writeLocalFile(packageFileName, newPackageFileContent);
   } catch (err) {
diff --git a/lib/modules/manager/npm/extract/index.ts b/lib/modules/manager/npm/extract/index.ts
index d7e4dc835f..cd15aebd61 100644
--- a/lib/modules/manager/npm/extract/index.ts
+++ b/lib/modules/manager/npm/extract/index.ts
@@ -95,7 +95,7 @@ export async function extractPackageFile(
       lockFiles[key] = undefined;
     }
   }
-  lockFiles.npmLock = lockFiles.packageLock || lockFiles.shrinkwrapJson;
+  lockFiles.npmLock = lockFiles.packageLock ?? lockFiles.shrinkwrapJson;
   delete lockFiles.packageLock;
   delete lockFiles.shrinkwrapJson;
 
@@ -109,7 +109,7 @@ export async function extractPackageFile(
         'Repo .npmrc file is ignored due to config.npmrc with config.npmrcMerge=false'
       );
     } else {
-      npmrc = config.npmrc || '';
+      npmrc = config.npmrc ?? '';
       if (npmrc.length) {
         if (!npmrc.endsWith('\n')) {
           npmrc += '\n';
@@ -152,7 +152,8 @@ export async function extractPackageFile(
     | undefined;
   try {
     lernaJsonFile = getSiblingFileName(fileName, 'lerna.json');
-    lernaJson = JSON.parse(await readLocalFile(lernaJsonFile, 'utf8'));
+    // TODO #7154
+    lernaJson = JSON.parse((await readLocalFile(lernaJsonFile, 'utf8'))!);
   } catch (err) /* istanbul ignore next */ {
     logger.warn({ err }, 'Could not parse lerna.json');
   }
diff --git a/lib/modules/manager/npm/extract/npm.ts b/lib/modules/manager/npm/extract/npm.ts
index 0cb729bd0c..7a756734b9 100644
--- a/lib/modules/manager/npm/extract/npm.ts
+++ b/lib/modules/manager/npm/extract/npm.ts
@@ -3,7 +3,8 @@ import { readLocalFile } from '../../../../util/fs';
 import type { LockFile, LockFileEntry } from './types';
 
 export async function getNpmLock(filePath: string): Promise<LockFile> {
-  const lockRaw = await readLocalFile(filePath, 'utf8');
+  // TODO #7154
+  const lockRaw = (await readLocalFile(filePath, 'utf8'))!;
   try {
     const lockParsed = JSON.parse(lockRaw);
     const lockedVersions: Record<string, string> = {};
diff --git a/lib/modules/manager/npm/extract/pnpm.ts b/lib/modules/manager/npm/extract/pnpm.ts
index 93136088f5..844c405bb3 100644
--- a/lib/modules/manager/npm/extract/pnpm.ts
+++ b/lib/modules/manager/npm/extract/pnpm.ts
@@ -17,7 +17,8 @@ export async function extractPnpmFilters(
   fileName: string
 ): Promise<string[] | undefined> {
   try {
-    const contents = load(await readLocalFile(fileName, 'utf8'), {
+    // TODO #7154
+    const contents = load((await readLocalFile(fileName, 'utf8'))!, {
       json: true,
     }) as PnpmWorkspaceFile;
     if (
diff --git a/lib/modules/manager/npm/extract/yarn.ts b/lib/modules/manager/npm/extract/yarn.ts
index f45e2378b5..b9c5c0f0af 100644
--- a/lib/modules/manager/npm/extract/yarn.ts
+++ b/lib/modules/manager/npm/extract/yarn.ts
@@ -10,7 +10,8 @@ import {
 import type { LockFile } from './types';
 
 export async function getYarnLock(filePath: string): Promise<LockFile> {
-  const yarnLockRaw = await readLocalFile(filePath, 'utf8');
+  // TODO #7154
+  const yarnLockRaw = (await readLocalFile(filePath, 'utf8'))!;
   try {
     const parsed = parseSyml(yarnLockRaw);
     const lockedVersions: Record<string, string> = {};
diff --git a/lib/modules/manager/npm/post-update/index.ts b/lib/modules/manager/npm/post-update/index.ts
index 41181e50a4..51db6b2a29 100644
--- a/lib/modules/manager/npm/post-update/index.ts
+++ b/lib/modules/manager/npm/post-update/index.ts
@@ -141,7 +141,7 @@ export async function writeExistingFiles(
     const basedir =
       // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
       upath.dirname(packageFile.packageFile!);
-    const npmrc: string = packageFile.npmrc || config.npmrc;
+    const npmrc: string = packageFile.npmrc ?? config.npmrc;
     const npmrcFilename = upath.join(basedir, '.npmrc');
     if (is.string(npmrc)) {
       try {
@@ -257,7 +257,9 @@ export async function writeUpdatedPackageFiles(
       supportedLockFiles.some((fileName) => packageFile.path.endsWith(fileName))
     ) {
       logger.debug(`Writing lock file: ${packageFile.path}`);
-      await writeLocalFile(packageFile.path, packageFile.contents);
+      // TODO #7154
+      // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
+      await writeLocalFile(packageFile.path, packageFile.contents!);
       continue;
     }
     if (!packageFile.path.endsWith('package.json')) {
@@ -265,8 +267,13 @@ export async function writeUpdatedPackageFiles(
     }
     logger.debug(`Writing ${packageFile.path}`);
     const detectedIndent =
-      detectIndent(packageFile.contents.toString()).indent || '  ';
-    const massagedFile = JSON.parse(packageFile.contents.toString());
+      // TODO #7154
+      // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
+      detectIndent(packageFile.contents!.toString()).indent || '  ';
+
+    // TODO #7154
+    // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
+    const massagedFile = JSON.parse(packageFile.contents!.toString());
     try {
       const { token } = hostRules.find({
         hostType: 'github',
@@ -406,8 +413,8 @@ async function updateYarnOffline(
 export async function updateYarnBinary(
   lockFileDir: string,
   updatedArtifacts: FileChange[],
-  existingYarnrcYmlContent: string | undefined
-): Promise<string | undefined> {
+  existingYarnrcYmlContent: string | undefined | null
+): Promise<string | undefined | null> {
   let yarnrcYml = existingYarnrcYmlContent;
   try {
     const yarnrcYmlFilename = upath.join(lockFileDir, '.yarnrc.yml');
@@ -465,7 +472,7 @@ export async function getAdditionalFiles(
     !config.updatedPackageFiles?.length &&
     config.transitiveRemediation &&
     config.upgrades?.every(
-      (upgrade) => upgrade.isRemediation || upgrade.isVulnerabilityAlert
+      (upgrade) => upgrade.isRemediation ?? upgrade.isVulnerabilityAlert
     )
   ) {
     logger.debug('Skipping lock file generation for remediations');
@@ -581,7 +588,7 @@ export async function getAdditionalFiles(
     const npmrcContent = await getNpmrcContent(lockFileDir);
     await updateNpmrcContent(lockFileDir, npmrcContent, additionalNpmrcContent);
     let yarnRcYmlFilename: string | undefined;
-    let existingYarnrcYmlContent: string | undefined;
+    let existingYarnrcYmlContent: string | undefined | null;
     // istanbul ignore if: needs test
     if (additionalYarnRcYml) {
       yarnRcYmlFilename = getSiblingFileName(yarnLock, '.yarnrc.yml');
@@ -635,6 +642,8 @@ export async function getAdditionalFiles(
       }
       artifactErrors.push({
         lockFile: yarnLock,
+        // TODO #7154
+
         stderr: res.stderr || res.stdout,
       });
     } else {
@@ -706,6 +715,7 @@ export async function getAdditionalFiles(
       }
       artifactErrors.push({
         lockFile: pnpmShrinkwrap,
+        // TODO #7154
         stderr: res.stderr || res.stdout,
       });
     } else {
@@ -742,9 +752,9 @@ export async function getAdditionalFiles(
       throw new Error('lerna-no-lockfile');
     }
     if (lernaPackageFile.lernaClient === 'npm') {
-      lockFile = config.npmLock || 'package-lock.json';
+      lockFile = config.npmLock ?? 'package-lock.json';
     } else {
-      lockFile = config.yarnLock || 'yarn.lock';
+      lockFile = config.yarnLock ?? 'yarn.lock';
     }
     const skipInstalls =
       lockFile === 'npm-shrinkwrap.json' ? false : config.skipInstalls;
@@ -811,8 +821,8 @@ export async function getAdditionalFiles(
       });
     } else {
       for (const packageFile of packageFiles.npm) {
-        const filename = packageFile.npmLock || packageFile.yarnLock;
-        logger.trace('Checking for ' + filename);
+        const filename = packageFile.npmLock ?? packageFile.yarnLock;
+        logger.trace(`Checking for ${filename}`);
         const existingContent = await getFile(
           // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
           filename!,
diff --git a/lib/modules/manager/npm/post-update/node-version.ts b/lib/modules/manager/npm/post-update/node-version.ts
index f35cbaab40..b856a41651 100644
--- a/lib/modules/manager/npm/post-update/node-version.ts
+++ b/lib/modules/manager/npm/post-update/node-version.ts
@@ -6,7 +6,8 @@ import type { PostUpdateConfig, Upgrade } from '../../types';
 
 async function getNodeFile(filename: string): Promise<string | null> {
   try {
-    const constraint = (await readLocalFile(filename, 'utf8'))
+    // TODO #7154
+    const constraint = (await readLocalFile(filename, 'utf8'))!
       .split(newlineRegex)[0]
       .replace(regEx(/^v/), '');
     if (semver.validRange(constraint)) {
@@ -35,8 +36,8 @@ export async function getNodeConstraint(
 ): Promise<string | null> {
   const { packageFile } = config;
   const constraint =
-    (await getNodeFile(getSiblingFileName(packageFile, '.nvmrc'))) ||
-    (await getNodeFile(getSiblingFileName(packageFile, '.node-version'))) ||
+    (await getNodeFile(getSiblingFileName(packageFile, '.nvmrc'))) ??
+    (await getNodeFile(getSiblingFileName(packageFile, '.node-version'))) ??
     getPackageJsonConstraint(config);
   if (!constraint) {
     logger.debug('No node constraint found - using latest');
diff --git a/lib/modules/manager/npm/post-update/npm.ts b/lib/modules/manager/npm/post-update/npm.ts
index 6bc9e8bdf8..d2c4eaa889 100644
--- a/lib/modules/manager/npm/post-update/npm.ts
+++ b/lib/modules/manager/npm/post-update/npm.ts
@@ -134,7 +134,11 @@ export async function generateLockFile(
     }
 
     // Read the result
-    lockFile = await readLocalFile(upath.join(lockFileDir, filename), 'utf8');
+    // TODO #7154
+    lockFile = (await readLocalFile(
+      upath.join(lockFileDir, filename),
+      'utf8'
+    ))!;
 
     // Massage lockfile counterparts of package.json that were modified
     // because npm install was called with an explicit version for rangeStrategy=update-lockfile
diff --git a/lib/modules/manager/nuget/package-tree.ts b/lib/modules/manager/nuget/package-tree.ts
index d2510f0ebc..e7872f73a0 100644
--- a/lib/modules/manager/nuget/package-tree.ts
+++ b/lib/modules/manager/nuget/package-tree.ts
@@ -40,7 +40,9 @@ export async function getDependentPackageFiles(
   for (const f of packageFiles) {
     const packageFileContent = await readLocalFile(f, 'utf8');
 
-    const doc = new xmldoc.XmlDocument(packageFileContent);
+    // TODO #7154
+    // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
+    const doc = new xmldoc.XmlDocument(packageFileContent!);
     const projectReferenceAttributes = doc
       .childrenNamed('ItemGroup')
       .map((ig) => ig.childrenNamed('ProjectReference'))
diff --git a/lib/modules/manager/nuget/util.ts b/lib/modules/manager/nuget/util.ts
index ff48cbb0dc..ba0751ce16 100644
--- a/lib/modules/manager/nuget/util.ts
+++ b/lib/modules/manager/nuget/util.ts
@@ -10,7 +10,8 @@ async function readFileAsXmlDocument(
   file: string
 ): Promise<XmlDocument | undefined> {
   try {
-    return new XmlDocument(await readLocalFile(file, 'utf8'));
+    // TODO #7154
+    return new XmlDocument((await readLocalFile(file, 'utf8'))!);
   } catch (err) {
     logger.debug({ err }, `failed to parse '${file}' as XML document`);
     return undefined;
diff --git a/lib/modules/manager/poetry/artifacts.ts b/lib/modules/manager/poetry/artifacts.ts
index 7793b9eb65..52aaf61aa4 100644
--- a/lib/modules/manager/poetry/artifacts.ts
+++ b/lib/modules/manager/poetry/artifacts.ts
@@ -91,7 +91,7 @@ function getPoetrySources(content: string, fileName: string): PoetrySource[] {
     return [];
   }
 
-  const sources = pyprojectFile.tool?.poetry?.source || [];
+  const sources = pyprojectFile.tool?.poetry?.source ?? [];
   const sourceArray: PoetrySource[] = [];
   for (const source of sources) {
     if (source.name && source.url) {
@@ -174,7 +174,7 @@ export async function updateArtifacts({
     }
     const tagConstraint = getPythonConstraint(existingLockFileContent, config);
     const constraint =
-      config.constraints?.poetry || getPoetryRequirement(newPackageFileContent);
+      config.constraints?.poetry ?? getPoetryRequirement(newPackageFileContent);
     const extraEnv = getSourceCredentialVars(
       newPackageFileContent,
       packageFileName
diff --git a/lib/modules/manager/poetry/extract.ts b/lib/modules/manager/poetry/extract.ts
index 66c4aae4d8..c89a131b37 100644
--- a/lib/modules/manager/poetry/extract.ts
+++ b/lib/modules/manager/poetry/extract.ts
@@ -91,7 +91,7 @@ function extractRegistries(pyprojectfile: PoetryFile): string[] | undefined {
       registryUrls.add(source.url);
     }
   }
-  registryUrls.add(process.env.PIP_INDEX_URL || 'https://pypi.org/pypi/');
+  registryUrls.add(process.env.PIP_INDEX_URL ?? 'https://pypi.org/pypi/');
 
   return Array.from(registryUrls);
 }
@@ -115,7 +115,8 @@ export async function extractPackageFile(
 
   // handle the lockfile
   const lockfileName = getSiblingFileName(fileName, 'poetry.lock');
-  const lockContents = await readLocalFile(lockfileName, 'utf8');
+  // TODO #7154
+  const lockContents = (await readLocalFile(lockfileName, 'utf8'))!;
 
   const lockfileMapping = extractLockFileEntries(lockContents);
 
diff --git a/lib/modules/manager/terraform/lockfile/util.ts b/lib/modules/manager/terraform/lockfile/util.ts
index d1f4730353..a19b2aff95 100644
--- a/lib/modules/manager/terraform/lockfile/util.ts
+++ b/lib/modules/manager/terraform/lockfile/util.ts
@@ -26,7 +26,7 @@ export function findLockFile(packageFilePath: string): string {
   return getSiblingFileName(packageFilePath, lockFile);
 }
 
-export function readLockFile(lockFilePath: string): Promise<string> {
+export function readLockFile(lockFilePath: string): Promise<string | null> {
   return readLocalFile(lockFilePath, 'utf8');
 }
 
diff --git a/lib/util/fs/index.ts b/lib/util/fs/index.ts
index 4b224bdc13..ad7076bf6e 100644
--- a/lib/util/fs/index.ts
+++ b/lib/util/fs/index.ts
@@ -23,12 +23,11 @@ export function getSiblingFileName(
   return upath.join(subDirectory, otherFileName);
 }
 
-// TODO: can return null #7154
-export async function readLocalFile(fileName: string): Promise<Buffer>;
+export async function readLocalFile(fileName: string): Promise<Buffer | null>;
 export async function readLocalFile(
   fileName: string,
   encoding: 'utf8'
-): Promise<string>;
+): Promise<string | null>;
 export async function readLocalFile(
   fileName: string,
   encoding?: string
diff --git a/lib/util/git/types.ts b/lib/util/git/types.ts
index 587cd5205d..0c124e6726 100644
--- a/lib/util/git/types.ts
+++ b/lib/util/git/types.ts
@@ -46,7 +46,7 @@ export interface FileAddition {
   /**
    * File contents
    */
-  contents: string | Buffer;
+  contents: string | Buffer | null;
 
   /**
    * The executable bit
diff --git a/lib/workers/repository/config-migration/branch/migrated-data.ts b/lib/workers/repository/config-migration/branch/migrated-data.ts
index 9739d940f5..a120f7633c 100644
--- a/lib/workers/repository/config-migration/branch/migrated-data.ts
+++ b/lib/workers/repository/config-migration/branch/migrated-data.ts
@@ -51,7 +51,9 @@ export class MigratedDataFactory {
       const raw = await readLocalFile(filename, 'utf8');
 
       // indent defaults to 2 spaces
-      const indent = detectIndent(raw).indent ?? '  ';
+      // TODO #7154
+      // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
+      const indent = detectIndent(raw!).indent ?? '  ';
       let content: string;
 
       if (filename.endsWith('.json5')) {
diff --git a/lib/workers/repository/init/merge.ts b/lib/workers/repository/init/merge.ts
index 4ad24befac..c623921b5a 100644
--- a/lib/workers/repository/init/merge.ts
+++ b/lib/workers/repository/init/merge.ts
@@ -27,7 +27,7 @@ export async function detectRepoFileConfig(): Promise<RepoFileConfig> {
   const cache = getCache();
   let { configFileName } = cache;
   if (configFileName) {
-    let configFileParsed = await platform.getJsonFile(configFileName);
+    let configFileParsed = (await platform.getJsonFile(configFileName))!;
     if (configFileParsed) {
       if (configFileName === 'package.json') {
         configFileParsed = configFileParsed.renovate;
@@ -41,7 +41,9 @@ export async function detectRepoFileConfig(): Promise<RepoFileConfig> {
     for (const fileName of configFileNames) {
       if (fileName === 'package.json') {
         try {
-          const pJson = JSON.parse(await readLocalFile('package.json', 'utf8'));
+          const pJson = JSON.parse(
+            (await readLocalFile('package.json', 'utf8'))!
+          );
           if (pJson.renovate) {
             logger.debug('Using package.json for global renovate config');
             return 'package.json';
@@ -62,11 +64,13 @@ export async function detectRepoFileConfig(): Promise<RepoFileConfig> {
   }
   cache.configFileName = configFileName;
   logger.debug(`Found ${configFileName} config file`);
-  let configFileParsed;
+  // TODO #7154
+  let configFileParsed: any;
   if (configFileName === 'package.json') {
     // We already know it parses
     configFileParsed = JSON.parse(
-      await readLocalFile('package.json', 'utf8')
+      // TODO #7154
+      (await readLocalFile('package.json', 'utf8'))!
     ).renovate;
     if (is.string(configFileParsed)) {
       logger.debug('Massaging string renovate config to extends array');
@@ -194,7 +198,7 @@ export async function mergeRenovateConfig(
   }
   if (migratedConfig.warnings) {
     returnConfig.warnings = [
-      ...(returnConfig.warnings || []),
+      ...(returnConfig.warnings ?? []),
       ...migratedConfig.warnings,
     ];
   }
@@ -231,7 +235,7 @@ export async function mergeRenovateConfig(
   }
   resolvedConfig = applySecretsToConfig(
     resolvedConfig,
-    mergeChildConfig(config.secrets || {}, resolvedConfig.secrets || {})
+    mergeChildConfig(config.secrets ?? {}, resolvedConfig.secrets ?? {})
   );
   // istanbul ignore if
   if (resolvedConfig.hostRules) {
diff --git a/lib/workers/repository/onboarding/branch/check.ts b/lib/workers/repository/onboarding/branch/check.ts
index e61a234ccd..7210ce6104 100644
--- a/lib/workers/repository/onboarding/branch/check.ts
+++ b/lib/workers/repository/onboarding/branch/check.ts
@@ -31,7 +31,8 @@ const configFileExists = async (): Promise<boolean> => {
 
 const packageJsonConfigExists = async (): Promise<boolean> => {
   try {
-    const pJson = JSON.parse(await readLocalFile('package.json', 'utf8'));
+    // TODO #7154
+    const pJson = JSON.parse((await readLocalFile('package.json', 'utf8'))!);
     if (pJson.renovate) {
       return true;
     }
diff --git a/lib/workers/repository/update/branch/execute-post-upgrade-commands.ts b/lib/workers/repository/update/branch/execute-post-upgrade-commands.ts
index f1a3088779..dca6b59b34 100644
--- a/lib/workers/repository/update/branch/execute-post-upgrade-commands.ts
+++ b/lib/workers/repository/update/branch/execute-post-upgrade-commands.ts
@@ -47,13 +47,14 @@ export async function postUpgradeCommandsExecutor(
       for (const file of config.updatedPackageFiles!.concat(updatedArtifacts)) {
         const canWriteFile = await localPathIsFile(file.path);
         if (file.type === 'addition' && canWriteFile) {
-          let contents;
+          let contents: Buffer | null;
           if (typeof file.contents === 'string') {
             contents = Buffer.from(file.contents);
           } else {
             contents = file.contents;
           }
-          await writeLocalFile(file.path, contents);
+          // TODO #7154
+          await writeLocalFile(file.path, contents!);
         }
       }
 
diff --git a/lib/workers/repository/update/branch/get-updated.ts b/lib/workers/repository/update/branch/get-updated.ts
index c287fe0c7a..497369ec8e 100644
--- a/lib/workers/repository/update/branch/get-updated.ts
+++ b/lib/workers/repository/update/branch/get-updated.ts
@@ -248,7 +248,8 @@ export async function getUpdatedPackageFiles(
       const results = await updateArtifacts({
         packageFileName: packageFile.path,
         updatedDeps,
-        newPackageFileContent: packageFile.contents.toString(),
+        // TODO #7154
+        newPackageFileContent: packageFile.contents!.toString(),
         config,
       });
       if (is.nonEmptyArray(results)) {
@@ -278,7 +279,8 @@ export async function getUpdatedPackageFiles(
       const results = await updateArtifacts({
         packageFileName: packageFile.path,
         updatedDeps,
-        newPackageFileContent: packageFile.contents.toString(),
+        // TODO #7154
+        newPackageFileContent: packageFile.contents!.toString(),
         config,
       });
       if (is.nonEmptyArray(results)) {
-- 
GitLab