From 88892abb5635c9132d0e3540fed30726dd8f0b05 Mon Sep 17 00:00:00 2001
From: Michael Kriese <michael.kriese@visualon.de>
Date: Wed, 28 Aug 2019 09:00:08 +0200
Subject: [PATCH] fix: typescript types (#4393)

---
 lib/platform/azure/index.ts                        |  1 +
 lib/platform/bitbucket/index.ts                    |  2 +-
 lib/platform/git/storage.ts                        |  2 +-
 lib/workers/branch/get-updated.js                  |  6 ++----
 lib/workers/branch/schedule.js                     |  8 ++++++--
 lib/workers/global/index.js                        |  1 -
 lib/workers/pr/changelog/source-github.js          |  1 -
 lib/workers/repository/finalise/validate.js        |  5 +----
 lib/workers/repository/init/config.js              | 10 ++--------
 lib/workers/repository/init/index.js               |  1 -
 lib/workers/repository/onboarding/branch/check.js  |  5 +----
 lib/workers/repository/onboarding/branch/config.js |  6 ++----
 lib/workers/repository/process/lookup/filter.js    |  6 +-----
 lib/workers/repository/process/write.js            |  1 -
 test/types/jest.d.ts                               |  9 +++++++++
 test/website-docs.spec.js                          |  1 -
 16 files changed, 27 insertions(+), 38 deletions(-)
 create mode 100644 test/types/jest.d.ts

diff --git a/lib/platform/azure/index.ts b/lib/platform/azure/index.ts
index 9b75df0ff0..ceb2704263 100644
--- a/lib/platform/azure/index.ts
+++ b/lib/platform/azure/index.ts
@@ -502,6 +502,7 @@ export /* istanbul ignore next */ function ensureIssue() {
   logger.warn(`ensureIssue() is not implemented`);
 }
 
+// eslint-disable-next-line @typescript-eslint/no-empty-function
 export /* istanbul ignore next */ function ensureIssueClosing() {}
 
 export /* istanbul ignore next */ function getIssueList() {
diff --git a/lib/platform/bitbucket/index.ts b/lib/platform/bitbucket/index.ts
index afb32278a9..5daac06a82 100644
--- a/lib/platform/bitbucket/index.ts
+++ b/lib/platform/bitbucket/index.ts
@@ -497,7 +497,7 @@ function matchesState(state: string, desiredState: string) {
 export async function findPr(
   branchName: string,
   prTitle?: string | null,
-  state: string = 'all'
+  state = 'all'
 ) {
   logger.debug(`findPr(${branchName}, ${prTitle}, ${state})`);
   const prList = await getPrList();
diff --git a/lib/platform/git/storage.ts b/lib/platform/git/storage.ts
index 3abd432ef8..f4bfc524b2 100644
--- a/lib/platform/git/storage.ts
+++ b/lib/platform/git/storage.ts
@@ -436,7 +436,7 @@ export class Storage {
     }
   }
 
-  // eslint-disable-next-line class-methods-use-this
+  // eslint-disable-next-line
   cleanRepo() {}
 
   static getUrl({
diff --git a/lib/workers/branch/get-updated.js b/lib/workers/branch/get-updated.js
index 7e0cc6240c..7bda9a23ee 100644
--- a/lib/workers/branch/get-updated.js
+++ b/lib/workers/branch/get-updated.js
@@ -81,8 +81,7 @@ async function getUpdatedPackageFiles(config) {
         config
       );
       if (is.nonEmptyArray(results)) {
-        for (const res of results) {
-          // @ts-ignore
+        for (/** @type any */ const res of results) {
           const { file, artifactError } = res;
           if (file) {
             updatedArtifacts.push(file);
@@ -109,8 +108,7 @@ async function getUpdatedPackageFiles(config) {
           config
         );
         if (is.nonEmptyArray(results)) {
-          for (const res of results) {
-            // @ts-ignore
+          for (/** @type any */ const res of results) {
             const { file, artifactError } = res;
             if (file) {
               updatedArtifacts.push(file);
diff --git a/lib/workers/branch/schedule.js b/lib/workers/branch/schedule.js
index 4ce8a67136..2831dbe654 100644
--- a/lib/workers/branch/schedule.js
+++ b/lib/workers/branch/schedule.js
@@ -15,6 +15,9 @@ function fixShortHours(input) {
   return input.replace(/( \d?\d)((a|p)m)/g, '$1:00$2');
 }
 
+/**
+ * @returns {[boolean] | [boolean, string]}
+ */
 function hasValidTimezone(timezone) {
   if (!moment.tz.zone(timezone)) {
     return [false, `Invalid timezone: ${timezone}`];
@@ -22,6 +25,9 @@ function hasValidTimezone(timezone) {
   return [true];
 }
 
+/**
+ * @returns {[boolean] | [boolean, string]}
+ */
 function hasValidSchedule(schedule) {
   let message;
   if (
@@ -85,7 +91,6 @@ function isScheduledNow(config) {
   }
   const [validSchedule, errorMessage] = hasValidSchedule(configSchedule);
   if (!validSchedule) {
-    // @ts-ignore
     logger.warn(errorMessage);
     return true;
   }
@@ -96,7 +101,6 @@ function isScheduledNow(config) {
     logger.debug({ timezone: config.timezone }, 'Found timezone');
     const [validTimezone, error] = hasValidTimezone(config.timezone);
     if (!validTimezone) {
-      // @ts-ignore
       logger.warn(error);
       return true;
     }
diff --git a/lib/workers/global/index.js b/lib/workers/global/index.js
index 281e0e94e7..31bdba775b 100644
--- a/lib/workers/global/index.js
+++ b/lib/workers/global/index.js
@@ -73,7 +73,6 @@ async function start() {
 // istanbul ignore next
 function detectRenovateVersion() {
   try {
-    // @ts-ignore
     global.renovateVersion = require('../../../package.json').version; // eslint-disable-line global-require
   } catch (err) {
     logger.debug({ err }, 'Error getting renovate version');
diff --git a/lib/workers/pr/changelog/source-github.js b/lib/workers/pr/changelog/source-github.js
index 05106fb169..e1b49523f1 100644
--- a/lib/workers/pr/changelog/source-github.js
+++ b/lib/workers/pr/changelog/source-github.js
@@ -70,7 +70,6 @@ async function getChangeLogJSON({
   const githubApiBaseURL = sourceUrl.startsWith('https://github.com/')
     ? 'https://api.github.com/'
     : endpoint; // TODO FIX
-  // @ts-ignore
   const repository = pathname.slice(1).replace(/\/$/, '');
   if (repository.split('/').length !== 2) {
     logger.info({ sourceUrl }, 'Invalid github URL found');
diff --git a/lib/workers/repository/finalise/validate.js b/lib/workers/repository/finalise/validate.js
index ade9c898da..dd26a2e313 100644
--- a/lib/workers/repository/finalise/validate.js
+++ b/lib/workers/repository/finalise/validate.js
@@ -52,10 +52,7 @@ async function validatePrs(config) {
           if (file.endsWith('.json5')) {
             parsed = JSON5.parse(content);
           } else {
-            parsed = JSON.parse(
-              // @ts-ignore
-              content
-            );
+            parsed = JSON.parse(content);
           }
         } catch (err) {
           validations.push({
diff --git a/lib/workers/repository/init/config.js b/lib/workers/repository/init/config.js
index 6b8ad59b14..07ded19677 100644
--- a/lib/workers/repository/init/config.js
+++ b/lib/workers/repository/init/config.js
@@ -20,10 +20,7 @@ async function mergeRenovateConfig(config) {
     for (const fileName of configFileNames) {
       if (fileName === 'package.json') {
         try {
-          const pJson = JSON.parse(
-            // @ts-ignore
-            await platform.getFile('package.json')
-          );
+          const pJson = JSON.parse(await platform.getFile('package.json'));
           if (pJson.renovate) {
             logger.info('Using package.json for global renovate config');
             return 'package.json';
@@ -46,10 +43,7 @@ async function mergeRenovateConfig(config) {
   let renovateJson;
   if (configFile === 'package.json') {
     // We already know it parses
-    renovateJson = JSON.parse(
-      // @ts-ignore
-      await platform.getFile('package.json')
-    ).renovate;
+    renovateJson = JSON.parse(await platform.getFile('package.json')).renovate;
     logger.info({ config: renovateJson }, 'package.json>renovate config');
   } else {
     let renovateConfig = await platform.getFile(configFile);
diff --git a/lib/workers/repository/init/index.js b/lib/workers/repository/init/index.js
index 245bcfc9a1..9870527218 100644
--- a/lib/workers/repository/init/index.js
+++ b/lib/workers/repository/init/index.js
@@ -8,7 +8,6 @@ const { detectSemanticCommits } = require('./semantic');
 const { detectVulnerabilityAlerts } = require('./vulnerability');
 
 async function initRepo(input) {
-  // @ts-ignore
   global.repoCache = {};
   let config = {
     ...input,
diff --git a/lib/workers/repository/onboarding/branch/check.js b/lib/workers/repository/onboarding/branch/check.js
index 1b37cacc7c..1c7c9e4f97 100644
--- a/lib/workers/repository/onboarding/branch/check.js
+++ b/lib/workers/repository/onboarding/branch/check.js
@@ -24,10 +24,7 @@ const configFileExists = async () => {
 
 const packageJsonConfigExists = async () => {
   try {
-    const pJson = JSON.parse(
-      // @ts-ignore
-      await platform.getFile('package.json')
-    );
+    const pJson = JSON.parse(await platform.getFile('package.json'));
     if (pJson[appSlug]) {
       return true;
     }
diff --git a/lib/workers/repository/onboarding/branch/config.js b/lib/workers/repository/onboarding/branch/config.js
index ffde5255ae..de9d0f6ada 100644
--- a/lib/workers/repository/onboarding/branch/config.js
+++ b/lib/workers/repository/onboarding/branch/config.js
@@ -13,10 +13,8 @@ async function getOnboardingConfig(config) {
   try {
     logger.debug('Checking for greenkeeper config');
 
-    const greenkeeperConfig = JSON.parse(
-      // @ts-ignore
-      await platform.getFile('package.json')
-    ).greenkeeper;
+    const greenkeeperConfig = JSON.parse(await platform.getFile('package.json'))
+      .greenkeeper;
     if (greenkeeperConfig) {
       onboardingConfig.statusCheckVerify = true;
     }
diff --git a/lib/workers/repository/process/lookup/filter.js b/lib/workers/repository/process/lookup/filter.js
index 20c671cebe..6493acbef3 100644
--- a/lib/workers/repository/process/lookup/filter.js
+++ b/lib/workers/repository/process/lookup/filter.js
@@ -56,11 +56,7 @@ function filterVersions(
         'Falling back to npm semver syntax for allowedVersions'
       );
       filteredVersions = filteredVersions.filter(v =>
-        semver.satisfies(
-          // @ts-ignore
-          semver.coerce(v),
-          allowedVersions
-        )
+        semver.satisfies(semver.coerce(v), allowedVersions)
       );
     } else {
       logger.warn(
diff --git a/lib/workers/repository/process/write.js b/lib/workers/repository/process/write.js
index 97ee733fd4..4c0daa1aa6 100644
--- a/lib/workers/repository/process/write.js
+++ b/lib/workers/repository/process/write.js
@@ -31,7 +31,6 @@ async function writeUpdates(config, packageFiles, allBranches) {
       packageFiles
     );
     branch.res = res;
-    // @ts-ignore
     if (res === 'automerged' && config.automergeType !== 'pr-comment') {
       // Stop procesing other branches because base branch has been changed
       return res;
diff --git a/test/types/jest.d.ts b/test/types/jest.d.ts
new file mode 100644
index 0000000000..ffc34fccce
--- /dev/null
+++ b/test/types/jest.d.ts
@@ -0,0 +1,9 @@
+declare namespace jest {
+  interface Matchers<R> {
+    /**
+     * only available in `test/website-docs.spec.js`
+     * @param arg
+     */
+    toContainOption(arg: R): void;
+  }
+}
diff --git a/test/website-docs.spec.js b/test/website-docs.spec.js
index 1c95febf0e..f484442d4f 100644
--- a/test/website-docs.spec.js
+++ b/test/website-docs.spec.js
@@ -86,7 +86,6 @@ describe('docs', () => {
   // Lists through each option in the relatedOptions array to be able to locate the exact element which causes error, in case of one
   it('has valid relateOptions values', () => {
     relatedOptions.forEach(relOption => {
-      // @ts-ignore
       expect(allOptionNames).toContainOption(relOption);
     });
   });
-- 
GitLab