Browse Source

Clean up and code conventions.

Afshin Darian 7 years ago
parent
commit
4433d4afa8

+ 2 - 2
packages/console-extension/src/index.ts

@@ -107,8 +107,8 @@ const contentFactoryPlugin: JupyterLabPlugin<ConsolePanel.IContentFactory> = {
   requires: [IEditorServices],
   autoStart: true,
   activate: (app: JupyterLab, editorServices: IEditorServices) => {
-    let editorFactory = editorServices.factoryService.newInlineEditor.bind(
-      editorServices.factoryService);
+    const editorFactory = editorServices.factoryService.newInlineEditor
+      .bind(editorServices.factoryService);
     return new ConsolePanel.ContentFactory({ editorFactory });
   }
 };

+ 5 - 5
packages/docmanager-extension/src/index.ts

@@ -34,6 +34,9 @@ import {
  * The command IDs used by the document manager plugin.
  */
 namespace CommandIDs {
+  export
+  const clone = 'docmanager:clone';
+
   export
   const close = 'docmanager:close';
 
@@ -53,7 +56,7 @@ namespace CommandIDs {
   const open = 'docmanager:open';
 
   export
-  const clone = 'docmanager:clone';
+  const rename = 'docmanager:rename';
 
   export
   const restoreCheckpoint = 'docmanager:restore-checkpoint';
@@ -63,10 +66,7 @@ namespace CommandIDs {
 
   export
   const saveAs = 'docmanager:save-as';
-
-  export
-  const rename = 'docmanager:rename';
-};
+}
 
 
 /**

+ 3 - 1
packages/faq-extension/src/index.ts

@@ -30,7 +30,7 @@ import '../style/index.css';
 namespace CommandIDs {
   export
   const open: string = 'faq-jupyterlab:open';
-};
+}
 
 
 /**
@@ -50,10 +50,12 @@ const plugin: JupyterLabPlugin<void> = {
 export default plugin;
 
 
+/* tslint:disable */
 /**
  * The faq page source.
  */
 const SOURCE = require('../faq.md');
+/* tslint:enable */
 
 
 /**

+ 1 - 1
packages/filebrowser-extension/src/index.ts

@@ -84,7 +84,7 @@ namespace CommandIDs {
 
   export
   const createLauncher = 'filebrowser:create-main-launcher'; // For main browser only.
-};
+}
 
 
 /**

+ 1 - 1
packages/fileeditor-extension/src/index.ts

@@ -68,7 +68,7 @@ namespace CommandIDs {
 
   export
   const markdownPreview = 'fileeditor:markdown-preview';
-};
+}
 
 
 /**

+ 23 - 30
packages/imageviewer-extension/src/index.ts

@@ -23,14 +23,14 @@ import {
  */
 namespace CommandIDs {
   export
-  const zoomIn = 'imageviewer:zoom-in';
+  const resetZoom = 'imageviewer:reset-zoom';
 
   export
-  const zoomOut = 'imageviewer:zoom-out';
+  const zoomIn = 'imageviewer:zoom-in';
 
   export
-  const resetZoom = 'imageviewer:reset-zoom';
-};
+  const zoomOut = 'imageviewer:zoom-out';
+}
 
 
 /**
@@ -91,17 +91,18 @@ function activate(app: JupyterLab, palette: ICommandPalette, restorer: ILayoutRe
     widget.context.pathChanged.connect(() => { tracker.save(widget); });
     tracker.add(widget);
 
-    let fts = app.docRegistry.getFileTypesForPath(widget.context.path);
-    if (fts.length > 0) {
-      widget.title.iconClass = fts[0].iconClass;
-      widget.title.iconLabel = fts[0].iconLabel;
-    }
+    const types = app.docRegistry.getFileTypesForPath(widget.context.path);
 
+    if (types.length > 0) {
+      widget.title.iconClass = types[0].iconClass;
+      widget.title.iconLabel = types[0].iconLabel;
+    }
   });
 
   addCommands(tracker, app.commands);
 
-  let category = 'Image Viewer';
+  const category = 'Image Viewer';
+
   [CommandIDs.zoomIn, CommandIDs.zoomOut, CommandIDs.resetZoom]
     .forEach(command => { palette.addItem({ command, category }); });
 
@@ -148,35 +149,27 @@ function addCommands(tracker: IImageTracker, commands: CommandRegistry) {
   });
 
   function zoomIn(): void {
-    let widget = tracker.currentWidget;
-    if (!widget) {
-      return;
-    }
-    if (widget.scale > 1) {
-      widget.scale += .5;
-    } else {
-      widget.scale *= 2;
+    const widget = tracker.currentWidget;
+
+    if (widget) {
+      widget.scale = widget.scale > 1 ? widget.scale + 0.5 : widget.scale * 2;
     }
   }
 
   function zoomOut(): void {
-    let widget = tracker.currentWidget;
-    if (!widget) {
-      return;
-    }
-    if (widget.scale > 1) {
-      widget.scale -= .5;
-    } else {
-      widget.scale /= 2;
+    const widget = tracker.currentWidget;
+
+    if (widget) {
+      widget.scale = widget.scale > 1 ? widget.scale - 0.5 : widget.scale / 2;
     }
   }
 
   function resetZoom(): void {
-    let widget = tracker.currentWidget;
-    if (!widget) {
-      return;
+    const widget = tracker.currentWidget;
+
+    if (widget) {
+      widget.scale = 1;
     }
-    widget.scale = 1;
   }
 }
 

+ 3 - 3
packages/inspector-extension/src/index.ts

@@ -38,8 +38,8 @@ namespace CommandIDs {
 /**
  * A service providing code introspection.
  */
-const service: JupyterLabPlugin<IInspector> = {
-  id: 'jupyter.services.inspector',
+const corePlugin: JupyterLabPlugin<IInspector> = {
+  id: '@jupyterlab/inspector-extension:corePlugin',
   requires: [ICommandPalette, ILayoutRestorer],
   provides: IInspector,
   autoStart: true,
@@ -210,7 +210,7 @@ const notebookPlugin: JupyterLabPlugin<void> = {
  * Export the plugins as default.
  */
 const plugins: JupyterLabPlugin<any>[] = [
-  service, consolePlugin, notebookPlugin
+  corePlugin, consolePlugin, notebookPlugin
 ];
 export default plugins;
 

+ 3 - 6
packages/launcher-extension/src/index.ts

@@ -31,7 +31,7 @@ import '../style/index.css';
 namespace CommandIDs {
   export
   const create = 'launcher:create';
-};
+}
 
 
 /**
@@ -40,9 +40,7 @@ namespace CommandIDs {
 const plugin: JupyterLabPlugin<ILauncher> = {
   activate,
   id: 'jupyter.services.launcher',
-  requires: [
-    ICommandPalette
-  ],
+  requires: [ICommandPalette],
   provides: ILauncher,
   autoStart: true
 };
@@ -59,8 +57,7 @@ export default plugin;
  */
 function activate(app: JupyterLab, palette: ICommandPalette): ILauncher {
   const { commands, shell } = app;
-
-  let model = new LauncherModel();
+  const model = new LauncherModel();
 
   commands.addCommand(CommandIDs.create, {
     label: 'New Launcher',

+ 2 - 2
packages/markdownviewer-extension/src/index.ts

@@ -53,12 +53,12 @@ function activate(app: JupyterLab, restorer: ILayoutRestorer) {
       fileTypes: ['markdown'],
       rendermime: app.rendermime
     });
-    app.docRegistry.addWidgetFactory(factory);
-
     const { commands } = app;
     const namespace = 'rendered-markdown';
     const tracker = new InstanceTracker<MimeDocument>({ namespace });
 
+    app.docRegistry.addWidgetFactory(factory);
+
     // Handle state restoration.
     restorer.restore(tracker, {
       command: 'docmanager:open',

+ 295 - 248
packages/notebook-extension/src/index.ts

@@ -207,7 +207,7 @@ namespace CommandIDs {
   export
   const showAllOutputs = 'notebook:show-all-cell-outputs';
 
-};
+}
 
 
 /**
@@ -433,8 +433,9 @@ function activateNotebookHandler(app: JupyterLab, mainMenu: IMainMenu, palette:
   // Add a launcher item if the launcher is available.
   if (launcher) {
     services.ready.then(() => {
-      let specs = services.specs;
-      let baseUrl = PageConfig.getBaseUrl();
+      const specs = services.specs;
+      const baseUrl = PageConfig.getBaseUrl();
+
       for (let name in specs.kernelspecs) {
         let displayName = specs.kernelspecs[name].display_name;
         let rank = name === specs.default ? 0 : Infinity;
@@ -456,14 +457,45 @@ function activateNotebookHandler(app: JupyterLab, mainMenu: IMainMenu, palette:
     });
   }
 
-  app.contextMenu.addItem({command: CommandIDs.clearOutputs, selector: '.jp-Notebook .jp-Cell'});
-  app.contextMenu.addItem({command: CommandIDs.split, selector: '.jp-Notebook .jp-Cell'});
-  app.contextMenu.addItem({ type: 'separator', selector: '.jp-Notebook', rank: 0 });
-  app.contextMenu.addItem({command: CommandIDs.undo, selector: '.jp-Notebook', rank: 1});
-  app.contextMenu.addItem({command: CommandIDs.redo, selector: '.jp-Notebook', rank: 2});
-  app.contextMenu.addItem({ type: 'separator', selector: '.jp-Notebook', rank: 0 });
-  app.contextMenu.addItem({command: CommandIDs.createConsole, selector: '.jp-Notebook', rank: 3});
-    app.contextMenu.addItem({command: CommandIDs.clearAllOutputs, selector: '.jp-Notebook', rank: 3});
+  app.contextMenu.addItem({
+    command: CommandIDs.clearOutputs,
+    selector: '.jp-Notebook .jp-Cell'
+  });
+  app.contextMenu.addItem({
+    command: CommandIDs.split,
+    selector: '.jp-Notebook .jp-Cell'
+  });
+  app.contextMenu.addItem({
+    type: 'separator',
+    selector: '.jp-Notebook',
+    rank: 0
+  });
+  app.contextMenu.addItem({
+    command: CommandIDs.undo,
+    selector: '.jp-Notebook',
+    rank: 1
+  });
+  app.contextMenu.addItem({
+    command: CommandIDs.redo,
+    selector: '.jp-Notebook',
+    rank: 2
+  });
+  app.contextMenu.addItem({
+    type: 'separator',
+    selector: '.jp-Notebook',
+    rank: 0
+  });
+  app.contextMenu.addItem({
+    command: CommandIDs.createConsole,
+    selector: '.jp-Notebook',
+    rank: 3
+  });
+  app.contextMenu.addItem({
+    command: CommandIDs.clearAllOutputs,
+    selector: '.jp-Notebook',
+    rank: 3
+  });
+
   return tracker;
 }
 
@@ -477,11 +509,13 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
 
   // Get the current widget and activate unless the args specify otherwise.
   function getCurrent(args: ReadonlyJSONObject): NotebookPanel | null {
-    let widget = tracker.currentWidget;
-    let activate = args['activate'] !== false;
+    const widget = tracker.currentWidget;
+    const activate = args['activate'] !== false;
+
     if (activate && widget) {
       shell.activateById(widget.id);
     }
+
     return widget;
   }
 
@@ -495,80 +529,85 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.runAndAdvance, {
     label: 'Run Cell(s) and Select Below',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        const { context, notebook } = current;
+
+        return NotebookActions.runAndAdvance(notebook, context.session);
       }
-      let content = current.notebook;
-      return NotebookActions.runAndAdvance(content, current.context.session);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.run, {
     label: 'Run Cell(s)',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        const { context, notebook } = current;
+
+        return NotebookActions.run(notebook, context.session);
       }
-      return NotebookActions.run(current.notebook, current.context.session);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.runAndInsert, {
     label: 'Run Cell(s) and Insert Below',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        const { context, notebook } = current;
+
+        return NotebookActions.runAndInsert(notebook, context.session);
       }
-      return NotebookActions.runAndInsert(
-        current.notebook, current.context.session
-      );
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.runAll, {
     label: 'Run All Cells',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        const { context, notebook } = current;
+
+        return NotebookActions.runAll(notebook, context.session);
       }
-      return NotebookActions.runAll(current.notebook, current.context.session);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.restart, {
     label: 'Restart Kernel',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return current.session.restart();
       }
-      current.session.restart();
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.closeAndShutdown, {
     label: 'Close and Shutdown',
     execute: args => {
-      let current = getCurrent(args);
+      const current = getCurrent(args);
+
       if (!current) {
         return;
       }
-      let fileName = current.title.label;
+
+      const fileName = current.title.label;
+
       return showDialog({
         title: 'Shutdown the notebook?',
         body: `Are you sure you want to close "${fileName}"?`,
         buttons: [Dialog.cancelButton(), Dialog.warnButton()]
       }).then(result => {
         if (result.button.accept) {
-          return current.context.session.shutdown().then(() => {
-            current.dispose();
-          });
-        } else {
-          return;
+          return current.context.session.shutdown()
+            .then(() => { current.dispose(); });
         }
       });
     },
@@ -577,104 +616,111 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.trust, {
     label: 'Trust Notebook',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        const { context, notebook } = current;
+
+        return NotebookActions.trust(notebook).then(() => context.save());
       }
-      return NotebookActions.trust(current.notebook).then(() => {
-        return current.context.save();
-      });
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.exportToFormat, {
     label: args => {
-        let formatLabel = (args['label']) as string;
+        const formatLabel = (args['label']) as string;
+
         return (args['isPalette'] ? 'Export To ' : '') + formatLabel;
     },
     execute: args => {
-      let current = getCurrent(args);
+      const current = getCurrent(args);
+
       if (!current) {
         return;
       }
 
-      let notebookPath = URLExt.encodeParts(current.context.path);
-      let url = URLExt.join(
+      const notebookPath = URLExt.encodeParts(current.context.path);
+      const url = URLExt.join(
         services.serverSettings.baseUrl,
         'nbconvert',
         (args['format']) as string,
         notebookPath
       ) + '?download=true';
+      const child = window.open('', '_blank');
+      const { context } = current;
 
-      let w = window.open('', '_blank');
-      if (current.context.model.dirty && !current.context.model.readOnly) {
-        return current.context.save().then(() => {
-          w.location.assign(url);
-        });
-      } else {
-        return new Promise((resolve, reject) => {
-          w.location.assign(url);
-        });
+      if (context.model.dirty && !context.model.readOnly) {
+        return context.save().then(() => { child.location.assign(url); });
       }
+
+      return new Promise<void>((resolve) => {
+        child.location.assign(url);
+        resolve(undefined);
+      });
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.restartClear, {
     label: 'Restart Kernel & Clear Outputs',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        const { notebook, session } = current;
+
+        return session.restart()
+          .then(() => { NotebookActions.clearAllOutputs(notebook); });
       }
-      return current.session.restart().then(() => {
-        NotebookActions.clearAllOutputs(current.notebook);
-      });
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.restartRunAll, {
     label: 'Restart Kernel & Run All',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        const { context, notebook, session } = current;
+
+        return session.restart()
+          .then(() => { NotebookActions.runAll(notebook, context.session); });
       }
-      return current.session.restart().then(() => {
-        NotebookActions.runAll(current.notebook, current.context.session);
-      });
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.clearAllOutputs, {
     label: 'Clear All Outputs',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.clearAllOutputs(current.notebook);
       }
-      return NotebookActions.clearAllOutputs(current.notebook);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.clearOutputs, {
     label: 'Clear Output(s)',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.clearOutputs(current.notebook);
       }
-      return NotebookActions.clearOutputs(current.notebook);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.interrupt, {
     label: 'Interrupt Kernel',
     execute: args => {
-      let current = getCurrent(args);
+      const current = getCurrent(args);
+
       if (!current) {
         return;
       }
-      let kernel = current.context.session.kernel;
+
+      const kernel = current.context.session.kernel;
+
       if (kernel) {
         return kernel.interrupt();
       }
@@ -684,298 +730,299 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.toCode, {
     label: 'Change to Code Cell Type',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.changeCellType(current.notebook, 'code');
       }
-      return NotebookActions.changeCellType(current.notebook, 'code');
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.toMarkdown, {
     label: 'Change to Markdown Cell Type',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.changeCellType(current.notebook, 'markdown');
       }
-      return NotebookActions.changeCellType(current.notebook, 'markdown');
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.toRaw, {
     label: 'Change to Raw Cell Type',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.changeCellType(current.notebook, 'raw');
       }
-      return NotebookActions.changeCellType(current.notebook, 'raw');
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.cut, {
     label: 'Cut Cell(s)',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.cut(current.notebook);
       }
-      return NotebookActions.cut(current.notebook);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.copy, {
     label: 'Copy Cell(s)',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.copy(current.notebook);
       }
-      return NotebookActions.copy(current.notebook);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.paste, {
     label: 'Paste Cell(s) Below',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.paste(current.notebook);
       }
-      return NotebookActions.paste(current.notebook);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.deleteCell, {
     label: 'Delete Cell(s)',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.deleteCells(current.notebook);
       }
-      return NotebookActions.deleteCells(current.notebook);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.split, {
     label: 'Split Cell',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.splitCell(current.notebook);
       }
-      return NotebookActions.splitCell(current.notebook);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.merge, {
     label: 'Merge Selected Cell(s)',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.mergeCells(current.notebook);
       }
-      return NotebookActions.mergeCells(current.notebook);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.insertAbove, {
     label: 'Insert Cell Above',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.insertAbove(current.notebook);
       }
-      return NotebookActions.insertAbove(current.notebook);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.insertBelow, {
     label: 'Insert Cell Below',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.insertBelow(current.notebook);
       }
-      return NotebookActions.insertBelow(current.notebook);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.selectAbove, {
     label: 'Select Cell Above',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.selectAbove(current.notebook);
       }
-      return NotebookActions.selectAbove(current.notebook);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.selectBelow, {
     label: 'Select Cell Below',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.selectBelow(current.notebook);
       }
-      return NotebookActions.selectBelow(current.notebook);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.extendAbove, {
     label: 'Extend Selection Above',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.extendSelectionAbove(current.notebook);
       }
-      return NotebookActions.extendSelectionAbove(current.notebook);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.extendBelow, {
     label: 'Extend Selection Below',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.extendSelectionBelow(current.notebook);
       }
-      return NotebookActions.extendSelectionBelow(current.notebook);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.moveUp, {
     label: 'Move Cell(s) Up',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.moveUp(current.notebook);
       }
-      return NotebookActions.moveUp(current.notebook);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.moveDown, {
     label: 'Move Cell(s) Down',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.moveDown(current.notebook);
       }
-      return NotebookActions.moveDown(current.notebook);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.toggleLines, {
     label: 'Toggle Line Numbers',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.toggleLineNumbers(current.notebook);
       }
-      return NotebookActions.toggleLineNumbers(current.notebook);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.toggleAllLines, {
     label: 'Toggle All Line Numbers',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+      if (current) {
+        return NotebookActions.toggleAllLineNumbers(current.notebook);
       }
-      return NotebookActions.toggleAllLineNumbers(current.notebook);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.commandMode, {
     label: 'Enter Command Mode',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        current.notebook.mode = 'command';
       }
-      return current.notebook.mode = 'command';
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.editMode, {
     label: 'Enter Edit Mode',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        current.notebook.mode = 'edit';
       }
-      current.notebook.mode = 'edit';
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.undo, {
     label: 'Undo Cell Operation',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.undo(current.notebook);
       }
-      return NotebookActions.undo(current.notebook);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.redo, {
     label: 'Redo Cell Operation',
     execute: args => {
-      let current = getCurrent(args);
+      const current = getCurrent(args);
+
       if (!current) {
-        return;
+        return NotebookActions.redo(current.notebook);
       }
-      return NotebookActions.redo(current.notebook);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.changeKernel, {
     label: 'Change Kernel',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return current.context.session.selectKernel();
       }
-      return current.context.session.selectKernel();
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.reconnectToKernel, {
     label: 'Reconnect To Kernel',
     execute: args => {
-      let current = getCurrent(args);
+      const current = getCurrent(args);
+
       if (!current) {
         return;
       }
-      let kernel = current.context.session.kernel;
-      if (!kernel) {
-        return;
+
+      const kernel = current.context.session.kernel;
+
+      if (kernel) {
+        return kernel.reconnect();
       }
-      return kernel.reconnect();
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.createConsole, {
     label: 'Create Console for Notebook',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
-      }
-      let widget = tracker.currentWidget;
-      if (!widget) {
+      const current = getCurrent(args);
+      const widget = tracker.currentWidget;
+
+      if (!current || !widget) {
         return;
       }
-      let options: ReadonlyJSONObject = {
+
+      const options: ReadonlyJSONObject = {
         path: widget.context.path,
         preferredLanguage: widget.context.model.defaultKernelLanguage,
         activate: args['activate']
       };
+
       return commands.execute('console:create', options);
     },
     isEnabled: hasWidget
@@ -983,154 +1030,154 @@ function addCommands(app: JupyterLab, services: ServiceManager, tracker: Noteboo
   commands.addCommand(CommandIDs.markdown1, {
     label: 'Change to Heading 1',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.setMarkdownHeader(current.notebook, 1);
       }
-      return NotebookActions.setMarkdownHeader(current.notebook, 1);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.markdown2, {
     label: 'Change to Heading 2',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.setMarkdownHeader(current.notebook, 2);
       }
-      return NotebookActions.setMarkdownHeader(current.notebook, 2);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.markdown3, {
     label: 'Change to Heading 3',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.setMarkdownHeader(current.notebook, 3);
       }
-      return NotebookActions.setMarkdownHeader(current.notebook, 3);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.markdown4, {
     label: 'Change to Heading 4',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.setMarkdownHeader(current.notebook, 4);
       }
-      return NotebookActions.setMarkdownHeader(current.notebook, 4);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.markdown5, {
     label: 'Change to Heading 5',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.setMarkdownHeader(current.notebook, 5);
       }
-      return NotebookActions.setMarkdownHeader(current.notebook, 5);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.markdown6, {
     label: 'Change to Heading 6',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.setMarkdownHeader(current.notebook, 6);
       }
-      return NotebookActions.setMarkdownHeader(current.notebook, 6);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.hideCode, {
     label: 'Hide Code',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.hideCode(current.notebook);
       }
-      return NotebookActions.hideCode(current.notebook);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.showCode, {
     label: 'Show Code',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.showCode(current.notebook);
       }
-      return NotebookActions.showCode(current.notebook);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.hideAllCode, {
     label: 'Hide All Code',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.hideAllCode(current.notebook);
       }
-      return NotebookActions.hideAllCode(current.notebook);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.showAllCode, {
     label: 'Show All Code',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.showAllCode(current.notebook);
       }
-      return NotebookActions.showAllCode(current.notebook);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.hideOutput, {
     label: 'Hide Output',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.hideOutput(current.notebook);
       }
-      return NotebookActions.hideOutput(current.notebook);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.showOutput, {
     label: 'Show Output',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.showOutput(current.notebook);
       }
-      return NotebookActions.showOutput(current.notebook);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.hideAllOutputs, {
     label: 'Hide All Outputs',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.hideAllOutputs(current.notebook);
       }
-      return NotebookActions.hideAllOutputs(current.notebook);
     },
     isEnabled: hasWidget
   });
   commands.addCommand(CommandIDs.showAllOutputs, {
     label: 'Show All Outputs',
     execute: args => {
-      let current = getCurrent(args);
-      if (!current) {
-        return;
+      const current = getCurrent(args);
+
+      if (current) {
+        return NotebookActions.showAllOutputs(current.notebook);
       }
-      return NotebookActions.showAllOutputs(current.notebook);
     },
     isEnabled: hasWidget
   });
@@ -1221,7 +1268,7 @@ function createMenu(app: JupyterLab): Menu {
   settings.title.label = 'Settings';
   settings.addItem({ command: CommandIDs.toggleAllLines });
 
-  exportTo.title.label = "Export to ...";
+  exportTo.title.label = 'Export to ...';
   EXPORT_TO_FORMATS.forEach(exportToFormat => {
     exportTo.addItem({ command: CommandIDs.exportToFormat, args: exportToFormat });
   });