From 45cc07f3fc1488152bcaa9f696363e6ef8f8bf41 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Janis=20Daniel=20Da=CC=88hne?=
 <janis.daehne2@student.uni-halle.de>
Date: Fri, 15 Nov 2019 02:05:13 +0100
Subject: [PATCH] - enabled more strict return function checking and fixed
 errors

---
 src/components/404internal/Chat404.tsx        |  1 +
 .../aceEditors/aceEditorsStorageHelper.ts     | 11 +++++--
 src/constants.ts                              |  2 +-
 src/helpers/markdownHelper.ts                 |  4 +--
 .../doExerciseSite/doExerciseCrudActions.ts   | 30 +++++++++----------
 .../editCustomProjectCrudActions.ts           |  6 ++--
 .../tutorViewSite/tutorViewSiteCrudActions.ts | 18 ++++++++---
 tsconfig.json                                 |  4 ++-
 8 files changed, 48 insertions(+), 28 deletions(-)

diff --git a/src/components/404internal/Chat404.tsx b/src/components/404internal/Chat404.tsx
index 674b4c06..51f1cf60 100644
--- a/src/components/404internal/Chat404.tsx
+++ b/src/components/404internal/Chat404.tsx
@@ -284,6 +284,7 @@ class Chat404 extends React.Component<Props, State> {
 
                   default:
                     notExhaustive(value)
+                    return null
                 }
               })
             }
diff --git a/src/components/codeEditors/aceEditors/aceEditorsStorageHelper.ts b/src/components/codeEditors/aceEditors/aceEditorsStorageHelper.ts
index 5b8d0283..1bd98b59 100644
--- a/src/components/codeEditors/aceEditors/aceEditorsStorageHelper.ts
+++ b/src/components/codeEditors/aceEditors/aceEditorsStorageHelper.ts
@@ -72,11 +72,17 @@ export class AceEditorsStorageHelper {
     tabs.push(initialWrappedTab)
   }
 
+  /**
+   *
+   * @param id
+   * @param tab
+   * @returns true: id was removed, false: tab was not found
+   */
   public static removeTabToEditor(id: string, tab: AceStoredTabLike): boolean {
 
     const tabs = this.editorsMap[id]
 
-    if (!tabs) return true
+    if (!tabs) return false
 
     const index = tabs.findIndex(p => p.tab.id === tab.id)
 
@@ -84,6 +90,7 @@ export class AceEditorsStorageHelper {
 
     tabs.splice(index,1)
 
+    return true
   }
 
   public static getEditor(id: string): EditorWrapperTab[] | undefined {
@@ -207,4 +214,4 @@ export interface EditorWrapperTabExport {
     modeId: string //e.g. ace/mode/java
     value: string //editor content
   }
-}
\ No newline at end of file
+}
diff --git a/src/constants.ts b/src/constants.ts
index 87a9f0bf..6536091d 100644
--- a/src/constants.ts
+++ b/src/constants.ts
@@ -13,7 +13,7 @@ import Logger from './helpers/logger'
  * y - breaking changes / new features
  * z - fixes, small changes
  */
-export const versionString = '2.5.14'
+export const versionString = '2.5.15'
 
 
 export const supportMail = 'yapex@informatik.uni-halle.de'
diff --git a/src/helpers/markdownHelper.ts b/src/helpers/markdownHelper.ts
index 23cb7d7b..0bfe2e7a 100644
--- a/src/helpers/markdownHelper.ts
+++ b/src/helpers/markdownHelper.ts
@@ -310,9 +310,9 @@ mdRenderer.renderer.rules.fence = (tokens, idx, options, env, self) => {
   return withCopyBtn
 }
 
-function getCodeFenceProperties(langLine: string): CodeFenceProperties {
+function getCodeFenceProperties(langLine: string): CodeFenceProperties |null {
 
-  if (!langLine) return
+  if (!langLine) return null
 
   //first is the lang
 
diff --git a/src/state/actions/doExerciseSite/doExerciseCrudActions.ts b/src/state/actions/doExerciseSite/doExerciseCrudActions.ts
index 6cda5d9e..7858de8f 100644
--- a/src/state/actions/doExerciseSite/doExerciseCrudActions.ts
+++ b/src/state/actions/doExerciseSite/doExerciseCrudActions.ts
@@ -166,7 +166,7 @@ export function _saveDoExerciseSolution(releaseCode: string, shouldClearAllTestR
 /**
  * run the given tests, sets the test states to running and selects the last or the first failed test
  * @param {RunTestCommandForBackend} runNormalTestCommand
- * @returns {AwaitActionsWithResult<boolean>} true: all tests passed, false: at least 1 did not compile or not passed
+ * @returns [hasAnyTestFailed] true: some test has not compiled or not passed, false: all tests passed
  */
 export function runDoExerciseTest(runNormalTestCommand: RunTestCommandForBackend): AwaitActionsWithResult<boolean> {
   return async (dispatch, getState) => {
@@ -202,7 +202,7 @@ export function runDoExerciseTest(runNormalTestCommand: RunTestCommandForBackend
         getI18n(globalState.getState().i18nState.langId,'Warning'),
         getI18n(globalState.getState().i18nState.langId,'Probably no test has run'), globalState.getState().i18nState.langId
       )
-      return
+      return true
     }
 
     const firstFailedTest = ranTests.find(p => !p || !p.result || !p.result.hasCompiled || !p.result.passed)
@@ -215,7 +215,7 @@ export function runDoExerciseTest(runNormalTestCommand: RunTestCommandForBackend
       dispatch(setSelectedConsoleViewTest(ranTests[ranTests.length - 1]))
     }
 
-    return !!firstFailedTest
+    return firstFailedTest !== undefined
   }
 }
 
@@ -230,7 +230,7 @@ export function _runDoExerciseTest(runNormalTestCommand: RunTestCommandForBacken
  *
  * @param {RunTestCommandForBackend} runNormalTestCommand
  * @param langId
- * @returns {AwaitActionsWithResult<boolean>} true: all tests passed, false: at least 1 did not compile or not passed
+ * @returns [hasAnyTestFailed] true: some test has not compiled or not passed, false: all tests passed
  */
 export function runCustomDoExerciseTest(runNormalTestCommand: RunTestCommandForBackend, langId: KnownLangs): AwaitActionsWithResult<boolean> {
   return async (dispatch, getState) => {
@@ -273,7 +273,7 @@ export function runCustomDoExerciseTest(runNormalTestCommand: RunTestCommandForB
         getI18n(globalState.getState().i18nState.langId,'Warning'),
         getI18n(globalState.getState().i18nState.langId,'Probably no test has run'), globalState.getState().i18nState.langId
       )
-      return
+      return true
     }
 
     const ranTests = runNormalTestCommand.testIds
@@ -294,7 +294,7 @@ export function runCustomDoExerciseTest(runNormalTestCommand: RunTestCommandForB
       dispatch(setSelectedConsoleViewTest(updatedTest))
     }
 
-    return !!firstFailedTest
+    return firstFailedTest !== undefined
   }
 }
 
@@ -412,7 +412,7 @@ export function _justRunProgramDoExercise(justRunProgramCommand: JustRunProgramC
 
 /**
  * run the given tests, sets the test states to running and selects the last or the first failed test
- * @returns {AwaitActionsWithResult<boolean>} true: all tests passed, false: at least 1 did not compile or not passed
+ * @returns [hasAnyTestFailed] true: some test has not compiled or not passed, false: all tests passed
  */
 export function runAfterNormalTest(runTestWithSolution: RunTestCommandForBackend): AwaitActionsWithResult<boolean> {
   return async (dispatch, getState) => {
@@ -451,7 +451,7 @@ export function runAfterNormalTest(runTestWithSolution: RunTestCommandForBackend
       warningDialog(getI18n(globalState.getState().i18nState.langId,'Warning'),
         getI18n(globalState.getState().i18nState.langId,'Probably no test has run'), globalState.getState().i18nState.langId
       )
-      return
+      return true
     }
 
     const firstFailedTest = ranTests.find(p => !p || !p.result || !p.result.hasCompiled || !p.result.passed)
@@ -464,7 +464,7 @@ export function runAfterNormalTest(runTestWithSolution: RunTestCommandForBackend
       dispatch(setSelectedConsoleViewTest(ranTests[ranTests.length - 1]))
     }
 
-    return !!firstFailedTest
+    return firstFailedTest !== undefined
   }
 }
 
@@ -478,7 +478,7 @@ export function _runAfterNormalTest(runTestWithSolution: RunTestCommandForBacken
 
 /**
  * run the given tests, sets the test states to running and selects the last or the first failed test
- * @returns {AwaitActionsWithResult<boolean>} true: all tests passed, false: at least 1 did not compile or not passed
+ * @returns [hasAnyTestFailed] true: some test has not compiled or not passed, false: all tests passed
  */
 export function runAfterSubmitTest(runTestWithSolution: RunTestCommandForBackend): AwaitActionsWithResult<boolean> {
   return async (dispatch, getState) => {
@@ -517,7 +517,7 @@ export function runAfterSubmitTest(runTestWithSolution: RunTestCommandForBackend
       warningDialog(getI18n(globalState.getState().i18nState.langId,'Warning'),
         getI18n(globalState.getState().i18nState.langId,'Probably no test has run'), globalState.getState().i18nState.langId
       )
-      return
+      return true
     }
 
     const firstFailedTest = ranTests.find(p => !p || !p.result || !p.result.hasCompiled || !p.result.passed)
@@ -530,7 +530,7 @@ export function runAfterSubmitTest(runTestWithSolution: RunTestCommandForBackend
       dispatch(setSelectedConsoleViewTest(ranTests[ranTests.length - 1]))
     }
 
-    return !!firstFailedTest
+    return firstFailedTest !== undefined
   }
 }
 
@@ -543,7 +543,7 @@ export function _runAfterSubmitTest(runTestWithSolution: RunTestCommandForBacken
 
 /**
  * run the given tests, sets the test states to running and selects the last or the first failed test
- * @returns {AwaitActionsWithResult<boolean>} true: all tests passed, false: at least 1 did not compile or not passed
+ * @returns [hasAnyTestFailed] true: some test has not compiled or not passed, false: all tests passed
  */
 export function runAfterCustomTest(runNormalTestCommand: RunTestCommandForBackend): AwaitActionsWithResult<boolean> {
   return async (dispatch, getState) => {
@@ -577,7 +577,7 @@ export function runAfterCustomTest(runNormalTestCommand: RunTestCommandForBacken
         getI18n(globalState.getState().i18nState.langId,'Warning'),
         getI18n(globalState.getState().i18nState.langId,'Probably no test has run'), globalState.getState().i18nState.langId
       )
-      return
+      return true
     }
 
     const ranTests = runNormalTestCommand.testIds
@@ -603,7 +603,7 @@ export function runAfterCustomTest(runNormalTestCommand: RunTestCommandForBacken
       dispatch(setSelectedConsoleViewTest({...customTestCopy, result: ranTests[ranTests.length - 1].result}))
     }
 
-    return !!firstFailedTest
+    return firstFailedTest !== undefined
   }
 }
 
diff --git a/src/state/actions/editCustomProjectSite/editCustomProjectCrudActions.ts b/src/state/actions/editCustomProjectSite/editCustomProjectCrudActions.ts
index c63b4399..336452cb 100644
--- a/src/state/actions/editCustomProjectSite/editCustomProjectCrudActions.ts
+++ b/src/state/actions/editCustomProjectSite/editCustomProjectCrudActions.ts
@@ -89,7 +89,7 @@ export function getCustomProjectTestResultsAsync(customProjectId: number,
  * copied from doExerciseCrudActions > runCustomDoExerciseTest
  * @param {RunTestCommandForBackend} runNormalTestCommand
  * @param langId
- * @returns {AwaitActionsWithResult<boolean>} true: all tests passed, false: at least 1 did not compile or not passed
+ * @returns {AwaitActionsWithResult<boolean>} [hasAnyTestFailed?] true: at least 1 did not compile or not passed, false: all passed
  */
 export function runCustomProjectTestAsync(runNormalTestCommand: RunTestCommandCustomProjectForBackend, langId: KnownLangs): AwaitActionsWithResult<boolean> {
   return async (dispatch, getState) => {
@@ -131,7 +131,7 @@ export function runCustomProjectTestAsync(runNormalTestCommand: RunTestCommandCu
         getI18n(globalState.getState().i18nState.langId, 'Warning'),
         getI18n(globalState.getState().i18nState.langId, 'Probably no test has run'), globalState.getState().i18nState.langId
       )
-      return
+      return true
     }
 
     const ranTests = runNormalTestCommand.testIds
@@ -152,7 +152,7 @@ export function runCustomProjectTestAsync(runNormalTestCommand: RunTestCommandCu
       dispatch(setSelectedConsoleViewTest(updatedTest))
     }
 
-    return !!firstFailedTest
+    return firstFailedTest !== undefined
   }
 }
 
diff --git a/src/state/actions/tutorViewSite/tutorViewSiteCrudActions.ts b/src/state/actions/tutorViewSite/tutorViewSiteCrudActions.ts
index b698331e..a160cccc 100644
--- a/src/state/actions/tutorViewSite/tutorViewSiteCrudActions.ts
+++ b/src/state/actions/tutorViewSite/tutorViewSiteCrudActions.ts
@@ -128,6 +128,11 @@ export function _changeSingleAssessmentTutorViewAsync(assessment: AssessmentFull
 }
 
 
+/**
+ *
+ * @param runTestAsTutorCommand
+ * @returns [hasAnyTestFailed] true: some test has not compiled or not passed, false: all tests passed
+ */
 export function runNormalTestAsTutor(runTestAsTutorCommand: RunTutorTestCommandForBackend): AwaitActionsWithResult<boolean> {
   return async (dispatch, getState) => {
     //if we run the same test twice and the output won't change then this looks like nothing happened...
@@ -165,7 +170,7 @@ export function runNormalTestAsTutor(runTestAsTutorCommand: RunTutorTestCommandF
       warningDialog(getI18n(globalState.getState().i18nState.langId,'Warning'),
         getI18n(globalState.getState().i18nState.langId,'Probably no test has run'), globalState.getState().i18nState.langId
         )
-      return
+      return true
     }
 
     const firstFailedTest = ranTests.find(p => !p || !p.result || !p.result.hasCompiled || !p.result.passed)
@@ -178,7 +183,7 @@ export function runNormalTestAsTutor(runTestAsTutorCommand: RunTutorTestCommandF
       dispatch(setSelectedConsoleViewTest(ranTests[ranTests.length - 1]))
     }
 
-    return !!firstFailedTest
+    return firstFailedTest !== undefined
   }
 }
 
@@ -189,6 +194,11 @@ export function _runNormalTestAsTutor(runTestAsTutorCommand: RunTutorTestCommand
   }
 }
 
+/**
+ *
+ * @param runTestAsTutorCommand
+ * @returns [hasAnyTestFailed] true: some test has not compiled or not passed, false: all tests passed
+ */
 export function runSubmitTestAsTutor(runTestAsTutorCommand: RunTutorTestCommandForBackend): AwaitActionsWithResult<boolean> {
   return async (dispatch, getState) => {
 
@@ -227,7 +237,7 @@ export function runSubmitTestAsTutor(runTestAsTutorCommand: RunTutorTestCommandF
         getI18n(globalState.getState().i18nState.langId,'Probably no test has run'), globalState.getState().i18nState.langId
       )
 
-      return
+      return true
     }
 
     const firstFailedTest = ranTests.find(p => !p || !p.result || !p.result.hasCompiled || !p.result.passed)
@@ -240,7 +250,7 @@ export function runSubmitTestAsTutor(runTestAsTutorCommand: RunTutorTestCommandF
       dispatch(setSelectedConsoleViewTest(ranTests[ranTests.length - 1]))
     }
 
-    return !!firstFailedTest
+    return firstFailedTest !== undefined
   }
 }
 
diff --git a/tsconfig.json b/tsconfig.json
index 53efa85b..421215de 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -12,7 +12,9 @@
     "suppressImplicitAnyIndexErrors": true,
     "lib": ["es2015", "dom","es5","scripthost", "es2015.promise"],
     "allowJs": true,
-    "importHelpers": true
+    "importHelpers": true,
+    "noImplicitReturns": true,
+    "strictNullChecks": false //TODO at some point enable this to fix many bugs...
   },
   "include": [
     "./src/*",
-- 
GitLab