From c1f0bb8df7facfede5d5ee79ef3ab689ca57e68f Mon Sep 17 00:00:00 2001 From: Janik Piepenhagen Date: Sun, 16 Jun 2024 17:48:20 +0200 Subject: [PATCH] Fixed lint issues --- README.md | 2 +- src/main/index.ts | 2 ++ src/main/logger.ts | 22 +++++++++---------- src/main/preload.ts | 14 ++++++------ src/renderer/app.tsx | 4 ++-- src/renderer/components/macros/MacroTree.tsx | 3 +-- .../components/macros/MacroTreeItem.tsx | 2 +- .../connection/ConnectionSettingsDialog.tsx | 14 ++++++------ .../menu/general/GeneralSettingsDialog.tsx | 8 +++---- .../menu/general/LanguageSelect.tsx | 4 ++-- src/renderer/components/output/ActionBar.tsx | 20 ++++++++--------- .../components/output/ContextMenuOutput.tsx | 4 ++-- .../components/output/OutputDataTableCore.tsx | 10 ++++----- .../components/output/OutputTabView.tsx | 2 +- .../components/output/OutputTextArea.tsx | 2 +- .../components/output/TransmitDataTable.tsx | 2 +- .../components/tools/BaudRateSelect.tsx | 4 ++-- src/renderer/components/tools/ButtonClear.tsx | 8 +++---- src/renderer/components/tools/PortSelect.tsx | 6 ++--- .../components/tools/SequenceInput.tsx | 2 +- src/renderer/types/AppInterfaces.ts | 4 ++-- src/services/FormatService.ts | 4 ++-- 22 files changed, 72 insertions(+), 71 deletions(-) diff --git a/README.md b/README.md index c1edc99..bd553a2 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ See docs and guides for [electron-forge](https://js.electronforge.io/) MIT © [Minterm](https://github.com/peace317/minterm) -[github-actions-status]: https://github.com/peace317/minterm/workflows/Test/badge.svg +[github-actions-status]: https://github.com/peace317/minterm/workflows/Build%20and%20Test/badge.svg [github-actions-url]: https://github.com/peace317/minterm/actions [github-tag-image]: https://img.shields.io/github/v/tag/peace317/minterm.svg?label=version [github-tag-url]: https://github.com/peace317/minterm/releases/latest diff --git a/src/main/index.ts b/src/main/index.ts index 97992d2..48c993d 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -83,6 +83,8 @@ const createWindow = (): void => { | "system" | "light" | "dark"; + + new AppUpdater(); }; // This method will be called when Electron has finished diff --git a/src/main/logger.ts b/src/main/logger.ts index 25d1f1b..0cb2caa 100644 --- a/src/main/logger.ts +++ b/src/main/logger.ts @@ -7,28 +7,28 @@ import { format } from 'util'; export default class ElectronLogger { init(): void { - ipcMain.on(IPCChannelType.DEBUG, (event, arg) => { - log.debug(this.buildLogString(arg)); + ipcMain.on(IPCChannelType.DEBUG, (event, args) => { + log.debug(this.buildLogString(args)); }); - ipcMain.on(IPCChannelType.INFO, async (event, arg) => { - log.info(this.buildLogString(arg)); + ipcMain.on(IPCChannelType.INFO, async (event, args) => { + log.info(this.buildLogString(args)); }); - ipcMain.on(IPCChannelType.LOG, async (event, arg) => { - log.log(this.buildLogString(arg)); + ipcMain.on(IPCChannelType.LOG, async (event, args) => { + log.log(this.buildLogString(args)); }); - ipcMain.on(IPCChannelType.WARN, async (event, arg) => { - log.warn(this.buildLogString(arg)); + ipcMain.on(IPCChannelType.WARN, async (event, args) => { + log.warn(this.buildLogString(args)); }); - ipcMain.on(IPCChannelType.ERROR, async (event, arg) => { - log.error(this.buildLogString(arg)); + ipcMain.on(IPCChannelType.ERROR, async (event, args) => { + log.error(this.buildLogString(args)); }); } - public buildLogString(data: any): any { + public buildLogString(data: unknown[]): string { let res = ''; const msgData = data[0] as LogMessage; if (msgData !== undefined) { diff --git a/src/main/preload.ts b/src/main/preload.ts index e142ae9..2494f02 100644 --- a/src/main/preload.ts +++ b/src/main/preload.ts @@ -25,7 +25,7 @@ const electronHandler = { }, removeListener( channel: IPCChannelType, - listener: (...args: any[]) => void + listener: (...args: unknown[]) => void ) { const cnt = ipcRenderer.listenerCount(channel); ipcRenderer.removeListener(channel, listener); @@ -41,24 +41,24 @@ const electronHandler = { get(key: StoreKey) { return ipcRenderer.sendSync(IPCChannelType.STORE_GET, key); }, - set(key: StoreKey, val: any) { + set(key: StoreKey, val: unknown) { ipcRenderer.send(IPCChannelType.STORE_SET, key, val); }, }, logger: { - log(...params: any[]) { + log(...params: unknown[]) { ipcRenderer.send(IPCChannelType.LOG, params); }, - info(...params: any[]) { + info(...params: unknown[]) { ipcRenderer.send(IPCChannelType.INFO, params); }, - debug(...params: any[]) { + debug(...params: unknown[]) { ipcRenderer.send(IPCChannelType.DEBUG, params); }, - error(...params: any[]) { + error(...params: unknown[]) { ipcRenderer.send(IPCChannelType.ERROR, params); }, - warn(...params: any[]) { + warn(...params: unknown[]) { ipcRenderer.send(IPCChannelType.WARN, params); }, }, diff --git a/src/renderer/app.tsx b/src/renderer/app.tsx index 274952f..4e74f13 100644 --- a/src/renderer/app.tsx +++ b/src/renderer/app.tsx @@ -4,7 +4,7 @@ import TransmitDataTable from "@/renderer//components/output/TransmitDataTable"; import MacroTree from "@/renderer/components/macros/MacroTree"; import MenuBar from "@/renderer/components/menu/MenuBar"; import clsx from "clsx"; -import i18n from "i18next"; +import { use } from "i18next"; import "primeflex/primeflex.scss"; import "primeicons/primeicons.css"; import "primereact/resources/primereact.min.css"; @@ -31,7 +31,7 @@ declare global { } } -i18n.use(initReactI18next).init({ +use(initReactI18next).init({ resources: { en: { translation: messageTextEn }, de: { translation: messageTextDe }, diff --git a/src/renderer/components/macros/MacroTree.tsx b/src/renderer/components/macros/MacroTree.tsx index d82f57a..69b273e 100644 --- a/src/renderer/components/macros/MacroTree.tsx +++ b/src/renderer/components/macros/MacroTree.tsx @@ -6,8 +6,7 @@ import { MenuItem } from "primereact/menuitem"; import { Tree, TreeDragDropEvent, - TreeExpandedKeysType, - TreeNodeTemplateOptions, + TreeExpandedKeysType } from "primereact/tree"; import { TreeNode } from "primereact/treenode"; import React, { useEffect, useRef, useState } from "react"; diff --git a/src/renderer/components/macros/MacroTreeItem.tsx b/src/renderer/components/macros/MacroTreeItem.tsx index 1669b5a..63ede36 100644 --- a/src/renderer/components/macros/MacroTreeItem.tsx +++ b/src/renderer/components/macros/MacroTreeItem.tsx @@ -69,7 +69,7 @@ const MacroTreeItem: React.FC = ({ if (clickInTextField) setClickInTextField(false); }, [clickForCommit]); - const onKeyPressed = (e: any) => { + const onKeyPressed = (e: React.KeyboardEvent) => { if (e.key === 'Enter') { renameNode(); removeListener(); diff --git a/src/renderer/components/menu/connection/ConnectionSettingsDialog.tsx b/src/renderer/components/menu/connection/ConnectionSettingsDialog.tsx index 2443f77..d2836e0 100644 --- a/src/renderer/components/menu/connection/ConnectionSettingsDialog.tsx +++ b/src/renderer/components/menu/connection/ConnectionSettingsDialog.tsx @@ -7,7 +7,7 @@ import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; import BaudRateSelect from '@/renderer/components/tools/BaudRateSelect'; import PortSelect from '@/renderer/components/tools/PortSelect'; -import { IDialogProps, ISelectValue, StoreKey } from '@minterm/types'; +import { IDialogProps, SelectValue, StoreKey } from '@minterm/types'; const ConnectionSettingsDialog: React.FC = ({ id, @@ -15,20 +15,20 @@ const ConnectionSettingsDialog: React.FC = ({ display, setDisplay, }) => { - const dataBitsOptions: Array = [ + const dataBitsOptions: Array = [ { name: '5', key: 5 }, { name: '6', key: 6 }, { name: '7', key: 7 }, { name: '8', key: 8 }, ]; - const stopBitsOptions: Array = [ + const stopBitsOptions: Array = [ { name: '1', key: 1 }, { name: '1.5', key: 1.5 }, { name: '2', key: 2 }, ]; - const parityOptions: Array = [ + const parityOptions: Array = [ { name: 'None', key: 'None' }, { name: 'Odd', key: 'Odd' }, { name: 'Even', key: 'Even' }, @@ -36,16 +36,16 @@ const ConnectionSettingsDialog: React.FC = ({ { name: 'Space', key: 'Space' }, ]; - const [dataBits, setDataBits] = useState( + const [dataBits, setDataBits] = useState( window.electron.store.get(StoreKey.SERIALPORT_DATA_BITS) ); - const [stopBits, setStopBits] = useState( + const [stopBits, setStopBits] = useState( window.electron.store.get(StoreKey.SERIALPORT_STOP_BITS) ); const [lock, setLock] = useState( window.electron.store.get(StoreKey.SERIALPORT_LOCK) ); - const [parity, setParity] = useState( + const [parity, setParity] = useState( window.electron.store.get(StoreKey.SERIALPORT_PARITY) ); const [rtscts, setRtscts] = useState( diff --git a/src/renderer/components/menu/general/GeneralSettingsDialog.tsx b/src/renderer/components/menu/general/GeneralSettingsDialog.tsx index fcdc3dd..a3546b3 100644 --- a/src/renderer/components/menu/general/GeneralSettingsDialog.tsx +++ b/src/renderer/components/menu/general/GeneralSettingsDialog.tsx @@ -1,4 +1,4 @@ -import i18n from 'i18next'; +import i18n, { changeLanguage } from 'i18next'; import { Button } from 'primereact/button'; import { ConfirmDialog, confirmDialog } from 'primereact/confirmdialog'; import { Dialog } from 'primereact/dialog'; @@ -21,7 +21,7 @@ const GeneralSettingsDialog: React.FC = ({ const [isRestartNecessary, setIsRestartNecessary] = useState(false); const toast = useRef(null); const [selectedLanguage, setSelectedLanguage] = useState(i18n.language); - const [selectedTheme, setSelectedTheme] = useState( + const [selectedTheme, setSelectedTheme] = useState( window.electron.store.get(StoreKey.THEME) ); @@ -42,7 +42,7 @@ const GeneralSettingsDialog: React.FC = ({ const onLanguageChange = (e: DropdownChangeEvent) => { setSelectedLanguage(e.value); - i18n.changeLanguage(e.value); + changeLanguage(e.value); }; const onHide = () => { @@ -52,7 +52,7 @@ const GeneralSettingsDialog: React.FC = ({ const onCancel = () => { onHide(); setSelectedTheme(window.electron.store.get(StoreKey.THEME)); - i18n.changeLanguage(window.electron.store.get(StoreKey.LANGUAGE)); + changeLanguage(window.electron.store.get(StoreKey.LANGUAGE)); setSelectedLanguage(window.electron.store.get(StoreKey.LANGUAGE)); setIsRestartNecessary(false); }; diff --git a/src/renderer/components/menu/general/LanguageSelect.tsx b/src/renderer/components/menu/general/LanguageSelect.tsx index e1a0661..170b2f6 100644 --- a/src/renderer/components/menu/general/LanguageSelect.tsx +++ b/src/renderer/components/menu/general/LanguageSelect.tsx @@ -2,7 +2,7 @@ import i18n from 'i18next'; import { Dropdown, DropdownChangeEvent } from 'primereact/dropdown'; import React from 'react'; import { useTranslation } from 'react-i18next'; -import { IDefaultProps, ISelectValue } from '@minterm/types'; +import { IDefaultProps, SelectValue } from '@minterm/types'; interface ILanguageSelectProps extends IDefaultProps { selectedLanguage: string; @@ -16,7 +16,7 @@ const LanguageSelect: React.FC = ({ onLanguageChange, }) => { const { t } = useTranslation(); - const languages: Array = i18n.languages.map((e) => ({ + const languages: Array = i18n.languages.map((e) => ({ name: t(e.toUpperCase()), key: e, })); diff --git a/src/renderer/components/output/ActionBar.tsx b/src/renderer/components/output/ActionBar.tsx index 2fabae6..7dfc56b 100644 --- a/src/renderer/components/output/ActionBar.tsx +++ b/src/renderer/components/output/ActionBar.tsx @@ -4,13 +4,13 @@ import { InputNumber } from 'primereact/inputnumber'; import { Tooltip } from 'primereact/tooltip'; import React from 'react'; import { useTranslation } from 'react-i18next'; -import { ConversionType, DataPointType, IDefaultProps } from '@minterm/types'; +import { ConversionType, DataPointType } from '@minterm/types'; import ButtonClear from '../tools/ButtonClear'; import { typeToSelectList } from '@minterm/services'; -export interface IActionBarProps extends IDefaultProps { +export interface ActionBarProps extends React.HTMLAttributes { data?: Array; - setData?: React.Dispatch>; + setData?: React.Dispatch>; dataCounterHidden?: boolean; dataCountLabel?: string; selectedConversions?: ConversionType[]; @@ -30,11 +30,10 @@ export interface IActionBarProps extends IDefaultProps { * outputting components. Therefore certain settings/actions will be displayed * equally when reusing this component. * - * @param IActionBarProps + * @param ActionBarProps */ -const ActionBar: React.FC = ({ +const ActionBar: React.FC = ({ id, - className, data = [], setData = () => {return;}, dataCounterHidden = true, @@ -47,6 +46,7 @@ const ActionBar: React.FC = ({ clearButtonToolTip = '', saveButtonHidden = true, onSave = () => {return;}, + ...props }) => { const { t } = useTranslation(); @@ -69,7 +69,7 @@ const ActionBar: React.FC = ({ }; return ( -
+
{!conversionsHidden && @@ -77,14 +77,14 @@ const ActionBar: React.FC = ({ return (
- +
); })} diff --git a/src/renderer/components/output/ContextMenuOutput.tsx b/src/renderer/components/output/ContextMenuOutput.tsx index 82ca27c..c6eed3d 100644 --- a/src/renderer/components/output/ContextMenuOutput.tsx +++ b/src/renderer/components/output/ContextMenuOutput.tsx @@ -3,13 +3,13 @@ import React, { useEffect, useRef } from 'react'; import { useTranslation } from 'react-i18next'; import { DataPointType } from '@minterm/types'; -interface IContextMenuOutputProps { +interface ContextMenuOutputProps { selectedCells: Array; onContextMenu: React.MouseEvent; data: Array; } -const ContextMenuOutput: React.FC = ({ +const ContextMenuOutput: React.FC = ({ data, selectedCells, onContextMenu, diff --git a/src/renderer/components/output/OutputDataTableCore.tsx b/src/renderer/components/output/OutputDataTableCore.tsx index ebc2f20..db93e20 100644 --- a/src/renderer/components/output/OutputDataTableCore.tsx +++ b/src/renderer/components/output/OutputDataTableCore.tsx @@ -4,14 +4,14 @@ import { DataTable, DataTableSelectionMultipleChangeEvent } from 'primereact/dat import React, { useEffect, useLayoutEffect, useRef, useState } from 'react'; import { useResizeDetector } from 'react-resize-detector'; import { ConversionType, DataPointType } from '@minterm/types'; -import ActionBar, { IActionBarProps } from './ActionBar'; +import ActionBar, { ActionBarProps } from './ActionBar'; -interface IOutputDataTableCoreProps extends IActionBarProps { +interface IOutputDataTableCoreProps extends ActionBarProps { data: Array; - setData?: React.Dispatch>; + setData?: React.Dispatch>; width?: number; - selectedCells?: Array; - setSelectedCells?: React.Dispatch>; + selectedCells?: Array; + setSelectedCells?: React.Dispatch>; } /** diff --git a/src/renderer/components/output/OutputTabView.tsx b/src/renderer/components/output/OutputTabView.tsx index 06a53f7..e1096de 100644 --- a/src/renderer/components/output/OutputTabView.tsx +++ b/src/renderer/components/output/OutputTabView.tsx @@ -11,7 +11,7 @@ import OutputLineChart from './OutputLineChart'; const OutputTabView: React.FC = ({ id, className }) => { const { t } = useTranslation(); - const [contextEvent, setContextEvent] = useState(); + const [contextEvent, setContextEvent] = useState>(); const { receivedData, setReceivedData } = useContext(); const [selectedCellsInTable, setSelectedCellsInTable] = useState>( [] diff --git a/src/renderer/components/output/OutputTextArea.tsx b/src/renderer/components/output/OutputTextArea.tsx index 56ca2ef..66e5b01 100644 --- a/src/renderer/components/output/OutputTextArea.tsx +++ b/src/renderer/components/output/OutputTextArea.tsx @@ -31,7 +31,7 @@ const OutputTextArea: React.FC = ({ const { t } = useTranslation(); const [topScrollable, setTopScrollable] = useState(false); const [downScrollable, setDownScrollable] = useState(false); - const { width, ref } = useResizeDetector({ + const { ref } = useResizeDetector({ onResize: () => { setScrollable(); }, diff --git a/src/renderer/components/output/TransmitDataTable.tsx b/src/renderer/components/output/TransmitDataTable.tsx index 98b4f03..4958059 100644 --- a/src/renderer/components/output/TransmitDataTable.tsx +++ b/src/renderer/components/output/TransmitDataTable.tsx @@ -10,7 +10,7 @@ import OutputDataTableCore from './OutputDataTableCore'; const TransmitDataTable: React.FC = ({ id, className }) => { const { t } = useTranslation(); const { transmittedData, setTransmittedData } = useContext(); - const [contextEvent, setContextEvent] = useState(); + const [contextEvent, setContextEvent] = useState>(); const [selectedCells, setSelectedCells] = useState>([]); const isContextEnabled = () => { diff --git a/src/renderer/components/tools/BaudRateSelect.tsx b/src/renderer/components/tools/BaudRateSelect.tsx index 6ca52da..310cc0c 100644 --- a/src/renderer/components/tools/BaudRateSelect.tsx +++ b/src/renderer/components/tools/BaudRateSelect.tsx @@ -2,10 +2,10 @@ import { Dropdown } from 'primereact/dropdown'; import React from 'react'; import { useTranslation } from 'react-i18next'; import { useContext } from '@/renderer/context'; -import { ISelectValue } from '@minterm/types'; +import { SelectValue } from '@minterm/types'; import clsx from 'clsx'; -const baudOptions: Array = [ +const baudOptions: Array = [ { name: '110', key: '110' }, { name: '300', key: '300' }, { name: '1200', key: '1200' }, diff --git a/src/renderer/components/tools/ButtonClear.tsx b/src/renderer/components/tools/ButtonClear.tsx index f7d229d..f356959 100644 --- a/src/renderer/components/tools/ButtonClear.tsx +++ b/src/renderer/components/tools/ButtonClear.tsx @@ -2,17 +2,17 @@ import React from 'react'; import { Button } from 'primereact/button'; import { VscTrash } from 'react-icons/vsc'; -interface IButtonClearProps extends React.HTMLAttributes { +interface ButtonClearProps extends React.HTMLAttributes { toolTip?: string; - clearObject?: React.Dispatch>; + clearObject?: React.Dispatch>; } /** * Component for a Button that clears the received data buffer. * - * @param IDefaultProps + * @param ButtonClearProps */ -const ButtonClear: React.FC = ({ +const ButtonClear: React.FC = ({ id, className, toolTip = '', diff --git a/src/renderer/components/tools/PortSelect.tsx b/src/renderer/components/tools/PortSelect.tsx index 893e9f6..f305bef 100644 --- a/src/renderer/components/tools/PortSelect.tsx +++ b/src/renderer/components/tools/PortSelect.tsx @@ -1,17 +1,17 @@ import { Dropdown } from 'primereact/dropdown'; import React, { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { IDefaultProps, ISelectValue } from '@minterm/types'; +import { IDefaultProps, SelectValue } from '@minterm/types'; import { useContext } from '@/renderer/context'; const PortSelect: React.FC = ({ id, className }) => { const { selectedPort, setPort, portList } = useContext(); const { t } = useTranslation(); - const [portOptions, setPorts] = useState>([]); + const [portOptions, setPorts] = useState>([]); useEffect(() => { - const selectablePorts: Array = []; + const selectablePorts: Array = []; if (portList !== undefined) { for (let i = 0; i < portList.length; i++) { if (portList[i].pnpId != undefined) { diff --git a/src/renderer/components/tools/SequenceInput.tsx b/src/renderer/components/tools/SequenceInput.tsx index d2c8094..b05cf67 100644 --- a/src/renderer/components/tools/SequenceInput.tsx +++ b/src/renderer/components/tools/SequenceInput.tsx @@ -98,7 +98,7 @@ const SequenceInput: React.FC = ({ SerialPortService.sendMessage(message, selectedEncoding); }; - const handleKeyDown = (event: any) => { + const handleKeyDown = (event: React.KeyboardEvent) => { if (event.key === 'Enter' && !sendButtonHidden) { onSend(); } diff --git a/src/renderer/types/AppInterfaces.ts b/src/renderer/types/AppInterfaces.ts index 134e383..719891f 100644 --- a/src/renderer/types/AppInterfaces.ts +++ b/src/renderer/types/AppInterfaces.ts @@ -16,7 +16,7 @@ export interface IDialogProps extends IDefaultProps { /** * Interface for a select-value that is to be used in dropdowns etc. */ -export interface ISelectValue { +export interface SelectValue { name: string; - key: any; + key: string | number; } diff --git a/src/services/FormatService.ts b/src/services/FormatService.ts index ec67f91..ccc84bd 100644 --- a/src/services/FormatService.ts +++ b/src/services/FormatService.ts @@ -1,4 +1,4 @@ -import { ISelectValue } from '@minterm/types'; +import { SelectValue } from '@minterm/types'; /** * Converts an ASCII string to a binary string. The binaries will be @@ -145,7 +145,7 @@ export const binArrayToAscii = (binaries: number[]): string => { export const typeToSelectList = (type: any) => { // eslint-disable-next-line @typescript-eslint/no-explicit-any return Object.keys(type).map((e: any) => { - const select: ISelectValue = { + const select: SelectValue = { name: type[e as keyof typeof type], key: type[e as keyof typeof type], };