From 02dd41ea3f9679c5d40829609430d97ca2586ff6 Mon Sep 17 00:00:00 2001 From: Nada Date: Mon, 9 Oct 2023 09:31:10 +0400 Subject: [PATCH 1/3] feat: add prettier config --- .prettierrc | 12 +++- package.json | 69 +++++++++--------- src/App.tsx | 16 ++--- src/components/chart/tools/index.tsx | 38 +++++----- .../common/error-boundary/index.tsx | 71 +++++++++---------- src/components/layout/index.tsx | 16 ++--- src/contexts/authProvider.tsx | 16 ++--- src/hooks/useAuth.ts | 4 +- src/hooks/useAuthAction.ts | 4 +- src/hooks/useResponsive.ts | 2 +- src/main.tsx | 14 ++-- src/utils/cookies.ts | 4 +- src/utils/storage.ts | 8 +-- 13 files changed, 140 insertions(+), 134 deletions(-) diff --git a/.prettierrc b/.prettierrc index 0967ef424b..4ace530dcb 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1 +1,11 @@ -{} +{ + "endOfLine": "lf", + "singleQuote": true, + "useTabs": false, + "tabWidth": 4, + "trailingComma": "es5", + "printWidth": 120, + "jsxSingleQuote": true, + "arrowParens": "avoid", + "proseWrap": "preserve" +} diff --git a/package.json b/package.json index c3fc7f71a3..7373929e33 100644 --- a/package.json +++ b/package.json @@ -1,36 +1,37 @@ { - "name": "smarttrader", - "private": true, - "version": "0.0.0", - "type": "module", - "scripts": { - "dev": "vite", - "build": "tsc && vite build", - "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", - "preview": "vite preview", - "test": "vitest" - }, - "dependencies": { - "react": "^18.2.0", - "react-dom": "^18.2.0" - }, - "devDependencies": { - "@testing-library/jest-dom": "^6.1.3", - "@testing-library/react": "^14.0.0", - "@testing-library/user-event": "^14.5.1", - "@types/node": "^20.6.3", - "@types/react": "^18.2.15", - "@types/react-dom": "^18.2.7", - "@typescript-eslint/eslint-plugin": "^6.0.0", - "@typescript-eslint/parser": "^6.0.0", - "@vitejs/plugin-react": "^4.0.3", - "eslint": "^8.45.0", - "eslint-plugin-react-hooks": "^4.6.0", - "eslint-plugin-react-refresh": "^0.4.3", - "jsdom": "^22.1.0", - "prettier": "3.0.3", - "typescript": "^5.0.2", - "vite": "^4.4.5", - "vitest": "^0.34.5" - } + "name": "smarttrader", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "dev": "vite", + "build": "tsc && vite build", + "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", + "prettier": "prettier --write \"./src/**/*.{js,jsx,ts,tsx}\"", + "preview": "vite preview", + "test": "vitest" + }, + "dependencies": { + "react": "^18.2.0", + "react-dom": "^18.2.0" + }, + "devDependencies": { + "@testing-library/jest-dom": "^6.1.3", + "@testing-library/react": "^14.0.0", + "@testing-library/user-event": "^14.5.1", + "@types/node": "^20.6.3", + "@types/react": "^18.2.15", + "@types/react-dom": "^18.2.7", + "@typescript-eslint/eslint-plugin": "^6.0.0", + "@typescript-eslint/parser": "^6.0.0", + "@vitejs/plugin-react": "^4.0.3", + "eslint": "^8.45.0", + "eslint-plugin-react-hooks": "^4.6.0", + "eslint-plugin-react-refresh": "^0.4.3", + "jsdom": "^22.1.0", + "prettier": "3.0.3", + "typescript": "^5.0.2", + "vite": "^4.4.5", + "vitest": "^0.34.5" + } } diff --git a/src/App.tsx b/src/App.tsx index 1636ac8b9d..c01508007b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,13 +1,13 @@ -import ErrorBoundary from "Components/common/error-boundary"; -import Layout from "Components/layout"; -import AuthProvider from "Contexts/authProvider"; +import ErrorBoundary from 'Components/common/error-boundary'; +import Layout from 'Components/layout'; +import AuthProvider from 'Contexts/authProvider'; const App = () => ( - - - App - - + + + App + + ); export default App; diff --git a/src/components/chart/tools/index.tsx b/src/components/chart/tools/index.tsx index df06578c74..a18f5617c9 100644 --- a/src/components/chart/tools/index.tsx +++ b/src/components/chart/tools/index.tsx @@ -1,24 +1,24 @@ -import ChartTemplate from "./chart-template"; -import ChartType from "./chart-type"; -import Comparisons from "./comparisons"; -import DrawingTools from "./drawing-tools"; -import Indicators from "./indicators"; -import ShareChart from "./share-chart"; -import TimeInterval from "./time-interval"; +import ChartTemplate from './chart-template'; +import ChartType from './chart-type'; +import Comparisons from './comparisons'; +import DrawingTools from './drawing-tools'; +import Indicators from './indicators'; +import ShareChart from './share-chart'; +import TimeInterval from './time-interval'; const Tools = () => ( -
- - - - - - - -
+
+ + + + + + + +
); export default Tools; diff --git a/src/components/common/error-boundary/index.tsx b/src/components/common/error-boundary/index.tsx index a939dbef84..828f56e7fc 100644 --- a/src/components/common/error-boundary/index.tsx +++ b/src/components/common/error-boundary/index.tsx @@ -1,4 +1,4 @@ -import { Component, ErrorInfo, ReactNode } from "react"; +import { Component, ErrorInfo, ReactNode } from 'react'; /* By default, if our application throws an error during rendering, React will remove its UI from the screen. @@ -7,49 +7,46 @@ An error boundary is a special component that lets us display some fallback UI i */ type TErrorBoundaryProps = { - children?: ReactNode; + children?: ReactNode; }; type TErrorBoundaryStates = { - has_error: boolean; + has_error: boolean; }; -class ErrorBoundary extends Component< - TErrorBoundaryProps, - TErrorBoundaryStates -> { - constructor(props: TErrorBoundaryProps) { - super(props); - this.state = { has_error: false }; - } - - static getDerivedStateFromError(error: Error): TErrorBoundaryStates { - console.log("error: ", error); - /* Update state so the next render will show the fallback UI. */ - return { has_error: true }; - } - - componentDidCatch(error: Error, info: ErrorInfo) { - // Example "componentStack": - // in ComponentThatThrows (created by App) - // in ErrorBoundary (created by App) - // in div (created by App) - // in App - console.log(error, info.componentStack); - } - - render() { - const { has_error } = this.state; - const { children } = this.props; - - if (has_error) { - // we can render any custom fallback UI - // return fallback; - return

Sorry.. there was an error

; +class ErrorBoundary extends Component { + constructor(props: TErrorBoundaryProps) { + super(props); + this.state = { has_error: false }; } - return children; - } + static getDerivedStateFromError(error: Error): TErrorBoundaryStates { + console.log('error: ', error); + /* Update state so the next render will show the fallback UI. */ + return { has_error: true }; + } + + componentDidCatch(error: Error, info: ErrorInfo) { + // Example "componentStack": + // in ComponentThatThrows (created by App) + // in ErrorBoundary (created by App) + // in div (created by App) + // in App + console.log(error, info.componentStack); + } + + render() { + const { has_error } = this.state; + const { children } = this.props; + + if (has_error) { + // we can render any custom fallback UI + // return fallback; + return

Sorry.. there was an error

; + } + + return children; + } } export default ErrorBoundary; diff --git a/src/components/layout/index.tsx b/src/components/layout/index.tsx index 802c19b315..c421179bd7 100644 --- a/src/components/layout/index.tsx +++ b/src/components/layout/index.tsx @@ -1,13 +1,13 @@ -import { Fragment, PropsWithChildren } from "react"; -import Header from "./header"; -import Footer from "./footer"; +import { Fragment, PropsWithChildren } from 'react'; +import Header from './header'; +import Footer from './footer'; const Layout = ({ children }: PropsWithChildren) => ( - -
- {children} -