From 5896d9cb37447151f2e13d0b8570bc1618dfbca4 Mon Sep 17 00:00:00 2001
From: Jamie Magee <JamieMagee@users.noreply.github.com>
Date: Mon, 5 Oct 2020 18:12:01 +0200
Subject: [PATCH] chore(eslint): fixing some eslint warnings (#7382)

Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
---
 .eslintrc.js                                          | 3 ---
 lib/datasource/git-submodules/index.ts                | 2 +-
 lib/datasource/index.ts                               | 6 +++---
 lib/datasource/packagist/index.ts                     | 6 +++---
 lib/util/cache/repository/index.ts                    | 2 +-
 lib/workers/pr/body/updates-table.ts                  | 2 +-
 lib/workers/pr/changelog/release-notes.ts             | 8 ++++----
 lib/workers/pr/changelog/source-github.ts             | 2 +-
 lib/workers/pr/changelog/source-gitlab.ts             | 2 +-
 lib/workers/pr/code-owners.spec.ts                    | 2 +-
 lib/workers/repository/process/extract-update.spec.ts | 3 ++-
 lib/workers/repository/process/extract-update.ts      | 2 +-
 lib/workers/repository/updates/generate.ts            | 2 +-
 13 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/.eslintrc.js b/.eslintrc.js
index 8dbbd5f9c6..d53c730b04 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -42,7 +42,6 @@ module.exports = {
     'prefer-destructuring': 0,
     'prefer-template': 0,
     'no-underscore-dangle': 0,
-    // 'no-unused-vars': 2,
 
     'sort-imports': [
       'error',
@@ -69,9 +68,7 @@ module.exports = {
     ],
 
     // TODO: fix lint
-    '@typescript-eslint/camelcase': 0, // disabled until ??
     '@typescript-eslint/no-explicit-any': 0,
-    '@typescript-eslint/no-floating-promises': 2,
     '@typescript-eslint/no-non-null-assertion': 2,
     '@typescript-eslint/no-unused-vars': [
       2,
diff --git a/lib/datasource/git-submodules/index.ts b/lib/datasource/git-submodules/index.ts
index 530796a489..730e81fd52 100644
--- a/lib/datasource/git-submodules/index.ts
+++ b/lib/datasource/git-submodules/index.ts
@@ -51,4 +51,4 @@ export async function getReleases({
 export const getDigest = (
   config: DigestConfig,
   newValue?: string
-): Promise<string> => new Promise((resolve) => resolve(newValue));
+): Promise<string> => Promise.resolve(newValue);
diff --git a/lib/datasource/index.ts b/lib/datasource/index.ts
index 7dbc356cef..2aa1554f0d 100644
--- a/lib/datasource/index.ts
+++ b/lib/datasource/index.ts
@@ -220,10 +220,10 @@ function getRawReleases(
     registryUrls
   )}`;
   // By returning a Promise and reusing it, we should only fetch each package at most once
-  const cachedResult = memCache.get(cacheKey);
+  const cachedResult = memCache.get<Promise<ReleaseResult | null>>(cacheKey);
   // istanbul ignore if
-  if (cachedResult) {
-    return cachedResult as Promise<ReleaseResult | null>;
+  if (cachedResult !== undefined) {
+    return cachedResult;
   }
   const promisedRes = fetchReleases(config);
   memCache.set(cacheKey, promisedRes);
diff --git a/lib/datasource/packagist/index.ts b/lib/datasource/packagist/index.ts
index 46b9e15748..175914a9c6 100644
--- a/lib/datasource/packagist/index.ts
+++ b/lib/datasource/packagist/index.ts
@@ -204,10 +204,10 @@ async function getAllPackages(regUrl: string): Promise<AllPackages | null> {
 
 function getAllCachedPackages(regUrl: string): Promise<AllPackages | null> {
   const cacheKey = `packagist-${regUrl}`;
-  const cachedResult = memCache.get(cacheKey);
+  const cachedResult = memCache.get<Promise<AllPackages | null>>(cacheKey);
   // istanbul ignore if
-  if (cachedResult) {
-    return cachedResult as Promise<AllPackages | null>;
+  if (cachedResult !== undefined) {
+    return cachedResult;
   }
   const promisedRes = getAllPackages(regUrl);
   memCache.set(cacheKey, promisedRes);
diff --git a/lib/util/cache/repository/index.ts b/lib/util/cache/repository/index.ts
index 3c9899127f..bed1781ca9 100644
--- a/lib/util/cache/repository/index.ts
+++ b/lib/util/cache/repository/index.ts
@@ -8,7 +8,7 @@ import { RepoInitConfig } from '../../../workers/repository/init/common';
 export interface BaseBranchCache {
   sha: string; // branch commit sha
   configHash: string; // object hash of config
-  packageFiles: PackageFile[]; // extract result
+  packageFiles: Record<string, PackageFile[]>; // extract result
 }
 
 export interface BranchUpgradeCache {
diff --git a/lib/workers/pr/body/updates-table.ts b/lib/workers/pr/body/updates-table.ts
index e5bb000e7d..d969556831 100644
--- a/lib/workers/pr/body/updates-table.ts
+++ b/lib/workers/pr/body/updates-table.ts
@@ -8,7 +8,7 @@ type TableDefinition = {
 };
 
 function getTableDefinition(config: BranchConfig): TableDefinition[] {
-  const res = [];
+  const res: TableDefinition[] = [];
   for (const header of config.prBodyColumns) {
     const value = config.prBodyDefinitions[header];
     res.push({ header, value });
diff --git a/lib/workers/pr/changelog/release-notes.ts b/lib/workers/pr/changelog/release-notes.ts
index f88d104bc8..50228c5ca0 100644
--- a/lib/workers/pr/changelog/release-notes.ts
+++ b/lib/workers/pr/changelog/release-notes.ts
@@ -42,9 +42,9 @@ export function getCachedReleaseList(
   repository: string
 ): Promise<ChangeLogNotes[]> {
   const cacheKey = `getReleaseList-${apiBaseUrl}-${repository}`;
-  const cachedResult = memCache.get(cacheKey);
+  const cachedResult = memCache.get<Promise<ChangeLogNotes[]>>(cacheKey);
   // istanbul ignore if
-  if (cachedResult) {
+  if (cachedResult !== undefined) {
     return cachedResult;
   }
   const promisedRes = getReleaseList(apiBaseUrl, repository);
@@ -179,9 +179,9 @@ export async function getReleaseNotesMdFileInner(
 export function getReleaseNotesMdFile(
   repository: string,
   apiBaseUrl: string
-): Promise<ChangeLogFile> | null {
+): Promise<ChangeLogFile | null> {
   const cacheKey = `getReleaseNotesMdFile-${repository}-${apiBaseUrl}`;
-  const cachedResult = memCache.get(cacheKey);
+  const cachedResult = memCache.get<Promise<ChangeLogFile | null>>(cacheKey);
   // istanbul ignore if
   if (cachedResult !== undefined) {
     return cachedResult;
diff --git a/lib/workers/pr/changelog/source-github.ts b/lib/workers/pr/changelog/source-github.ts
index 8c8fcfca12..fbb2fbca89 100644
--- a/lib/workers/pr/changelog/source-github.ts
+++ b/lib/workers/pr/changelog/source-github.ts
@@ -16,7 +16,7 @@ function getCachedTags(
   repository: string
 ): Promise<string[]> {
   const cacheKey = `getTags-${endpoint}-${repository}`;
-  const cachedResult = memCache.get(cacheKey);
+  const cachedResult = memCache.get<Promise<string[]>>(cacheKey);
   // istanbul ignore if
   if (cachedResult !== undefined) {
     return cachedResult;
diff --git a/lib/workers/pr/changelog/source-gitlab.ts b/lib/workers/pr/changelog/source-gitlab.ts
index 5303312256..e5a760fbb3 100644
--- a/lib/workers/pr/changelog/source-gitlab.ts
+++ b/lib/workers/pr/changelog/source-gitlab.ts
@@ -18,7 +18,7 @@ function getCachedTags(
   repository: string
 ): Promise<string[]> {
   const cacheKey = `getTags-${endpoint}-${versionScheme}-${repository}`;
-  const cachedResult = memCache.get(cacheKey);
+  const cachedResult = memCache.get<Promise<string[]>>(cacheKey);
   // istanbul ignore if
   if (cachedResult !== undefined) {
     return cachedResult;
diff --git a/lib/workers/pr/code-owners.spec.ts b/lib/workers/pr/code-owners.spec.ts
index d6999d28b3..8832dfddbd 100644
--- a/lib/workers/pr/code-owners.spec.ts
+++ b/lib/workers/pr/code-owners.spec.ts
@@ -74,7 +74,7 @@ describe('workers/pr/code-owners', () => {
           if (path === codeOwnerFilePath) {
             return Promise.resolve(['* @mike'].join('\n'));
           }
-          return Promise.resolve(null);
+          return Promise.resolve<string>(null);
         });
         git.getBranchFiles.mockResolvedValueOnce(['README.md']);
         const codeOwners = await codeOwnersForPr(pr);
diff --git a/lib/workers/repository/process/extract-update.spec.ts b/lib/workers/repository/process/extract-update.spec.ts
index 2ba50adbcb..acb1409e49 100644
--- a/lib/workers/repository/process/extract-update.spec.ts
+++ b/lib/workers/repository/process/extract-update.spec.ts
@@ -1,5 +1,6 @@
 import hasha from 'hasha';
 import { git, mocked } from '../../../../test/util';
+import { PackageFile } from '../../../manager/common';
 import * as _repositoryCache from '../../../util/cache/repository';
 import * as _branchify from '../updates/branchify';
 import { extract, lookup, update } from './extract-update';
@@ -46,7 +47,7 @@ describe('workers/repository/process/extract-update', () => {
       expect(packageFiles).toMatchSnapshot();
     });
     it('uses repository cache', async () => {
-      const packageFiles = [];
+      const packageFiles: Record<string, PackageFile[]> = {};
       const config = {
         repoIsOnboarded: true,
         suppressNotifications: ['deprecationWarningIssues'],
diff --git a/lib/workers/repository/process/extract-update.ts b/lib/workers/repository/process/extract-update.ts
index f06fc4f110..1b303a3bf4 100644
--- a/lib/workers/repository/process/extract-update.ts
+++ b/lib/workers/repository/process/extract-update.ts
@@ -53,7 +53,7 @@ export async function extract(
   logger.debug('extract()');
   const { baseBranch } = config;
   const baseBranchSha = getBranchCommit(baseBranch);
-  let packageFiles;
+  let packageFiles: Record<string, PackageFile[]>;
   const cache = getCache();
   const cachedExtract = cache?.scan?.[baseBranch];
   const configHash = hasha(JSON.stringify(config));
diff --git a/lib/workers/repository/updates/generate.ts b/lib/workers/repository/updates/generate.ts
index 22a51fe088..6ef1bd6e90 100644
--- a/lib/workers/repository/updates/generate.ts
+++ b/lib/workers/repository/updates/generate.ts
@@ -9,7 +9,7 @@ import * as template from '../../../util/template';
 import { BranchConfig, BranchUpgradeConfig } from '../../common';
 import { formatCommitMessagePrefix } from '../util/commit-message';
 
-function isTypesGroup(branchUpgrades: any[]): boolean {
+function isTypesGroup(branchUpgrades: BranchUpgradeConfig[]): boolean {
   return (
     branchUpgrades.some(({ depName }) => depName?.startsWith('@types/')) &&
     new Set(
-- 
GitLab