From 095f2f8240ca90d3dc61016cb97b84d8e853c9b8 Mon Sep 17 00:00:00 2001
From: Sergio Zharinov <zharinov@users.noreply.github.com>
Date: Thu, 27 Aug 2020 11:11:10 +0400
Subject: [PATCH] refactor(util): Fix lint warnings (#7114)

---
 lib/util/cache/memory/index.ts  |  2 +-
 lib/util/cache/package/index.ts |  2 +-
 lib/util/exec/docker/index.ts   |  4 ++--
 lib/util/exec/index.ts          |  5 +++--
 lib/util/fs/index.ts            |  6 +++---
 lib/util/fs/proxies.ts          |  2 +-
 lib/util/http/github.ts         |  2 +-
 lib/util/http/index.ts          |  2 +-
 lib/util/package-rules.ts       |  4 ++--
 lib/util/regex.ts               |  2 +-
 lib/util/template/index.ts      | 12 ++++++++----
 11 files changed, 24 insertions(+), 19 deletions(-)

diff --git a/lib/util/cache/memory/index.ts b/lib/util/cache/memory/index.ts
index 3b2860220e..b83ee4969d 100644
--- a/lib/util/cache/memory/index.ts
+++ b/lib/util/cache/memory/index.ts
@@ -12,7 +12,7 @@ export function get<T = any>(key: string): T {
   return repoCache?.[key];
 }
 
-export function set(key: string, value: any): void {
+export function set(key: string, value: unknown): void {
   if (repoCache) {
     repoCache[key] = value;
   }
diff --git a/lib/util/cache/package/index.ts b/lib/util/cache/package/index.ts
index 6962b73c6a..4735f5e977 100644
--- a/lib/util/cache/package/index.ts
+++ b/lib/util/cache/package/index.ts
@@ -24,7 +24,7 @@ export function get<T = any>(namespace: string, key: string): Promise<T> {
 export function set(
   namespace: string,
   key: string,
-  value: any,
+  value: unknown,
   minutes: number
 ): Promise<void> {
   if (!cacheProxy) {
diff --git a/lib/util/exec/docker/index.ts b/lib/util/exec/docker/index.ts
index cb3221807a..7731267947 100644
--- a/lib/util/exec/docker/index.ts
+++ b/lib/util/exec/docker/index.ts
@@ -117,7 +117,7 @@ function getContainerName(image: string): string {
   return image.replace(/\//g, '_');
 }
 
-export async function removeDockerContainer(image): Promise<void> {
+export async function removeDockerContainer(image: string): Promise<void> {
   const containerName = getContainerName(image);
   let cmd = `docker ps --filter name=${containerName} -aq`;
   try {
@@ -208,7 +208,7 @@ export async function generateDockerCommand(
     result.push(`-w "${cwd}"`);
   }
 
-  let tag;
+  let tag: string;
   if (options.tag) {
     tag = options.tag;
   } else if (tagConstraint) {
diff --git a/lib/util/exec/index.ts b/lib/util/exec/index.ts
index 27f60115a6..7f94d0b560 100644
--- a/lib/util/exec/index.ts
+++ b/lib/util/exec/index.ts
@@ -158,9 +158,10 @@ export async function exec(
       logger.trace({ err }, 'rawExec err');
       clearTimeout(timer);
       if (useDocker) {
-        await removeDockerContainer(docker.image).catch((removeErr) => {
+        await removeDockerContainer(docker.image).catch((removeErr: Error) => {
+          const message: string = err.message;
           throw new Error(
-            `Error: "${removeErr.message}" - Original Error: "${err.message}"`
+            `Error: "${removeErr.message}" - Original Error: "${message}"`
           );
         });
       }
diff --git a/lib/util/fs/index.ts b/lib/util/fs/index.ts
index 313dd6e488..e26afe1ea8 100644
--- a/lib/util/fs/index.ts
+++ b/lib/util/fs/index.ts
@@ -60,18 +60,18 @@ export async function deleteLocalFile(fileName: string): Promise<void> {
 }
 
 // istanbul ignore next
-export async function ensureDir(dirName): Promise<void> {
+export async function ensureDir(dirName: string): Promise<void> {
   await fs.ensureDir(dirName);
 }
 
 // istanbul ignore next
-export async function ensureLocalDir(dirName): Promise<void> {
+export async function ensureLocalDir(dirName: string): Promise<void> {
   const localDirName = join(localDir, dirName);
   await fs.ensureDir(localDirName);
 }
 
 export async function ensureCacheDir(
-  dirName,
+  dirName: string,
   envPathVar?: string
 ): Promise<string> {
   const envCacheDirName = envPathVar ? process.env[envPathVar] : null;
diff --git a/lib/util/fs/proxies.ts b/lib/util/fs/proxies.ts
index 86f26b5fdf..9dfefc4667 100644
--- a/lib/util/fs/proxies.ts
+++ b/lib/util/fs/proxies.ts
@@ -37,7 +37,7 @@ export function writeFile(
 // istanbul ignore next
 export function outputFile(
   file: string,
-  data: any,
+  data: unknown,
   options?: WriteFileOptions | string
 ): Promise<void> {
   return fs.outputFile(file, data, options ?? {});
diff --git a/lib/util/http/github.ts b/lib/util/http/github.ts
index 35ca32c319..aacc666d75 100644
--- a/lib/util/http/github.ts
+++ b/lib/util/http/github.ts
@@ -257,7 +257,7 @@ export class GithubHttp extends Http<GithubHttpOptions, GithubHttpOptions> {
 
     const { paginate = true } = options;
     let count = options.count || 100;
-    let cursor = null;
+    let cursor: string = null;
 
     let isIterating = true;
     while (isIterating) {
diff --git a/lib/util/http/index.ts b/lib/util/http/index.ts
index c45fa75bae..b3ba41b522 100644
--- a/lib/util/http/index.ts
+++ b/lib/util/http/index.ts
@@ -33,7 +33,7 @@ export interface HttpPostOptions extends HttpOptions {
 }
 
 export interface InternalHttpOptions extends HttpOptions {
-  json?: object;
+  json?: Record<string, unknown>;
   responseType?: 'json';
   method?: 'get' | 'post' | 'put' | 'patch' | 'delete' | 'head';
 }
diff --git a/lib/util/package-rules.ts b/lib/util/package-rules.ts
index ea73c86e4d..8401eec933 100644
--- a/lib/util/package-rules.ts
+++ b/lib/util/package-rules.ts
@@ -147,7 +147,7 @@ function matchesRule(inputConfig: Config, packageRule: PackageRule): boolean {
             : packagePattern
         );
         if (packageRegex.test(depName)) {
-          logger.trace(`${depName} matches against ${packageRegex}`);
+          logger.trace(`${depName} matches against ${String(packageRegex)}`);
           isMatch = true;
         }
       }
@@ -171,7 +171,7 @@ function matchesRule(inputConfig: Config, packageRule: PackageRule): boolean {
         pattern === '^*$' || pattern === '*' ? '.*' : pattern
       );
       if (packageRegex.test(depName)) {
-        logger.trace(`${depName} matches against ${packageRegex}`);
+        logger.trace(`${depName} matches against ${String(packageRegex)}`);
         isMatch = true;
       }
     }
diff --git a/lib/util/regex.ts b/lib/util/regex.ts
index d1e7aa9559..64bdbb6b7f 100644
--- a/lib/util/regex.ts
+++ b/lib/util/regex.ts
@@ -21,7 +21,7 @@ export function regEx(pattern: string, flags?: string): RegExp {
   } catch (err) {
     const error = new Error(CONFIG_VALIDATION);
     error.configFile = pattern;
-    error.validationError = 'Invalid regular expression: ' + err.toString();
+    error.validationError = `Invalid regular expression: ${pattern}`;
     throw error;
   }
 }
diff --git a/lib/util/template/index.ts b/lib/util/template/index.ts
index abc78c1f85..502a863997 100644
--- a/lib/util/template/index.ts
+++ b/lib/util/template/index.ts
@@ -84,7 +84,9 @@ export const allowedFields = {
   versions: 'An array of ChangeLogRelease objects in the upgrade',
 };
 
-function getFilteredObject(input: any): any {
+type CompileInput = Record<string, unknown>;
+
+function getFilteredObject(input: CompileInput): any {
   const obj = clone(input);
   const res = {};
   const allAllowed = [
@@ -94,8 +96,10 @@ function getFilteredObject(input: any): any {
   for (const field of allAllowed) {
     const value = obj[field];
     if (is.array(value)) {
-      res[field] = value.map((element) => getFilteredObject(element));
-    } else if (is.object(value)) {
+      res[field] = value.map((element) =>
+        getFilteredObject(element as CompileInput)
+      );
+    } else if (is.plainObject(value)) {
       res[field] = getFilteredObject(value);
     } else if (!is.undefined(value)) {
       res[field] = value;
@@ -106,7 +110,7 @@ function getFilteredObject(input: any): any {
 
 export function compile(
   template: string,
-  input: any,
+  input: CompileInput,
   filterFields = true
 ): string {
   const filteredInput = filterFields ? getFilteredObject(input) : input;
-- 
GitLab