From 9652b33e4dc33909cf6ddf4efd357bf58de283d8 Mon Sep 17 00:00:00 2001 From: Piotr Rogowski Date: Tue, 6 Apr 2021 18:13:13 +0200 Subject: [PATCH] Add more eslint rules, bump up dependency --- .eslintrc.yml | 8 +++++ package-lock.json | 51 +++++++++++++++++++++++---- package.json | 3 +- src/App.tsx | 15 ++++++-- src/components/BurnButton.tsx | 5 ++- src/components/Dialog.tsx | 38 +++++++++++--------- src/components/Dialog/SmartSelect.tsx | 16 ++++----- src/components/Log.tsx | 19 +++++++--- src/components/SideBar.tsx | 4 +-- src/components/StatusBar.tsx | 18 ++++++++-- src/data/help.ts | 4 +-- src/data/standardDialogs.ts | 4 +-- src/electron.ts | 5 ++- src/parser/ini.ts | 4 +-- src/store.ts | 6 +++- src/utils/api.ts | 4 +-- src/utils/tune/expression.ts | 40 ++++++++++----------- 17 files changed, 162 insertions(+), 82 deletions(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index 990e41f..32e51eb 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -17,7 +17,9 @@ extends: plugins: - jsx-a11y - prettier + - modules-newline rules: + indent: [2, 2, { "SwitchCase": 1 }] semi: - error - always @@ -35,6 +37,12 @@ rules: object-curly-spacing: - error - always + object-curly-newline: [2, { + "ImportDeclaration": { "multiline": true, "minProperties": 2 }, + "ExportDeclaration": { "multiline": true, "minProperties": 1 } + }] + modules-newline/import-declaration-newline: 2 + modules-newline/export-declaration-newline: 2 quotes: - error - single diff --git a/package-lock.json b/package-lock.json index 0b55f98..495e09d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38,7 +38,7 @@ "@types/react-dom": "^17.0.3", "@types/react-redux": "^7.1.16", "@types/react-router-dom": "^5.1.7", - "concurrently": "^6.0.0", + "concurrently": "^6.0.1", "electron": "^12.0.1", "eslint": "^7.23.0", "eslint-config-airbnb": "^18.2.1", @@ -46,6 +46,7 @@ "eslint-config-prettier": "^8.1.0", "eslint-plugin-import": "^2.22.1", "eslint-plugin-jsx-a11y": "^6.4.1", + "eslint-plugin-modules-newline": "^0.0.6", "eslint-plugin-prettier": "^3.3.1", "less-loader": "^6.1.0", "prettier": "^2.2.1", @@ -6363,9 +6364,9 @@ } }, "node_modules/concurrently": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/concurrently/-/concurrently-6.0.0.tgz", - "integrity": "sha512-Ik9Igqnef2ONLjN2o/OVx1Ow5tymVvvEwQeYCQdD/oV+CN9oWhxLk7ibcBdOtv0UzBqHCEKRwbKceYoTK8t3fQ==", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/concurrently/-/concurrently-6.0.1.tgz", + "integrity": "sha512-YCF/Wf31a910hXu7eGN9/SyHKD/usw3Shw4IPYuqIsxxC39v92engYlIlOs/zXnBJtX/6aVuhgzfhZeGJkhU4w==", "dev": true, "dependencies": { "chalk": "^4.1.0", @@ -9212,6 +9213,18 @@ "eslint": "^3 || ^4 || ^5 || ^6 || ^7" } }, + "node_modules/eslint-plugin-modules-newline": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/eslint-plugin-modules-newline/-/eslint-plugin-modules-newline-0.0.6.tgz", + "integrity": "sha512-69NpBr68U6pmXL+y+KHl/64PwRarceC3/sCNUVxRbe0gPI32SIw8AtdpkqNiJYCa2yMd4lRrkrnU09Yio7KVzA==", + "dev": true, + "dependencies": { + "requireindex": "~1.1.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/eslint-plugin-prettier": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.3.1.tgz", @@ -20632,6 +20645,15 @@ "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==" }, + "node_modules/requireindex": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/requireindex/-/requireindex-1.1.0.tgz", + "integrity": "sha1-5UBLgVV+91225JxacgBIk/4D4WI=", + "dev": true, + "engines": { + "node": ">=0.10.5" + } + }, "node_modules/requires-port": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", @@ -31360,9 +31382,9 @@ } }, "concurrently": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/concurrently/-/concurrently-6.0.0.tgz", - "integrity": "sha512-Ik9Igqnef2ONLjN2o/OVx1Ow5tymVvvEwQeYCQdD/oV+CN9oWhxLk7ibcBdOtv0UzBqHCEKRwbKceYoTK8t3fQ==", + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/concurrently/-/concurrently-6.0.1.tgz", + "integrity": "sha512-YCF/Wf31a910hXu7eGN9/SyHKD/usw3Shw4IPYuqIsxxC39v92engYlIlOs/zXnBJtX/6aVuhgzfhZeGJkhU4w==", "dev": true, "requires": { "chalk": "^4.1.0", @@ -33638,6 +33660,15 @@ "language-tags": "^1.0.5" } }, + "eslint-plugin-modules-newline": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/eslint-plugin-modules-newline/-/eslint-plugin-modules-newline-0.0.6.tgz", + "integrity": "sha512-69NpBr68U6pmXL+y+KHl/64PwRarceC3/sCNUVxRbe0gPI32SIw8AtdpkqNiJYCa2yMd4lRrkrnU09Yio7KVzA==", + "dev": true, + "requires": { + "requireindex": "~1.1.0" + } + }, "eslint-plugin-prettier": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-3.3.1.tgz", @@ -42490,6 +42521,12 @@ "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==" }, + "requireindex": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/requireindex/-/requireindex-1.1.0.tgz", + "integrity": "sha1-5UBLgVV+91225JxacgBIk/4D4WI=", + "dev": true + }, "requires-port": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", diff --git a/package.json b/package.json index 271bda3..621c8db 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,7 @@ "@types/react-dom": "^17.0.3", "@types/react-redux": "^7.1.16", "@types/react-router-dom": "^5.1.7", - "concurrently": "^6.0.0", + "concurrently": "^6.0.1", "electron": "^12.0.1", "eslint": "^7.23.0", "eslint-config-airbnb": "^18.2.1", @@ -73,6 +73,7 @@ "eslint-config-prettier": "^8.1.0", "eslint-plugin-import": "^2.22.1", "eslint-plugin-jsx-a11y": "^6.4.1", + "eslint-plugin-modules-newline": "^0.0.6", "eslint-plugin-prettier": "^3.3.1", "less-loader": "^6.1.0", "prettier": "^2.2.1", diff --git a/src/App.tsx b/src/App.tsx index 560ae6a..52589f6 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,7 @@ -import { useEffect, useMemo } from 'react'; +import { + useEffect, + useMemo, +} from 'react'; import { useLocation, Switch, @@ -7,12 +10,18 @@ import { Redirect, generatePath, } from 'react-router-dom'; -import { Layout, Result } from 'antd'; +import { + Layout, + Result, +} from 'antd'; import { connect } from 'react-redux'; import Dialog from './components/Dialog'; import { loadAll } from './utils/api'; import SideBar, { DialogMatchedPathType } from './components/SideBar'; -import { AppState, UIState } from './types/state'; +import { + AppState, + UIState, +} from './types/state'; import BurnButton from './components/BurnButton'; import TopBar from './components/TopBar'; import StatusBar from './components/StatusBar'; diff --git a/src/components/BurnButton.tsx b/src/components/BurnButton.tsx index 70340b9..e9fe357 100644 --- a/src/components/BurnButton.tsx +++ b/src/components/BurnButton.tsx @@ -1,4 +1,7 @@ -import { Button, Grid } from 'antd'; +import { + Button, + Grid, +} from 'antd'; import { FireOutlined } from '@ant-design/icons'; const { useBreakpoint } = Grid; diff --git a/src/components/Dialog.tsx b/src/components/Dialog.tsx index 85d9ca2..f658cfc 100644 --- a/src/components/Dialog.tsx +++ b/src/components/Dialog.tsx @@ -26,13 +26,17 @@ import { ScalarConstant as ScalarConstantType, ConstantTypes, } from '../types/config'; -import { - Tune as TuneType, -} from '../types/tune'; +import { Tune as TuneType } from '../types/tune'; import { findOnPage } from '../utils/config/find'; -import { parseXy, parseZ } from '../utils/tune/table'; +import { + parseXy, + parseZ, +} from '../utils/tune/table'; import Map from './Dialog/Map'; -import { evaluateExpression, isExpression } from '../utils/tune/expression'; +import { + evaluateExpression, + isExpression, +} from '../utils/tune/expression'; import useStorage from '../hooks/useStorage'; interface DialogsAndCurves { @@ -291,7 +295,7 @@ const Dialog = ({ type = PanelTypes.FIELDS; fields = (currentDialog as DialogType) .fields - .filter((field) => field.title !== '' ); + .filter((field) => field.title !== ''); } else if ('zBins' in currentDialog) { type = PanelTypes.TABLE; } @@ -352,21 +356,21 @@ const Dialog = ({ // case ConstantTypes.ARRAY: // TODO: arrays case ConstantTypes.BITS: input = ; + defaultValue={`${tuneField.value}`} + values={constant.values as string[]} + disabled={!enabled} + />; break; case ConstantTypes.SCALAR: input = ; + defaultValue={Number(tuneField.value)} + digits={(constant as ScalarConstantType).digits} + min={((constant as ScalarConstantType).min as number) || 0} + max={(constant as ScalarConstantType).max as number} + disabled={!enabled} + units={(constant as ScalarConstantType).units} + />; break; default: diff --git a/src/components/Dialog/SmartSelect.tsx b/src/components/Dialog/SmartSelect.tsx index 06f817a..afe3944 100644 --- a/src/components/Dialog/SmartSelect.tsx +++ b/src/components/Dialog/SmartSelect.tsx @@ -26,24 +26,24 @@ const SmartSelect = ({ ) ) { return } - unCheckedChildren={} - />; + defaultChecked={[Switches.ON, Switches.YES].includes(defaultValue as Switches)} + checkedChildren={} + unCheckedChildren={} + />; } if (values.length < 3) { return ( - - {values.map((val: string, index) => + {values.map((val: string, index) => {val}, - )} - + )} + ); } diff --git a/src/components/Log.tsx b/src/components/Log.tsx index 92c23b5..0468da8 100644 --- a/src/components/Log.tsx +++ b/src/components/Log.tsx @@ -24,16 +24,25 @@ import { import { CheckboxValueType } from 'antd/lib/checkbox/Group'; import useBreakpoint from 'antd/lib/grid/hooks/useBreakpoint'; import { connect } from 'react-redux'; -import { Field, Result as ParserResult } from 'mlg-converter/dist/types'; +import { + Field, + Result as ParserResult, +} from 'mlg-converter/dist/types'; import PerfectScrollbar from 'react-perfect-scrollbar'; // eslint-disable-next-line import/no-unresolved import MlgParserWorker from 'worker-loader!../workers/mlgParser.worker'; import { loadLogs } from '../utils/api'; import Canvas, { LogEntry } from './Log/Canvas'; -import { AppState, UIState } from '../types/state'; +import { + AppState, + UIState, +} from '../types/state'; import { Config } from '../types/config'; import store from '../store'; -import { formatBytes, msToTime } from '../utils/number'; +import { + formatBytes, + msToTime, +} from '../utils/number'; const { TabPane } = Tabs; const { Content } = Layout; @@ -139,11 +148,11 @@ const Log = ({ ui, config }: { ui: UIState, config: Config }) => { } key="files"> Files - + } key="gauges"> Gauges - + } diff --git a/src/components/SideBar.tsx b/src/components/SideBar.tsx index 112b9e3..f843953 100644 --- a/src/components/SideBar.tsx +++ b/src/components/SideBar.tsx @@ -19,9 +19,7 @@ import { Config as ConfigType, Menus as MenusType, } from '../types/config'; -import { - Tune as TuneType, -} from '../types/tune'; +import { Tune as TuneType } from '../types/tune'; import Icon from './SideBar/Icon'; import { evaluateExpression } from '../utils/tune/expression'; import { Routes } from '../routes'; diff --git a/src/components/StatusBar.tsx b/src/components/StatusBar.tsx index 817eb90..5620346 100644 --- a/src/components/StatusBar.tsx +++ b/src/components/StatusBar.tsx @@ -1,8 +1,20 @@ -import { Layout, Space, Row, Col } from 'antd'; -import { CarOutlined, InfoCircleOutlined } from '@ant-design/icons'; +import { + Layout, + Space, + Row, + Col, +} from 'antd'; +import { + CarOutlined, + InfoCircleOutlined, +} from '@ant-design/icons'; import { connect } from 'react-redux'; -import { AppState, ConfigState, StatusState } from '../types/state'; +import { + AppState, + ConfigState, + StatusState, +} from '../types/state'; const { Footer } = Layout; diff --git a/src/data/help.ts b/src/data/help.ts index 0188c88..9bb8a89 100644 --- a/src/data/help.ts +++ b/src/data/help.ts @@ -1,6 +1,4 @@ -import { - Help as HelpType, -} from '../types/config'; +import { Help as HelpType } from '../types/config'; export const help: HelpType = { reqFuel: 'The base reference pulse width required to achieve stoichiometric at 100% VE and a manifold absolute pressure (MAP) of 100kPa using current settings.', diff --git a/src/data/standardDialogs.ts b/src/data/standardDialogs.ts index ef485ee..bd98eae 100644 --- a/src/data/standardDialogs.ts +++ b/src/data/standardDialogs.ts @@ -1,6 +1,4 @@ -import { - Dialogs as DialogsType, -} from '../types/config'; +import { Dialogs as DialogsType } from '../types/config'; const standardDialogs: DialogsType = { std_injection: { diff --git a/src/electron.ts b/src/electron.ts index 43a8b97..dadd9b4 100644 --- a/src/electron.ts +++ b/src/electron.ts @@ -1,4 +1,7 @@ -import { app, BrowserWindow } from 'electron'; +import { + app, + BrowserWindow, +} from 'electron'; import path from 'path'; const isDev = !app.isPackaged; diff --git a/src/parser/ini.ts b/src/parser/ini.ts index 48de70e..b64abc9 100644 --- a/src/parser/ini.ts +++ b/src/parser/ini.ts @@ -815,7 +815,7 @@ class INI { val.startsWith('$') ? this.result.defines[val.slice(1)] : val - )).flat(); + )).flat(); this.result.defines[result.name] = resolved; } @@ -869,7 +869,7 @@ class INI { size: result.size, length: Number(result.length), }; - break; + break; default: break; } diff --git a/src/store.ts b/src/store.ts index b84b72e..92d58b1 100644 --- a/src/store.ts +++ b/src/store.ts @@ -1,6 +1,10 @@ /* eslint-disable no-param-reassign */ -import { configureStore, createAction, createReducer } from '@reduxjs/toolkit'; +import { + configureStore, + createAction, + createReducer, +} from '@reduxjs/toolkit'; import * as Types from './types/state'; // tune and config diff --git a/src/utils/api.ts b/src/utils/api.ts index 2aabae9..4921548 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -1,7 +1,5 @@ import store from '../store'; -import { - Config as ConfigType, -} from '../types/config'; +import { Config as ConfigType } from '../types/config'; import stdDialogs from '../data/standardDialogs'; import help from '../data/help'; import { divider } from '../data/constants'; diff --git a/src/utils/tune/expression.ts b/src/utils/tune/expression.ts index 4a747c7..65cfc50 100644 --- a/src/utils/tune/expression.ts +++ b/src/utils/tune/expression.ts @@ -1,6 +1,4 @@ -import { - Constants as TuneConstantsType, -} from '../../types/tune'; +import { Constants as TuneConstantsType } from '../../types/tune'; import { Config as ConfigType, @@ -19,29 +17,29 @@ export const isNumber = (val: any) => !Number.isNaN(Number(val)); // ochGetCommand export const prepareConstDeclarations = (tuneConstants: TuneConstantsType, configPages: ConfigPageType[]) => ( Object.keys(tuneConstants).map((constName: string) => { - let val = tuneConstants[constName].value; + let val = tuneConstants[constName].value; - // TODO: skip 2D and 3D maps for now - if (typeof val === 'string' && val.includes('\n')) { - return null; - } + // TODO: skip 2D and 3D maps for now + if (typeof val === 'string' && val.includes('\n')) { + return null; + } - // TODO: check whether we can limit this to a single page - const constant = configPages - .find((page: ConfigPageType) => constName in page.data) - ?.data[constName]; + // TODO: check whether we can limit this to a single page + const constant = configPages + .find((page: ConfigPageType) => constName in page.data) + ?.data[constName]; - // we need array index instead of a display value - if (constant?.type === 'bits') { - val = (constant.values as string[]).indexOf(`${val}`); - } + // we need array index instead of a display value + if (constant?.type === 'bits') { + val = (constant.values as string[]).indexOf(`${val}`); + } - // escape string values - if (typeof val === 'string') { - val = `'${val}'`; - } + // escape string values + if (typeof val === 'string') { + val = `'${val}'`; + } - return `const ${constName} = ${val};`; + return `const ${constName} = ${val};`; }) );