From 8bd7cba6f5ce56bcccda1459cdd953b3add799d6 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 24 Feb 2024 16:02:48 -0800 Subject: Fix lint and issues --- modern/.eslintrc.js | 28 ------------------------- modern/.eslintrc.json | 37 ++++++++++++++++++++++++++++++++++ modern/package.json | 2 +- modern/src/UpdateController.jsx | 22 ++++++++++---------- modern/src/login/LoginPage.jsx | 2 +- modern/src/main/DeviceRow.jsx | 6 +++--- modern/src/other/PositionPage.jsx | 1 - modern/src/reports/EventReportPage.jsx | 4 ++-- modern/src/reports/LogsPage.jsx | 4 ++-- modern/src/settings/UserPage.jsx | 3 +-- modern/src/settings/UsersPage.jsx | 8 ++++---- 11 files changed, 62 insertions(+), 55 deletions(-) delete mode 100644 modern/.eslintrc.js create mode 100644 modern/.eslintrc.json diff --git a/modern/.eslintrc.js b/modern/.eslintrc.js deleted file mode 100644 index 20e3f4fb..00000000 --- a/modern/.eslintrc.js +++ /dev/null @@ -1,28 +0,0 @@ -module.exports = { - extends: 'airbnb', - parserOptions: { - ecmaVersion: 2020, - }, - plugins: [ - 'react', - ], - ignorePatterns: ['build/', 'switcher.js', 'theme.js'], - rules: { - 'max-len': [0], - 'no-shadow': [0], - 'no-return-assign': [0], - 'no-param-reassign': [0], - 'no-prototype-builtins': [0], - 'object-curly-newline': [1, { - ObjectExpression: { minProperties: 8, multiline: true, consistent: true }, - ObjectPattern: { minProperties: 8, multiline: true, consistent: true }, - ImportDeclaration: { minProperties: 4, multiline: true, consistent: true }, - ExportDeclaration: { minProperties: 4, multiline: true, consistent: true }, - }], - 'react/function-component-definition': [1, { - namedComponents: 'arrow-function', - unnamedComponents: 'arrow-function', - }], - 'react/prop-types': [0], - }, -}; diff --git a/modern/.eslintrc.json b/modern/.eslintrc.json new file mode 100644 index 00000000..6a60e087 --- /dev/null +++ b/modern/.eslintrc.json @@ -0,0 +1,37 @@ +{ + "extends": "airbnb", + "parserOptions": { + "ecmaVersion": 2020 + }, + "overrides": [{ + "files": ["*.jsx", "*.js"] + }], + "plugins": [ + "react" + ], + "ignorePatterns": ["build/", "switcher.js", "theme.js"], + "rules": { + "max-len": [0], + "no-shadow": [0], + "no-return-assign": [0], + "no-param-reassign": [0], + "no-prototype-builtins": [0], + "object-curly-newline": [1, { + "ObjectExpression": { "minProperties": 8, "multiline": true, "consistent": true }, + "ObjectPattern": { "minProperties": 8, "multiline": true, "consistent": true }, + "ImportDeclaration": { "minProperties": 4, "multiline": true, "consistent": true }, + "ExportDeclaration": { "minProperties": 4, "multiline": true, "consistent": true } + }], + "import/no-unresolved": [1, { + "ignore": ["\\.svg", "virtual:"] + }], + "react/function-component-definition": [1, { + "namedComponents": "arrow-function", + "unnamedComponents": "arrow-function" + }], + "react/jsx-props-no-spreading": [0], + "jsx-a11y/anchor-is-valid": [0], + "jsx-a11y/label-has-associated-control": [0], + "react/prop-types": [0] + } +} diff --git a/modern/package.json b/modern/package.json index 5c947753..0a325835 100644 --- a/modern/package.json +++ b/modern/package.json @@ -43,7 +43,7 @@ "build": "vite build", "generate-pwa-assets": "pwa-assets-generator --preset minimal public/logo.svg", "lint": "eslint .", - "lint:fix": "eslint --fix --ext .js ." + "lint:fix": "eslint --fix ." }, "browserslist": { "production": [ diff --git a/modern/src/UpdateController.jsx b/modern/src/UpdateController.jsx index 0b2b7985..80ca6dc2 100644 --- a/modern/src/UpdateController.jsx +++ b/modern/src/UpdateController.jsx @@ -1,12 +1,12 @@ import { Snackbar, IconButton } from '@mui/material'; import RefreshIcon from '@mui/icons-material/Refresh'; -import React from 'react' +import React from 'react'; import { useSelector } from 'react-redux'; +import { useRegisterSW } from 'virtual:pwa-register/react'; import { useTranslation } from './common/components/LocalizationProvider'; -import { useRegisterSW } from 'virtual:pwa-register/react' // Based on https://vite-pwa-org.netlify.app/frameworks/react.html -function UpdateController() { +const UpdateController = () => { const t = useTranslation(); const swUpdateInterval = useSelector((state) => state.session.server.attributes.serviceWorkerUpdateInterval || 3600000); @@ -21,30 +21,30 @@ function UpdateController() { if (!(!swRegistration.installing && navigator)) { return; } - + if (('connection' in navigator) && !navigator.onLine) { return; } - + const newSW = await fetch(swUrl, { cache: 'no-store', headers: { - 'cache': 'no-store', + cache: 'no-store', 'cache-control': 'no-cache', }, }); - + if (newSW?.status === 200) { await swRegistration.update(); } }, swUpdateInterval); } - } + }, }); return ( - updateServiceWorker(true)}> @@ -53,6 +53,6 @@ function UpdateController() { )} /> ); -} +}; export default UpdateController; diff --git a/modern/src/login/LoginPage.jsx b/modern/src/login/LoginPage.jsx index 6cca2837..62aa4a6b 100644 --- a/modern/src/login/LoginPage.jsx +++ b/modern/src/login/LoginPage.jsx @@ -96,7 +96,7 @@ const LoginPage = () => { const query = `email=${encodeURIComponent(email)}&password=${encodeURIComponent(password)}`; const response = await fetch('/api/session', { method: 'POST', - body: new URLSearchParams(code.length ? query + `&code=${code}` : query), + body: new URLSearchParams(code.length ? `${query}&code=${code}` : query), }); if (response.ok) { const user = await response.json(); diff --git a/modern/src/main/DeviceRow.jsx b/modern/src/main/DeviceRow.jsx index 8d40e139..d9c1a189 100644 --- a/modern/src/main/DeviceRow.jsx +++ b/modern/src/main/DeviceRow.jsx @@ -119,15 +119,15 @@ const DeviceRow = ({ data, index, style }) => { {position.attributes.hasOwnProperty('batteryLevel') && ( - {position.attributes.batteryLevel > 70 ? ( + {(position.attributes.batteryLevel > 70 && ( position.attributes.charge ? () : () - ) : position.attributes.batteryLevel > 30 ? ( + )) || (position.attributes.batteryLevel > 30 && ( position.attributes.charge ? () : () - ) : ( + )) || ( position.attributes.charge ? () : () diff --git a/modern/src/other/PositionPage.jsx b/modern/src/other/PositionPage.jsx index 3ed3498c..f253cd2c 100644 --- a/modern/src/other/PositionPage.jsx +++ b/modern/src/other/PositionPage.jsx @@ -8,7 +8,6 @@ import makeStyles from '@mui/styles/makeStyles'; import ArrowBackIcon from '@mui/icons-material/ArrowBack'; import { useNavigate, useParams } from 'react-router-dom'; import { useEffectAsync } from '../reactHelper'; -import { prefixString } from '../common/util/stringUtils'; import { useTranslation } from '../common/components/LocalizationProvider'; import PositionValue from '../common/components/PositionValue'; import usePositionAttributes from '../common/attributes/usePositionAttributes'; diff --git a/modern/src/reports/EventReportPage.jsx b/modern/src/reports/EventReportPage.jsx index 10b539ab..5ffc8ac3 100644 --- a/modern/src/reports/EventReportPage.jsx +++ b/modern/src/reports/EventReportPage.jsx @@ -204,7 +204,7 @@ const EventReportPage = () => { {!loading ? items.map((item) => ( - {item.positionId ? selectedItem === item ? ( + {(item.positionId && (selectedItem === item ? ( setSelectedItem(null)}> @@ -212,7 +212,7 @@ const EventReportPage = () => { setSelectedItem(item)}> - ) : ''} + ))) || ''} {columns.map((key) => ( diff --git a/modern/src/reports/LogsPage.jsx b/modern/src/reports/LogsPage.jsx index 4b689944..7bdbd309 100644 --- a/modern/src/reports/LogsPage.jsx +++ b/modern/src/reports/LogsPage.jsx @@ -41,7 +41,7 @@ const LogsPage = () => { const registerDevice = (uniqueId) => { const query = new URLSearchParams({ uniqueId }); navigate(`/settings/device?${query.toString()}`); - } + }; return ( } breadcrumbs={['reportTitle', 'statisticsTitle']}> @@ -55,7 +55,7 @@ const LogsPage = () => { - {items.map((item, index) => ( + {items.map((item, index) => /* eslint-disable react/no-array-index-key */ ( {item.deviceId ? ( diff --git a/modern/src/settings/UserPage.jsx b/modern/src/settings/UserPage.jsx index 02312a86..4e0cab2c 100644 --- a/modern/src/settings/UserPage.jsx +++ b/modern/src/settings/UserPage.jsx @@ -18,7 +18,6 @@ import { IconButton, OutlinedInput, } from '@mui/material'; -import makeStyles from '@mui/styles/makeStyles'; import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; import DeleteForeverIcon from '@mui/icons-material/DeleteForever'; import CachedIcon from '@mui/icons-material/Cached'; @@ -84,7 +83,7 @@ const UserPage = () => { const handleGenerateTotp = useCatch(async () => { const response = await fetch('/api/users/totp', { method: 'POST' }); if (response.ok) { - setItem({ ...item, totpKey: await response.text() }) + setItem({ ...item, totpKey: await response.text() }); } else { throw Error(await response.text()); } diff --git a/modern/src/settings/UsersPage.jsx b/modern/src/settings/UsersPage.jsx index e54ecc01..2941965b 100644 --- a/modern/src/settings/UsersPage.jsx +++ b/modern/src/settings/UsersPage.jsx @@ -1,7 +1,7 @@ import React, { useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { - Table, TableRow, TableCell, TableHead, TableBody, Switch, TableFooter, FormControlLabel, FormControl, FormGroup, Grid, + Table, TableRow, TableCell, TableHead, TableBody, Switch, TableFooter, FormControlLabel, } from '@mui/material'; import LoginIcon from '@mui/icons-material/Login'; import LinkIcon from '@mui/icons-material/Link'; @@ -81,7 +81,7 @@ const UsersPage = () => { {t('userAdmin')} {t('sharedDisabled')} {t('userExpirationTime')} - + @@ -108,13 +108,13 @@ const UsersPage = () => { setTemporary(e.target.checked)} size="small" /> - } + )} label={t('userTemporary')} labelPlacement="start" /> -- cgit v1.2.3