From d55c21e69ce1cd2152acef98e419532e4e4aa000 Mon Sep 17 00:00:00 2001 From: Fernanda Toledo Date: Wed, 11 Sep 2024 11:41:17 -0300 Subject: [PATCH 1/3] chore: eslint no duplicates import --- .eslintrc.js | 1 + src/components/inputs.tsx | 3 +-- src/ui/select.tsx | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 6bf880fc..6499cfaf 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -19,6 +19,7 @@ module.exports = { project: './tsconfig.json', }, rules: { + 'import/no-duplicates': 'error', '@typescript-eslint/no-explicit-any': 'error', 'unicorn/filename-case': [ 'error', diff --git a/src/components/inputs.tsx b/src/components/inputs.tsx index f4911646..53ebb9ac 100644 --- a/src/components/inputs.tsx +++ b/src/components/inputs.tsx @@ -1,8 +1,7 @@ import { useState } from 'react'; import type { OptionType } from '@/ui'; -import { Input, Select, View } from '@/ui'; -import { Checkbox, Radio, Switch } from '@/ui'; +import { Checkbox, Input, Radio, Select, Switch, View } from '@/ui'; import { Title } from './title'; diff --git a/src/ui/select.tsx b/src/ui/select.tsx index f6b8c3b8..123443ac 100644 --- a/src/ui/select.tsx +++ b/src/ui/select.tsx @@ -18,8 +18,7 @@ import colors from '@/ui/colors'; import { CaretDown } from '@/ui/icons'; import type { InputControllerType } from './input'; -import { useModal } from './modal'; -import { Modal } from './modal'; +import { Modal, useModal } from './modal'; import { Text } from './text'; const selectTv = tv({ From 86ef87e5ca8a811456917b78dee82f8c6902f24c Mon Sep 17 00:00:00 2001 From: Fernanda Toledo Date: Wed, 11 Sep 2024 13:58:22 -0300 Subject: [PATCH 2/3] chore: no-console --- .eslintrc.js | 10 ++++++-- env.js | 2 -- package.json | 3 ++- pnpm-lock.yaml | 27 +++++++++++++++++++++ src/api/common/api-provider.tsx | 3 ++- src/app/_layout.tsx | 1 + src/app/feed/add-post.tsx | 1 - src/app/onboarding.tsx | 2 +- src/components/settings/item.tsx | 2 ++ src/components/settings/items-container.tsx | 2 ++ src/core/auth/index.tsx | 5 ++-- src/core/hooks/use-selected-theme.tsx | 3 +-- src/core/test-utils.tsx | 1 + src/ui/focus-aware-status-bar.tsx | 1 + src/ui/utils.tsx | 1 - 15 files changed, 50 insertions(+), 14 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 6499cfaf..48ee2600 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -5,15 +5,21 @@ module.exports = { extends: [ 'expo', 'plugin:tailwindcss/recommended', - 'prettier' + 'prettier', + 'eslint:recommended' ], + env: { + 'jest/globals': true, + 'node': true + }, plugins: [ 'unicorn', '@typescript-eslint', 'unused-imports', 'tailwindcss', 'simple-import-sort', - 'sonarjs' + 'sonarjs', + 'jest' ], parserOptions: { project: './tsconfig.json', diff --git a/env.js b/env.js index a75c4543..a6d4b854 100644 --- a/env.js +++ b/env.js @@ -219,8 +219,6 @@ if (shouldValidateEnv) { ); } - console.error(...messages); - throw new Error( 'Invalid environment variables, Check terminal for more details ' ); diff --git a/package.json b/package.json index 856ab2cf..58fdb7f5 100644 --- a/package.json +++ b/package.json @@ -73,8 +73,8 @@ "expo-splash-screen": "0.27.5", "expo-status-bar": "~1.12.1", "expo-system-ui": "~3.0.7", - "i18next": "^23.14.0", "expo-updates": "~0.25.24", + "i18next": "^23.14.0", "lodash.memoize": "^4.1.2", "moti": "^0.29.0", "nativewind": "4.0.36", @@ -120,6 +120,7 @@ "eslint-config-expo": "^7.1.2", "eslint-config-prettier": "^9.1.0", "eslint-plugin-i18n-json": "^4.0.0", + "eslint-plugin-jest": "^28.8.3", "eslint-plugin-prettier": "^5.2.1", "eslint-plugin-simple-import-sort": "^10.0.0", "eslint-plugin-sonarjs": "^1.0.4", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 87e1b81f..3ec5c6cb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -198,6 +198,9 @@ importers: eslint-plugin-i18n-json: specifier: ^4.0.0 version: 4.0.0(eslint@8.57.0) + eslint-plugin-jest: + specifier: ^28.8.3 + version: 28.8.3(@typescript-eslint/eslint-plugin@5.62.0(@typescript-eslint/parser@5.62.0(eslint@8.57.0)(typescript@5.3.3))(eslint@8.57.0)(typescript@5.3.3))(eslint@8.57.0)(jest@29.7.0(@types/node@22.5.0)(ts-node@10.9.2(@types/node@22.5.0)(typescript@5.3.3)))(typescript@5.3.3) eslint-plugin-prettier: specifier: ^5.2.1 version: 5.2.1(eslint-config-prettier@9.1.0(eslint@8.57.0))(eslint@8.57.0)(prettier@3.3.3) @@ -3417,6 +3420,19 @@ packages: '@typescript-eslint/parser': optional: true + eslint-plugin-jest@28.8.3: + resolution: {integrity: sha512-HIQ3t9hASLKm2IhIOqnu+ifw7uLZkIlR7RYNv7fMcEi/p0CIiJmfriStQS2LDkgtY4nyLbIZAD+JL347Yc2ETQ==} + engines: {node: ^16.10.0 || ^18.12.0 || >=20.0.0} + peerDependencies: + '@typescript-eslint/eslint-plugin': ^6.0.0 || ^7.0.0 || ^8.0.0 + eslint: ^7.0.0 || ^8.0.0 || ^9.0.0 + jest: '*' + peerDependenciesMeta: + '@typescript-eslint/eslint-plugin': + optional: true + jest: + optional: true + eslint-plugin-prettier@5.2.1: resolution: {integrity: sha512-gH3iR3g4JfF+yYPaJYkN7jEl9QbweL/YfkoRlNnuIEHEz1vHVlCmWOS+eGGiRuzHQXdJFCOTxRgvju9b8VUmrw==} engines: {node: ^14.18.0 || >=16.0.0} @@ -11867,6 +11883,17 @@ snapshots: - eslint-import-resolver-webpack - supports-color + eslint-plugin-jest@28.8.3(@typescript-eslint/eslint-plugin@5.62.0(@typescript-eslint/parser@5.62.0(eslint@8.57.0)(typescript@5.3.3))(eslint@8.57.0)(typescript@5.3.3))(eslint@8.57.0)(jest@29.7.0(@types/node@22.5.0)(ts-node@10.9.2(@types/node@22.5.0)(typescript@5.3.3)))(typescript@5.3.3): + dependencies: + '@typescript-eslint/utils': 7.18.0(eslint@8.57.0)(typescript@5.3.3) + eslint: 8.57.0 + optionalDependencies: + '@typescript-eslint/eslint-plugin': 5.62.0(@typescript-eslint/parser@5.62.0(eslint@8.57.0)(typescript@5.3.3))(eslint@8.57.0)(typescript@5.3.3) + jest: 29.7.0(@types/node@22.5.0)(ts-node@10.9.2(@types/node@22.5.0)(typescript@5.3.3)) + transitivePeerDependencies: + - supports-color + - typescript + eslint-plugin-prettier@5.2.1(eslint-config-prettier@9.1.0(eslint@8.57.0))(eslint@8.57.0)(prettier@3.3.3): dependencies: eslint: 8.57.0 diff --git a/src/api/common/api-provider.tsx b/src/api/common/api-provider.tsx index 1f86b8c6..6139e293 100644 --- a/src/api/common/api-provider.tsx +++ b/src/api/common/api-provider.tsx @@ -1,8 +1,9 @@ import { useReactQueryDevTools } from '@dev-plugins/react-query'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; +import { type ReactNode } from 'react'; export const queryClient = new QueryClient(); -export function APIProvider({ children }: { children: React.ReactNode }) { +export function APIProvider({ children }: { children: ReactNode }) { useReactQueryDevTools(queryClient); return ( // Provide the client to your App diff --git a/src/app/_layout.tsx b/src/app/_layout.tsx index 25177696..577edcc5 100644 --- a/src/app/_layout.tsx +++ b/src/app/_layout.tsx @@ -4,6 +4,7 @@ import '../../global.css'; import { BottomSheetModalProvider } from '@gorhom/bottom-sheet'; import { ThemeProvider } from '@react-navigation/native'; import { SplashScreen, Stack } from 'expo-router'; +import React from 'react'; import { StyleSheet } from 'react-native'; import FlashMessage from 'react-native-flash-message'; import { GestureHandlerRootView } from 'react-native-gesture-handler'; diff --git a/src/app/feed/add-post.tsx b/src/app/feed/add-post.tsx index 4ff5fbda..aa2021d7 100644 --- a/src/app/feed/add-post.tsx +++ b/src/app/feed/add-post.tsx @@ -21,7 +21,6 @@ export default function AddPost() { const { mutate: addPost, isPending } = useAddPost(); const onSubmit = (data: FormType) => { - console.log(data); addPost( { ...data, userId: 1 }, { diff --git a/src/app/onboarding.tsx b/src/app/onboarding.tsx index f38ba74b..1de43a14 100644 --- a/src/app/onboarding.tsx +++ b/src/app/onboarding.tsx @@ -4,7 +4,7 @@ import { Cover } from '@/components/cover'; import { useIsFirstTime } from '@/core/hooks'; import { Button, FocusAwareStatusBar, SafeAreaView, Text, View } from '@/ui'; export default function Onboarding() { - const [_, setIsFirstTime] = useIsFirstTime(); + const [, setIsFirstTime] = useIsFirstTime(); const router = useRouter(); return ( diff --git a/src/components/settings/item.tsx b/src/components/settings/item.tsx index f8cf35b7..71407741 100644 --- a/src/components/settings/item.tsx +++ b/src/components/settings/item.tsx @@ -1,3 +1,5 @@ +import React from 'react'; + import type { TxKeyPath } from '@/core'; import { Pressable, Text, View } from '@/ui'; import { ArrowRight } from '@/ui/icons'; diff --git a/src/components/settings/items-container.tsx b/src/components/settings/items-container.tsx index 8f0fcf1e..4ece303a 100644 --- a/src/components/settings/items-container.tsx +++ b/src/components/settings/items-container.tsx @@ -1,3 +1,5 @@ +import React from 'react'; + import type { TxKeyPath } from '@/core'; import { Text, View } from '@/ui'; diff --git a/src/core/auth/index.tsx b/src/core/auth/index.tsx index 0e0d426d..63347c4a 100644 --- a/src/core/auth/index.tsx +++ b/src/core/auth/index.tsx @@ -1,8 +1,7 @@ import { create } from 'zustand'; import { createSelectors } from '../utils'; -import type { TokenType } from './utils'; -import { getToken, removeToken, setToken } from './utils'; +import { getToken, removeToken, setToken, type TokenType } from './utils'; interface AuthState { token: TokenType | null; @@ -31,7 +30,7 @@ const _useAuth = create((set, get) => ({ } else { get().signOut(); } - } catch (e) { + } catch (_) { // catch error here // Maybe sign_out user! } diff --git a/src/core/hooks/use-selected-theme.tsx b/src/core/hooks/use-selected-theme.tsx index a5bc1f6f..b370d4b2 100644 --- a/src/core/hooks/use-selected-theme.tsx +++ b/src/core/hooks/use-selected-theme.tsx @@ -14,7 +14,7 @@ export type ColorSchemeType = 'light' | 'dark' | 'system'; * */ export const useSelectedTheme = () => { - const { colorScheme: _color, setColorScheme } = useColorScheme(); + const { setColorScheme } = useColorScheme(); const [theme, _setTheme] = useMMKVString(SELECTED_THEME, storage); const setSelectedTheme = useCallback( @@ -32,7 +32,6 @@ export const useSelectedTheme = () => { export const loadSelectedTheme = () => { const theme = storage.getString(SELECTED_THEME); if (theme !== undefined) { - console.log('theme', theme); colorScheme.set(theme as ColorSchemeType); } }; diff --git a/src/core/test-utils.tsx b/src/core/test-utils.tsx index 65d9b006..0f133034 100644 --- a/src/core/test-utils.tsx +++ b/src/core/test-utils.tsx @@ -5,6 +5,7 @@ import { NavigationContainer } from '@react-navigation/native'; import type { RenderOptions } from '@testing-library/react-native'; import { render } from '@testing-library/react-native'; import type { ReactElement } from 'react'; +import React from 'react'; const createAppWrapper = () => ({ children }: { children: React.ReactNode }) => ( {children} diff --git a/src/ui/focus-aware-status-bar.tsx b/src/ui/focus-aware-status-bar.tsx index f7ad844a..315d6ee9 100644 --- a/src/ui/focus-aware-status-bar.tsx +++ b/src/ui/focus-aware-status-bar.tsx @@ -1,5 +1,6 @@ import { useIsFocused } from '@react-navigation/native'; import { useColorScheme } from 'nativewind'; +import React from 'react'; import { StatusBar } from 'react-native'; type Props = React.ComponentProps; diff --git a/src/ui/utils.tsx b/src/ui/utils.tsx index 9a189234..452e1548 100644 --- a/src/ui/utils.tsx +++ b/src/ui/utils.tsx @@ -10,7 +10,6 @@ export const HEIGHT = height; // for onError react queries and mutations export const showError = (error: AxiosError) => { - console.log(JSON.stringify(error?.response?.data)); const description = extractError(error?.response?.data).trimEnd(); showMessage({ From 30113bd417db65e94ac4612232ba3418ff7231bf Mon Sep 17 00:00:00 2001 From: Fernanda Toledo Date: Wed, 11 Sep 2024 14:40:35 -0300 Subject: [PATCH 3/3] chore: accept no console for error --- .eslintrc.js | 3 ++- env.js | 1 + src/api/common/api-provider.tsx | 2 +- src/app/login.tsx | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 48ee2600..dc859781 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -79,7 +79,8 @@ module.exports = { }, ], 'object-shorthand': 'error', - 'arrow-body-style': ["error", "as-needed"] + 'arrow-body-style': ["error", "as-needed"], + 'no-console': ['error', {allow: ['error']}] }, overrides: [ // Configuration for translations files (i18next) diff --git a/env.js b/env.js index a6d4b854..17293509 100644 --- a/env.js +++ b/env.js @@ -219,6 +219,7 @@ if (shouldValidateEnv) { ); } + console.error(...messages); throw new Error( 'Invalid environment variables, Check terminal for more details ' ); diff --git a/src/api/common/api-provider.tsx b/src/api/common/api-provider.tsx index 6139e293..b02d3949 100644 --- a/src/api/common/api-provider.tsx +++ b/src/api/common/api-provider.tsx @@ -3,7 +3,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { type ReactNode } from 'react'; export const queryClient = new QueryClient(); -export function APIProvider({ children }: { children: ReactNode }) { +export function APIProvider({ children }: Readonly<{ children: ReactNode }>) { useReactQueryDevTools(queryClient); return ( // Provide the client to your App diff --git a/src/app/login.tsx b/src/app/login.tsx index 4557a03f..28a51d0e 100644 --- a/src/app/login.tsx +++ b/src/app/login.tsx @@ -10,6 +10,7 @@ export default function Login() { const signIn = useAuth.use.signIn(); const onSubmit: LoginFormProps['onSubmit'] = (data) => { + // eslint-disable-next-line no-console console.log(data); signIn({ access: 'access-token', refresh: 'refresh-token' }); router.push('/');