Stricter lints part 1

This commit is contained in:
Piotr Rogowski 2023-08-06 13:20:08 +02:00
parent 649a09f296
commit 0717fcb1ce
No known key found for this signature in database
GPG Key ID: 4A842D702D9C6F8F
16 changed files with 76 additions and 60 deletions

View File

@ -7,6 +7,7 @@
"FOME",
"hypertuner",
"kbar",
"MLVLG",
"noisymime",
"pocketbase",
"prefs",

View File

@ -14,7 +14,8 @@
"start": "vite",
"build": "tsc && vite build",
"serve": "vite preview",
"lint": "tsc && rome ci src",
"lint": "tsc && npm run lint:rome",
"lint:rome": "rome ci src",
"lint:fix": "rome format --write src && rome check --apply src",
"lint:fix:unsafe": "rome check --apply-unsafe src",
"analyze": "npm run build && open stats.html",

View File

@ -18,17 +18,25 @@
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"all": true,
"correctness": {
"all": true,
"noUnusedVariables": "warn"
},
"style": {
"all": true,
"noImplicitBoolean": "off",
"useEnumInitializers": "off",
"noNonNullAssertion": "off"
},
"suspicious": {
"all": true,
"noExplicitAny": "off"
},
"nursery": {
"all": true,
"useExhaustiveDependencies": "off",
"noForEach": "off"
}
}
}

View File

@ -195,12 +195,13 @@ const ResultItem = forwardRef(
const RenderResults = () => {
const { results, rootActionId } = useMatches();
const onResultsRender = ({ item, active }: { item: any; active: boolean }) =>
typeof item === 'string' ? (
const onResultsRender = ({ item, active }: { item: any; active: boolean }) => {
return typeof item === 'string' ? (
<div style={groupNameStyle}>{item}</div>
) : (
<ResultItem action={item} active={active} currentRootActionId={rootActionId as string} />
);
};
return <KBarResults items={results} onRender={onResultsRender} />;
};

View File

@ -21,9 +21,10 @@ import {
UnorderedListOutlined,
UpCircleOutlined,
} from '@ant-design/icons';
import React from 'react';
const Icon = ({ name }: { name: string }): JSX.Element => {
const map: { [index: string]: JSX.Element } = {
const Icon = ({ name }: { name: string }): React.JSX.Element => {
const map: { [index: string]: React.JSX.Element } = {
settings: <ControlOutlined />,
tuning: <CarOutlined />,
spark: <FireOutlined />,

View File

@ -1,4 +1,4 @@
import { useCallback, useEffect, useMemo, useRef } from 'react';
import React, { useCallback, useEffect, useMemo, useRef } from 'react';
import { useLocation, useNavigate, Link, generatePath, useMatch } from 'react-router-dom';
import { Layout, Space, Button, Row, Col, Tooltip, Grid, Dropdown, Typography, Radio } from 'antd';
import {
@ -39,7 +39,7 @@ import { buildHyperTunerAppLink } from '../utils/url';
const { Header } = Layout;
const { useBreakpoint } = Grid;
const logsExtensionsIcons: { [key: string]: JSX.Element } = {
const logsExtensionsIcons: { [key: string]: React.JSX.Element } = {
mlg: <FileZipOutlined />,
msl: <FileTextOutlined />,
csv: <FileExcelOutlined />,
@ -264,39 +264,37 @@ const TopBar = ({
return list.length ? list : null;
}, [lg, sm]);
const userAuthMenuItems = useMemo(
() =>
currentUser
? [
{
key: 'profile',
icon: <UserOutlined />,
label: 'Profile',
onClick: () => navigate(Routes.PROFILE),
},
{
key: 'logout',
icon: <LogoutOutlined />,
label: 'Logout',
onClick: logoutClick,
},
]
: [
{
key: 'login',
icon: <LoginOutlined />,
label: 'Login',
onClick: () => navigate(Routes.LOGIN),
},
{
key: 'sign-up',
icon: <UserAddOutlined />,
label: 'Sign Up',
onClick: () => navigate(Routes.SIGN_UP),
},
],
[currentUser, logoutClick, navigate],
);
const userAuthMenuItems = useMemo(() => {
return currentUser
? [
{
key: 'profile',
icon: <UserOutlined />,
label: 'Profile',
onClick: () => navigate(Routes.PROFILE),
},
{
key: 'logout',
icon: <LogoutOutlined />,
label: 'Logout',
onClick: logoutClick,
},
]
: [
{
key: 'login',
icon: <LoginOutlined />,
label: 'Login',
onClick: () => navigate(Routes.LOGIN),
},
{
key: 'sign-up',
icon: <UserAddOutlined />,
label: 'Sign Up',
onClick: () => navigate(Routes.SIGN_UP),
},
];
}, [currentUser, logoutClick, navigate]);
const userMenuItems = [
...userAuthMenuItems,

View File

@ -1,4 +1,4 @@
import { useCallback, useEffect, useRef, useState } from 'react';
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { connect } from 'react-redux';
import { Form, Divider, Col, Row, Popover, Space, Result } from 'antd';
import { QuestionCircleOutlined } from '@ant-design/icons';
@ -81,7 +81,7 @@ const Dialog = ({
tune && config && Object.keys(tune.constants).length && Object.keys(config.constants).length;
const { storageSet } = useBrowserStorage();
const { findConstantOnPage } = useConfig(config);
const [panelsComponents, setPanelsComponents] = useState<(JSX.Element | null)[]>([]);
const [panelsComponents, setPanelsComponents] = useState<(React.JSX.Element | null)[]>([]);
const containerRef = useRef<HTMLDivElement | null>(null);
const renderHelp = (link?: string) =>

View File

@ -50,13 +50,13 @@ const SmartSelect = ({
style={{ maxWidth: 250 }}
>
{/* we need to preserve indexes here, skip INVALID option */}
{values.map((val: string, index) =>
val === 'INVALID' ? null : (
{values.map((val: string, index) => {
return val === 'INVALID' ? null : (
<Select.Option key={val} value={index} label={val}>
{val}
</Select.Option>
),
)}
);
})}
</Select>
);
};

View File

@ -1,7 +1,10 @@
import { Tag } from 'antd';
import { TunesTagsOptions } from '../@types/pocketbase-types';
const TuneTag = ({ tag }: { tag: TunesTagsOptions | undefined }) =>
tag ? <Tag color={tag === TunesTagsOptions['base map'] ? 'green' : 'red'}>{tag}</Tag> : null;
const TuneTag = ({ tag }: { tag: TunesTagsOptions | undefined }) => {
return tag ? (
<Tag color={tag === TunesTagsOptions['base map'] ? 'green' : 'red'}>{tag}</Tag>
) : null;
};
export default TuneTag;

View File

@ -27,6 +27,7 @@ interface AuthValue {
}
const AuthContext = createContext<AuthValue | null>(null);
// rome-ignore lint/nursery/useHookAtTopLevel: <explanation>
const useAuth = () => useContext<AuthValue>(AuthContext as any);
const users = client.collection(Collections.Users);

View File

@ -50,6 +50,7 @@ const findDatalog = (config: ConfigType, name: string): DatalogEntry => {
};
const useConfig = (config: ConfigType | null) =>
// rome-ignore lint/nursery/useHookAtTopLevel: <explanation>
useMemo(
() => ({
isConfigReady: !!config?.constants,

View File

@ -408,7 +408,6 @@ const UploadPage = () => {
}
default:
valid = false;
break;
}
return {

View File

@ -183,8 +183,8 @@ const Login = ({ formRole }: { formRole: FormRoles }) => {
});
}, [listAuthMethods]);
const OauthSection = () =>
isOauthEnabled ? (
const OauthSection = () => {
return isOauthEnabled ? (
<>
<Space direction='horizontal' style={{ width: '100%', justifyContent: 'center' }}>
{providersReady &&
@ -205,6 +205,7 @@ const Login = ({ formRole }: { formRole: FormRoles }) => {
<Divider />
</>
) : null;
};
const bottomLinksLogin = (
<>

View File

@ -1,7 +1,7 @@
import { ParserInterface } from '../ParserInterface';
class LogValidator implements ParserInterface {
private MLG_FORMAT_LENGTH = 6;
private mlgFormatLength = 6;
private isMLGLogs = false;
@ -32,7 +32,7 @@ class LogValidator implements ParserInterface {
}
private checkMLG() {
const fileFormat = new TextDecoder('utf8').decode(this.buffer.slice(0, this.MLG_FORMAT_LENGTH))
const fileFormat = new TextDecoder('utf8').decode(this.buffer.slice(0, this.mlgFormatLength))
.replace(/\x00/gu, '');

View File

@ -25,9 +25,9 @@ export interface ToothLogEntry {
}
class TriggerLogsParser implements ParserInterface {
private COMMENT_PREFIX = '#';
private commentPrefix = '#';
private MARKER_PREFIX = 'MARK';
private markerPrefix = 'MARK';
private isToothLogs = false;
@ -118,11 +118,11 @@ class TriggerLogsParser implements ParserInterface {
raw.split('\n').forEach((line) => {
const trimmed = line.trim();
if (trimmed.startsWith(this.COMMENT_PREFIX)) {
if (trimmed.startsWith(this.commentPrefix)) {
return;
}
if (trimmed.startsWith(this.MARKER_PREFIX)) {
if (trimmed.startsWith(this.markerPrefix)) {
const previous = this.resultTooth[this.resultTooth.length - 1] || {
toothTime: 0,
time: 0,
@ -160,11 +160,11 @@ class TriggerLogsParser implements ParserInterface {
raw.split('\n').forEach((line) => {
const trimmed = line.trim();
if (trimmed.startsWith(this.COMMENT_PREFIX)) {
if (trimmed.startsWith(this.commentPrefix)) {
return;
}
if (trimmed.startsWith(this.MARKER_PREFIX)) {
if (trimmed.startsWith(this.markerPrefix)) {
const previous = this.resultComposite[this.resultComposite.length - 1] || {
primaryLevel: 0,
secondaryLevel: 0,

View File

@ -21,6 +21,7 @@
"incremental": false,
"noUncheckedIndexedAccess": false,
"noUnusedLocals": true,
"noUnusedParameters": true
},
"include": [
"src"