Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linting #52

Draft
wants to merge 17 commits into
base: dev
Choose a base branch
from
37 changes: 25 additions & 12 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
{
"root": true,
"extends": [
"plugin:react/recommended",
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:import/errors",
"plugin:import/warnings",
"prettier/@typescript-eslint", // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
"plugin:react/recommended",
"prettier/react",
"prettier/standard",
"plugin:prettier/recommended" // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.

],
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint",
"jsdoc",
"import",
"prettier"
"prettier",
"react-hooks"
],
"parserOptions": {
"project": ["tsconfig.json"],
Expand All @@ -26,20 +31,28 @@
"ecmaVersion": 2020 // Allows for the parsing of modern ECMAScript features
},
"rules": {
"react/forbid-prop-types": "off",
"react/jsx-filename-extension": "off",
"react/no-string-refs": "off",
"react/require-default-props": "off",
"react-hooks/rules-of-hooks": "error", // Checks rules of Hooks
"react-hooks/exhaustive-deps": "warn", // Checks effect dependencies,

"@typescript-eslint/explicit-function-return-type": "off",
"no-console": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-unnecessary-type-assertion": "off",
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"@typescript-eslint/require-await": "off",

// "comma-dangle": ["error", "never"],
"object-curly-spacing": ["error", "always"],
"default-case": "off",
"import/extensions": "off",
"no-constant-condition": ["error", { "checkLoops": false }],
"no-param-reassign": "off",
"no-restricted-syntax": "off",
"no-underscore-dangle": "off",
"default-case": "off",
"react/jsx-closing-tag-location": "off",
"import/extensions": "off",
"@typescript-eslint/explicit-module-boundary-types": "off"
"prettier/prettier": "error"
},
"settings": {
"import/resolver": {
Expand Down
10 changes: 6 additions & 4 deletions fake-runtime/FakeRuntime.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable */

/*
* Fake Runtime is not handled by webpack like most of the other JS code but instead
* will be run "as is" as a child-process of the rest of the application.
Expand Down Expand Up @@ -53,7 +55,7 @@ class FakeRuntime {
});
this.tcpServer.listen(TCP_PORT, () => {
print('server bound');
})
});

setInterval(this.onInterval, MSGINTERVAL);
}
Expand Down Expand Up @@ -82,13 +84,13 @@ class FakeRuntime {
// sensor('Ignored', 5, [param('is_unsafe', 'bool', Math.random() < 0.5), param('v_batt', 'float', randomFloat(0, 15))], 0),
],
};
}
};

onInterval = () => {
const fakeData: DevData = this.generateFakeData();
this.sendSocket.send(DevData.encode(fakeData).finish(), UDP_SEND_PORT, 'localhost');
// TODO: Handle TCP writes to console
}
};
}

new FakeRuntime(); // eslint-disable-line no-new
new FakeRuntime(); // eslint-disable-line no-new
10 changes: 5 additions & 5 deletions main/MenuTemplate/DawnMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ const DawnMenu: MenuItemConstructorOptions = {
accelerator: 'CommandOrControl+Q',
click() {
app.quit();
},
}
},
{
label: 'Field Control Mode',
click() {
RendererBridge.reduxDispatch({
type: 'TOGGLE_FIELD_CONTROL',
type: 'TOGGLE_FIELD_CONTROL'
});
},
},
],
}
}
]
};

export default DawnMenu;
29 changes: 15 additions & 14 deletions main/MenuTemplate/DebugMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ const DebugMenu: MenuItemConstructorOptions = {
RendererBridge.registeredWindow.webContents.toggleDevTools();
}
},
accelerator: 'CommandOrControl+alt+I',
accelerator: 'CommandOrControl+alt+I'
},
{
label: 'Restart Runtime',
click() {
RendererBridge.reduxDispatch({
type: 'RESTART_RUNTIME',
type: 'RESTART_RUNTIME'
});
},
}
},
{
label: 'Restart FC',
Expand All @@ -42,15 +42,15 @@ const DebugMenu: MenuItemConstructorOptions = {
} else {
console.log('Field Control not active');
}
},
}
},
{
label: 'Toggle Console Autoscroll',
click() {
RendererBridge.reduxDispatch({
type: 'TOGGLE_SCROLL',
type: 'TOGGLE_SCROLL'
});
},
}
},

{
Expand All @@ -60,30 +60,31 @@ const DebugMenu: MenuItemConstructorOptions = {
if (RendererBridge.registeredWindow) {
RendererBridge.registeredWindow.reload();
}
},
}
},

{
label: 'Full Stack Timestamp',
click() {
RendererBridge.reduxDispatch({
type: 'TIMESTAMP_CHECK',
type: 'TIMESTAMP_CHECK'
});
},
},
],
}
}
]
};

if (process.env.NODE_ENV === 'development') {
(DebugMenu.submenu as MenuItemConstructorOptions[]).push({ // Need to type cast since submenu's type isn't always array
(DebugMenu.submenu as MenuItemConstructorOptions[]).push({
// Need to type cast since submenu's type isn't always array
label: 'Toggle Fake Runtime',
click() {
if (fakeRuntime) {
killFakeRuntime();
} else {
fakeRuntime = fork('./fake-runtime/FakeRuntime.ts', [], { execArgv: ['-r', 'ts-node/register']});
fakeRuntime = fork('./fake-runtime/FakeRuntime.ts', [], { execArgv: ['-r', 'ts-node/register'] });
}
},
}
});
}

Expand Down
12 changes: 6 additions & 6 deletions main/MenuTemplate/EditMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@
* Defines the edit menu.
*/

import { MenuItemConstructorOptions } from "electron";
import { MenuItemConstructorOptions } from 'electron';

const EditMenu: MenuItemConstructorOptions = {
label: 'Edit',
submenu: [
{
label: 'Cut',
accelerator: 'CommandOrControl+X',
role: 'cut',
role: 'cut'
},
{
label: 'Copy',
accelerator: 'CommandOrControl+C',
role: 'copy',
role: 'copy'
},
{
label: 'Paste',
accelerator: 'CommandOrControl+V',
role: 'paste',
},
],
role: 'paste'
}
]
};

export default EditMenu;
18 changes: 7 additions & 11 deletions main/MenuTemplate/FileMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
*/

import RendererBridge from '../RendererBridge';
import {
openFile,
saveFile,
createNewFile,
} from '../../renderer/actions/EditorActions';
import { openFile, saveFile, createNewFile } from '../../renderer/actions/EditorActions';
import { MenuItemConstructorOptions } from 'electron';

const FileMenu: MenuItemConstructorOptions = {
Expand All @@ -18,30 +14,30 @@ const FileMenu: MenuItemConstructorOptions = {
click() {
RendererBridge.reduxDispatch(createNewFile());
},
accelerator: 'CommandOrControl+N',
accelerator: 'CommandOrControl+N'
},
{
label: 'Open file',
click() {
RendererBridge.reduxDispatch(openFile());
},
accelerator: 'CommandOrControl+O',
accelerator: 'CommandOrControl+O'
},
{
label: 'Save file',
click() {
RendererBridge.reduxDispatch(saveFile());
},
accelerator: 'CommandOrControl+S',
accelerator: 'CommandOrControl+S'
},
{
label: 'Save file as',
click() {
RendererBridge.reduxDispatch(saveFile(true));
},
accelerator: 'CommandOrControl+Shift+S',
},
],
accelerator: 'CommandOrControl+Shift+S'
}
]
};

export default FileMenu;
8 changes: 4 additions & 4 deletions main/MenuTemplate/HelpMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ const HelpMenu: MenuItemConstructorOptions = {
RendererBridge.registeredWindow.webContents.send('start-interactive-tour');
}
},
accelerator: 'CommandOrControl+T',
accelerator: 'CommandOrControl+T'
},
{
label: 'PiE API',
click() {
showAPI();
},
accelerator: 'CommandOrControl+P',
},
],
accelerator: 'CommandOrControl+P'
}
]
};

export default HelpMenu;
8 changes: 1 addition & 7 deletions main/MenuTemplate/Template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ import FileMenu from './FileMenu';
import DebugMenu from './DebugMenu';
import HelpMenu from './HelpMenu';

const Template = [
DawnMenu,
FileMenu,
EditMenu,
DebugMenu,
HelpMenu,
];
const Template = [DawnMenu, FileMenu, EditMenu, DebugMenu, HelpMenu];

export default Template;
8 changes: 3 additions & 5 deletions main/RendererBridge.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { BrowserWindow } from 'electron';

/**
* RendererBridge connects the main process to the renderer's Redux flow.
* Maintains a real-time copy of the renderer's Redux state in the main process, and
* allows the main process to dispatch redux actions to the renderer.
*/

import _ from 'lodash';
import { BrowserWindow } from "electron";

class RendererBridge {
registeredWindow: BrowserWindow | null = null;

Expand All @@ -19,6 +17,6 @@ class RendererBridge {
this.registeredWindow.webContents.send('dispatch', action);
}
};
};
}

export default new RendererBridge();
Loading