Skip to content

Commit

Permalink
chore: npm run lint
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Apr 13, 2021
1 parent ea8251c commit 012b2b6
Show file tree
Hide file tree
Showing 45 changed files with 487 additions and 251 deletions.
28 changes: 21 additions & 7 deletions lib/code-manager.ts
Expand Up @@ -86,7 +86,9 @@ export function removeCommentsMarkdownCell(
text: string
): string {
const commentStartString = getCommentStartString(editor);
if (!commentStartString) return text;
if (!commentStartString) {
return text;
}
const lines = text.split("\n");
const editedLines = [];

Expand Down Expand Up @@ -118,15 +120,19 @@ export function escapeBlankRows(
endRow: number
) {
while (endRow > startRow) {
if (!isBlank(editor, endRow)) break;
if (!isBlank(editor, endRow)) {
break;
}
endRow -= 1;
}

return endRow;
}
export function getFoldRange(editor: TextEditor, row: number) {
const range = rowRangeForCodeFoldAtBufferRow(editor, row);
if (!range) return;
if (!range) {
return;
}

if (
range[1] < editor.getLastBufferRow() &&
Expand All @@ -140,7 +146,9 @@ export function getFoldRange(editor: TextEditor, row: number) {
}
export function getFoldContents(editor: TextEditor, row: number) {
const range = getFoldRange(editor, row);
if (!range) return;
if (!range) {
return;
}
return {
code: getRows(editor, range[0], range[1]),
row: range[1],
Expand Down Expand Up @@ -188,7 +196,9 @@ export function getCommentStartString(
}
export function getRegexString(editor: TextEditor) {
const commentStartString = getCommentStartString(editor);
if (!commentStartString) return null;
if (!commentStartString) {
return null;
}
const escapedCommentStartString = escapeStringRegexp(commentStartString);
const regexString = `${escapedCommentStartString} *%% *(md|markdown)?| *<(codecell|md|markdown)>| *(In\[[0-9 ]*\])`;
return regexString;
Expand Down Expand Up @@ -272,7 +282,9 @@ function getCurrentFencedCodeBlock(editor: TextEditor) {
let start = cursor.row;
let end = cursor.row;
const scope = getEmbeddedScope(editor, cursor);
if (!scope) return getCell(editor);
if (!scope) {
return getCell(editor);
}

while (start > 0 && isEmbeddedCode(editor, scope, start - 1)) {
start -= 1;
Expand Down Expand Up @@ -339,7 +351,9 @@ export function moveDown(editor: TextEditor, row: number) {

while (row < lastRow) {
row += 1;
if (!isBlank(editor, row)) break;
if (!isBlank(editor, row)) {
break;
}
}

editor.setCursorBufferPosition({
Expand Down
2 changes: 1 addition & 1 deletion lib/commands.ts
Expand Up @@ -26,7 +26,7 @@ export function toggleInspector(store: store) {
kernel.inspect(
code,
cursorPos,
(result: { data: Record<string, any>; found: Boolean }) => {
(result: { data: Record<string, any>; found: boolean }) => {
log("Inspector: Result:", result);

if (!result.found) {
Expand Down
8 changes: 5 additions & 3 deletions lib/components/inspector.tsx
@@ -1,8 +1,8 @@
import React from "react";
import { observer } from "mobx-react";
import { RichMedia, Media } from "@nteract/outputs";
import { INSPECTOR_URI } from "./../utils";
import type Kernel from "./../kernel";
import { INSPECTOR_URI } from "../utils";
import type Kernel from "../kernel";
import Markdown from "./result-view/markdown";
type Props = {
store: {
Expand All @@ -16,7 +16,9 @@ function hide() {
}

const Inspector = observer(({ store: { kernel } }: Props) => {
if (!kernel) return hide();
if (!kernel) {
return hide();
}
const bundle = kernel.inspector.bundle;

if (
Expand Down
22 changes: 12 additions & 10 deletions lib/components/kernel-monitor.tsx
@@ -1,6 +1,6 @@
import React from "react";
import ReactTable from "react-table";
import { ReactTableDefaults } from "react-table";
import ReactTable, { ReactTableDefaults } from "react-table";

import { observer } from "mobx-react";
import _ from "lodash";
import tildify from "tildify";
Expand Down Expand Up @@ -43,7 +43,9 @@ const openUnsavedEditor = (filePath: string) => {
});
// This path won't happen after https://github.com/nteract/hydrogen/pull/1662 since every deleted
// editors would be deleted from `store.kernelMapping`. Just kept here for safety.
if (!editor) return;
if (!editor) {
return;
}
atom.workspace.open(editor, {
searchAllPanes: true,
});
Expand Down Expand Up @@ -75,7 +77,7 @@ const kernelInfoCell = (props: KernelInfo) => {
className="icon"
onClick={showKernelSpec.bind(this, kernelSpec)}
title="Show kernel spec"
key={displayName + "kernelInfo"}
key={`${displayName}kernelInfo`}
>
{displayName}
</a>
Expand Down Expand Up @@ -114,7 +116,7 @@ const KernelMonitor = observer(({ store }: { store: store }) => {
executionCount: kernel.executionCount,
lastExecutionTime: kernel.lastExecutionTime,
kernelKey: {
kernel: kernel,
kernel,
key: String(key),
},
files: store.getFilesForKernel(kernel),
Expand Down Expand Up @@ -164,19 +166,19 @@ const KernelMonitor = observer(({ store }: { store: store }) => {
className="icon icon-zap"
onClick={interrupt.bind(this, kernel)}
title="Interrupt kernel"
key={key + "interrupt"}
key={`${key}interrupt`}
/>,
<a
className="icon icon-sync"
onClick={restart.bind(this, kernel)}
title="Restart kernel"
key={key + "restart"}
key={`${key}restart`}
/>,
<a
className="icon icon-trashcan"
onClick={shutdown.bind(this, kernel)}
title="Shutdown kernel"
key={key + "shutdown"}
key={`${key}shutdown`}
/>,
];
},
Expand All @@ -192,15 +194,15 @@ const KernelMonitor = observer(({ store }: { store: store }) => {
<a
onClick={openUnsavedEditor.bind(this, filePath)}
title="Jump to file"
key={filePath + "jump"}
key={`${filePath}jump`}
>
{filePath}
</a>
) : (
<a
onClick={openEditor.bind(this, filePath)}
title="Jump to file"
key={filePath + "jump"}
key={`${filePath}jump`}
>
{tildify(filePath)}
</a>
Expand Down
6 changes: 4 additions & 2 deletions lib/components/output-area.tsx
Expand Up @@ -6,7 +6,7 @@ import { observer } from "mobx-react";
import Anser from "anser";
import History from "./result-view/history";
import ScrollList from "./result-view/list";
import { OUTPUT_AREA_URI, EmptyMessage } from "./../utils";
import { OUTPUT_AREA_URI, EmptyMessage } from "../utils";
type store = typeof import("../store").default;

@observer
Expand Down Expand Up @@ -39,7 +39,9 @@ class OutputArea extends React.Component<{

handleClick = () => {
const kernel = this.props.store.kernel;
if (!kernel || !kernel.outputStore) return;
if (!kernel || !kernel.outputStore) {
return;
}
const output = kernel.outputStore.outputs[kernel.outputStore.index];
const copyOutput = this.getOutputText(output);

Expand Down
8 changes: 4 additions & 4 deletions lib/components/result-view/index.tsx
Expand Up @@ -2,11 +2,11 @@ import { CompositeDisposable, TextEditor, DisplayMarker } from "atom";
import React from "react";
import { Provider } from "@nteract/mathjax";
import { mathJaxPath } from "mathjax-electron";
import { reactFactory } from "./../../utils";
import OutputStore from "./../../store/output";
import { reactFactory } from "../../utils";
import OutputStore from "../../store/output";
import ResultViewComponent from "./result-view";
import type MarkerStore from "./../../store/markers";
import type Kernel from "./../../kernel";
import type MarkerStore from "../../store/markers";
import type Kernel from "../../kernel";
export default class ResultView {
disposer: CompositeDisposable;
marker: DisplayMarker;
Expand Down
8 changes: 6 additions & 2 deletions lib/components/result-view/list.tsx
Expand Up @@ -10,7 +10,9 @@ class ScrollList extends React.Component<Props> {
el: HTMLElement | null | undefined;

scrollToBottom() {
if (!this.el) return;
if (!this.el) {
return;
}
const scrollHeight = this.el.scrollHeight;
const height = this.el.clientHeight;
const maxScrollTop = scrollHeight - height;
Expand All @@ -26,7 +28,9 @@ class ScrollList extends React.Component<Props> {
}

render() {
if (this.props.outputs.length === 0) return null;
if (this.props.outputs.length === 0) {
return null;
}
return (
<div
className="scroll-list multiline-container native-key-bindings"
Expand Down
30 changes: 19 additions & 11 deletions lib/components/result-view/result-view.tsx
Expand Up @@ -4,8 +4,8 @@ import { observer } from "mobx-react";
import { action, observable } from "mobx";
import Display from "./display";
import Status from "./status";
import type OutputStore from "./../../store/output";
import type Kernel from "./../../kernel";
import type OutputStore from "../../store/output";
import type Kernel from "../../kernel";
const SCROLL_HEIGHT = 600;
type Props = {
store: OutputStore;
Expand All @@ -23,7 +23,9 @@ class ResultViewComponent extends React.Component<Props> {
@observable
expanded: boolean = false;
getAllText = () => {
if (!this.el) return "";
if (!this.el) {
return "";
}
return this.el.innerText ? this.el.innerText : "";
};
handleClick = (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
Expand Down Expand Up @@ -55,7 +57,9 @@ class ResultViewComponent extends React.Component<Props> {
element: HTMLElement | null | undefined,
comp: CompositeDisposable
) => {
if (!element || !comp.disposables || comp.disposables.size > 0) return;
if (!element || !comp.disposables || comp.disposables.size > 0) {
return;
}
comp.add(
atom.tooltips.add(element, {
title: `Click to copy,
Expand All @@ -69,7 +73,9 @@ class ResultViewComponent extends React.Component<Props> {
element: HTMLElement | null | undefined,
comp: CompositeDisposable
) => {
if (!element || !comp.disposables || comp.disposables.size > 0) return;
if (!element || !comp.disposables || comp.disposables.size > 0) {
return;
}
comp.add(
atom.tooltips.add(element, {
title: this.props.store.executionCount
Expand Down Expand Up @@ -132,10 +138,9 @@ class ResultViewComponent extends React.Component<Props> {

return (
<div
className={
(isPlain ? "inline-container" : "multiline-container") +
" native-key-bindings"
}
className={`${
isPlain ? "inline-container" : "multiline-container"
} native-key-bindings`}
tabIndex={-1}
onClick={isPlain ? this.checkForSelection : undefined}
style={
Expand All @@ -152,7 +157,9 @@ class ResultViewComponent extends React.Component<Props> {
<div
className="hydrogen_cell_display"
ref={(ref) => {
if (!ref) return;
if (!ref) {
return;
}
this.el = ref;
isPlain
? this.addCopyTooltip(ref, this.containerTooltip)
Expand Down Expand Up @@ -216,8 +223,9 @@ class ResultViewComponent extends React.Component<Props> {
this.expanded === true ||
this.props.store.isPlain === true ||
atom.config.get(`Hydrogen.autoScroll`) === false
)
) {
return;
}
const scrollHeight = this.el.scrollHeight;
const height = this.el.clientHeight;
const maxScrollTop = scrollHeight - height;
Expand Down
2 changes: 1 addition & 1 deletion lib/components/watch-sidebar/index.tsx
Expand Up @@ -3,7 +3,7 @@ import React from "react";
import { observer } from "mobx-react";
import Watch from "./watch";
import { WATCHES_URI, EmptyMessage } from "../../utils";
import type Kernel from "./../../kernel";
import type Kernel from "../../kernel";
type store = typeof import("../../store").default;
const Watches = observer(({ store: { kernel } }: { store: store }) => {
if (!kernel) {
Expand Down
8 changes: 5 additions & 3 deletions lib/components/watch-sidebar/watch.tsx
@@ -1,15 +1,17 @@
import React from "react";
import { CompositeDisposable } from "atom";
import History from "./../result-view/history";
import type WatchStore from "./../../store/watch";
import History from "../result-view/history";
import type WatchStore from "../../store/watch";
export default class Watch extends React.Component<{
store: WatchStore;
}> {
container: HTMLElement | null | undefined;
subscriptions: CompositeDisposable = new CompositeDisposable();

componentDidMount() {
if (!this.container) return;
if (!this.container) {
return;
}
const container = this.container;
container.insertBefore(
this.props.store.editor.element,
Expand Down
4 changes: 3 additions & 1 deletion lib/config.ts
@@ -1,7 +1,9 @@
const Config = {
getJson(key: string, _default: Record<string, any> = {}) {
const value = atom.config.get(`Hydrogen.${key}`);
if (!value || typeof value !== "string") return _default;
if (!value || typeof value !== "string") {
return _default;
}

try {
return JSON.parse(value);
Expand Down

0 comments on commit 012b2b6

Please sign in to comment.