From 2a737df1550e8973e59da871d5c2615841447f8d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Loi=CC=88c=20Correnson?= <loic.correnson@cea.fr>
Date: Sat, 16 May 2020 03:01:21 +0200
Subject: [PATCH] [ivette] taming master yoda

---
 ivette/.eslintrc.js                |  2 ++
 ivette/src/renderer/Controller.tsx | 26 +++++++++++++++-----------
 2 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/ivette/.eslintrc.js b/ivette/.eslintrc.js
index e57c8f64dbc..163e36aee57 100644
--- a/ivette/.eslintrc.js
+++ b/ivette/.eslintrc.js
@@ -51,6 +51,8 @@ module.exports = {
     "padded-blocks": "off",
     // Allow braces on their own line
     "@typescript-eslint/brace-style": "off",
+    // Allow range conditions such as 0 <= x && x < 10
+    "yoda": [2, "never", { "onlyEquality": true }],
     // Allow single command on new line after 'if' statement
     "curly": "off",
     // Do not specify position for single commands
diff --git a/ivette/src/renderer/Controller.tsx b/ivette/src/renderer/Controller.tsx
index be5402edb88..3152abf927d 100644
--- a/ivette/src/renderer/Controller.tsx
+++ b/ivette/src/renderer/Controller.tsx
@@ -160,7 +160,9 @@ const RenderConsole = () => {
     if (cursor < 0) {
       dumpCmdLine(Server.getConfig());
       const cmd = cmdLine.getDoc().getValue().trim();
-      const hs = history.filter((h: string) => h !== cmd).slice(0, 50);
+      const hs = history
+        .filter((h: string) => h !== cmd && h !== '')
+        .slice(0, 50);
       hs.unshift(cmd);
       scratch.current = hs.slice();
       setHistory(hs);
@@ -172,20 +174,22 @@ const RenderConsole = () => {
     }
   };
 
-  const doMove = (target: number) =>
-    (0 <= target && target < history.length ?
-      () => {
+  const doMove = (target: number) => {
+    if (0 <= target && target < history.length)
+      return () => {
         const doc = cmdLine.getDoc();
         const cmd = scratch.current;
         cmd[cursor] = doc.getValue();
         doc.setValue(cmd[target]);
         setCursor(target);
-      } : undefined);
+      };
+    return undefined;
+  };
 
   const doReload = () => {
     const doc = cmdLine.getDoc();
     const cmd = scratch.current;
-    if (cursor != 0) cmd[cursor] = doc.getValue();
+    if (cursor !== 0) cmd[cursor] = doc.getValue();
     dumpCmdLine(Server.getConfig());
     cmd[0] = doc.getValue();
     setCursor(0);
@@ -203,15 +207,15 @@ const RenderConsole = () => {
       setHistory(hst);
       setCursor(next);
     } else {
-      scratch.current = [""];
-      cmdLine.getDoc().setValue("");
+      scratch.current = [''];
+      cmdLine.getDoc().setValue('');
     }
   };
 
   const doPrev = doMove(cursor + 1);
   const doNext = doMove(cursor - 1);
   const edited = 0 <= cursor;
-  const length = history.length;
+  const n = history.length;
 
   return (
     <>
@@ -235,8 +239,8 @@ const RenderConsole = () => {
           onClick={doPrev}
           title="Previous Command"
         />
-        <Label className="dimmed" display={edited && length > 0}>
-          {1 + cursor}/{length}
+        <Label className="dimmed" display={edited && n > 0}>
+          {1 + cursor}/{n}
         </Label>
         <IconButton
           icon="MEDIA.NEXT"
-- 
GitLab