Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
narthur committed Aug 6, 2024
1 parent 35c6407 commit 845e430
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 121 deletions.
4 changes: 0 additions & 4 deletions .eslintignore

This file was deleted.

79 changes: 0 additions & 79 deletions .eslintrc.js

This file was deleted.

124 changes: 124 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { fixupConfigRules, fixupPluginRules } from '@eslint/compat';
import react from 'eslint-plugin-react';
import typescriptEslint from '@typescript-eslint/eslint-plugin';
import regex from 'eslint-plugin-regex';
import lodash from 'eslint-plugin-lodash';
import globals from 'globals';
import tsParser from '@typescript-eslint/parser';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import js from '@eslint/js';
import { FlatCompat } from '@eslint/eslintrc';
import testingLibrary from 'eslint-plugin-testing-library';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});

export default [
{
ignores: ['public', 'src/serviceWorker.js', '**/eslint.config.mjs', 'dist'],
},
...fixupConfigRules(
compat.extends(
'eslint:recommended',
'plugin:react/recommended',
'plugin:react-hooks/recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'prettier',
),
),
{
plugins: {
react: fixupPluginRules(react),
'@typescript-eslint': fixupPluginRules(typescriptEslint),
regex,
lodash,
'testing-library': fixupPluginRules({
rules: testingLibrary.rules,
}),
},

languageOptions: {
globals: {
...globals.browser,
},

parser: tsParser,
ecmaVersion: 'latest',
sourceType: 'module',

parserOptions: {
ecmaFeatures: {
jsx: true,
},

project: './tsconfig.json',
},
},

settings: {
react: {
version: 'detect',
},
},

rules: {
'lodash/import-scope': 'error',

'regex/required': [
'error',
[
{
regex: 'describe.+from.+vitest',
message: 'Import `describe` explicitly.',

files: {
inspect: '\\.(test|spec)\\.tsx?$',
},
},
{
regex: 'it.+from.+vitest',
message: 'Import `it` explicitly.',

files: {
inspect: '\\.(test|spec)\\.tsx?$',
},
},
{
regex: 'expect.+from.+vitest',
message: 'Import `expect` explicitly.',

files: {
inspect: '\\.(test|spec)\\.tsx?$',
},
},
],
],
},
},
{
files: [
'**/*.spec.ts',
'**/*.spec.tsx',
'**/__mocks__/**/*',
'**/__tests__/**/*',
'**/global-setup.ts',
'src/lib/test/**/*',
],

rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
},
},
];
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
"react-toastify": "^10.0.5"
},
"devDependencies": {
"@eslint/compat": "^1.1.1",
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.8.0",
"@testing-library/jest-dom": "^6.4.8",
"@testing-library/react": "^16.0.0",
"@testing-library/user-event": "^14.5.2",
Expand All @@ -80,6 +83,7 @@
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-regex": "^1.10.0",
"eslint-plugin-testing-library": "^6.2.2",
"globals": "^15.9.0",
"jsdom": "^24.1.1",
"prettier": "3.3.3",
"rollup-plugin-visualizer": "^5.12.0",
Expand Down
24 changes: 24 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 12 additions & 10 deletions src/components/HOCs/AndTheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import React from 'react';
import {
Link as RouterLink,
LinkProps as RouterLinkProps,
To,
} from 'react-router-dom';
import { LinkProps } from '@mui/material/Link';
import { ToastContainer } from 'react-toastify';
Expand All @@ -29,18 +30,19 @@ const colors = {
},
};

const LinkBehavior = React.forwardRef<
HTMLAnchorElement,
Omit<RouterLinkProps, 'to'> & { href: RouterLinkProps['to'] }
>(function LinkBehavior(props, ref) {
const { href, ...other } = props;
type Props = Omit<RouterLinkProps, 'to'> & { href: To };

if (props.href.toString().match(/^https?:\/\//)) {
return <a ref={ref} href={href.toString()} {...other} />;
}
const LinkBehavior = React.forwardRef<HTMLAnchorElement, Props>(
function LinkBehavior(props: Props, ref) {
const { href, ...other } = props;

return <RouterLink ref={ref} to={href} {...other} />;
});
if (String(href).match(/^https?:\/\//)) {
return <a ref={ref} href={String(href)} {...other} />;
}

return <RouterLink ref={ref} to={href} {...other} />;
},
);

export default function AndTheme({
children,
Expand Down
2 changes: 1 addition & 1 deletion src/components/organisms/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function NavBar({ onTodayClick }: NavBarProps): JSX.Element {
const [isOpen, setIsOpen] = useState<boolean>(false);
const toggleMenu = () => setIsOpen(!isOpen);
const handleTodayClick = () => {
onTodayClick && onTodayClick();
onTodayClick?.();
navigate('/');
};

Expand Down
2 changes: 1 addition & 1 deletion src/components/organisms/TaskEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const TaskEdit = ({
<>
<MenuItem
onClick={() => {
onOpen && onOpen();
onOpen?.();
setIsOpen(true);
}}
disabled={!task.id || task.status !== 'pending'}
Expand Down
2 changes: 1 addition & 1 deletion src/components/organisms/UncleButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function UncleButton({
/* TODO: Disable if task id not set */
disabled={task.status !== 'pending'}
onClick={() => {
onClick && onClick();
onClick?.();
setOpen(true);
}}
>
Expand Down
22 changes: 1 addition & 21 deletions src/lib/api/useMe.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,13 @@
import { QueryObserverResult, useQuery } from 'react-query';
import { UseQueryOptions } from 'react-query';
import { useEffect } from 'react';
import { User, getMe } from '@taskratchet/sdk';

export function useMe(
queryOptions: UseQueryOptions<User> | undefined = {},
): QueryObserverResult<User, unknown> {
const result = useQuery({
return useQuery({
queryKey: 'me',
queryFn: getMe,
...queryOptions,
});

const { data } = result;

useEffect(() => {
if (!data) return;

const metadata = Object.keys(data).reduce(
(prev, key) => {
const value = data[key as keyof User];

prev[key] = typeof value === 'string' ? value : JSON.stringify(value);

return prev;
},
{} as Record<string, string>,
);
}, [data]);

return result;
}
Loading

0 comments on commit 845e430

Please sign in to comment.