From 3a9941f69f6c15328b00d16ebb2ee3995a215096 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sat, 16 Sep 2023 16:07:30 +0200 Subject: [PATCH] Format code --- .editorconfig | 2 +- .github/workflows/coding-style.yml | 2 +- front/.prettierignore | 1 + front/apps/mobile/app.config.js | 4 +- front/apps/mobile/metro.config.js | 5 +- front/apps/web/next.config.js | 3 +- front/apps/web/src/pages/_app.tsx | 17 +++-- front/apps/web/src/router.tsx | 5 +- front/package.json | 4 +- front/packages/models/src/accounts.tsx | 11 +-- front/packages/models/src/accounts.web.ts | 2 +- front/packages/models/src/index.ts | 4 +- .../packages/models/src/resources/episode.ts | 2 +- front/packages/models/src/secure-store.ts | 12 ++-- front/packages/models/src/traits/images.ts | 5 +- front/packages/primitives/src/alert.tsx | 8 +-- front/packages/primitives/src/alert.web.tsx | 6 +- front/packages/primitives/src/avatar.tsx | 7 +- front/packages/primitives/src/divider.tsx | 2 +- .../primitives/src/image/base-image.tsx | 4 +- front/packages/primitives/src/input.tsx | 2 +- front/packages/primitives/src/links.tsx | 6 +- front/packages/primitives/src/skeleton.tsx | 2 +- front/packages/primitives/src/slider.tsx | 2 +- front/packages/primitives/src/text.tsx | 7 +- front/packages/primitives/src/themes/index.ts | 1 - front/packages/primitives/src/utils/head.tsx | 8 ++- .../primitives/src/utils/head.web.tsx | 8 ++- front/packages/ui/src/browse/header.tsx | 9 ++- front/packages/ui/src/browse/index.tsx | 4 +- front/packages/ui/src/browse/list.tsx | 8 ++- front/packages/ui/src/fetch-infinite.web.tsx | 11 ++- front/packages/ui/src/login/register.tsx | 7 +- .../ui/src/player/components/hover.tsx | 4 +- .../ui/src/player/components/left-buttons.tsx | 11 +-- .../ui/src/player/react-native-video.d.ts | 70 +++++++++---------- front/packages/ui/src/player/state.tsx | 6 +- .../ui/src/player/subtitle-octopus.d.ts | 4 +- front/packages/ui/src/player/video.tsx | 2 +- front/packages/ui/src/player/video.web.tsx | 10 +-- shell.nix | 2 + 41 files changed, 164 insertions(+), 126 deletions(-) create mode 100644 front/.prettierignore diff --git a/.editorconfig b/.editorconfig index 5344f175..a9140c63 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,6 +9,6 @@ indent_style = tab indent_size = tab smart_tab = true -[{*.yaml,*.yml}] +[{*.yaml,*.yml,*.nix}] indent_style = space indent_size = 2 diff --git a/.github/workflows/coding-style.yml b/.github/workflows/coding-style.yml index 1d4bd577..fd07b739 100644 --- a/.github/workflows/coding-style.yml +++ b/.github/workflows/coding-style.yml @@ -40,7 +40,7 @@ jobs: run: yarn install --immutable - name: Lint - run: yarn lint + run: yarn lint && yarn format scanner: name: "Lint scanner" diff --git a/front/.prettierignore b/front/.prettierignore new file mode 100644 index 00000000..61c3bc75 --- /dev/null +++ b/front/.prettierignore @@ -0,0 +1 @@ +.yarn diff --git a/front/apps/mobile/app.config.js b/front/apps/mobile/app.config.js index 9d328956..123b542f 100644 --- a/front/apps/mobile/app.config.js +++ b/front/apps/mobile/app.config.js @@ -68,9 +68,7 @@ const config = { projectId: "55de6b52-c649-4a15-9a45-569ff5ed036c", }, }, - plugins: [ - "expo-build-properties" - ], + plugins: ["expo-build-properties"], }, }; export default config; diff --git a/front/apps/mobile/metro.config.js b/front/apps/mobile/metro.config.js index 0405694a..e1528c71 100644 --- a/front/apps/mobile/metro.config.js +++ b/front/apps/mobile/metro.config.js @@ -62,10 +62,7 @@ module.exports = addMonorepoSupport( ...defaultConfig, resolver: { ...defaultConfig.resolver, - requireCycleIgnorePatterns: [ - ...defaultConfig.resolver.requireCycleIgnorePatterns, - /.*/, - ], + requireCycleIgnorePatterns: [...defaultConfig.resolver.requireCycleIgnorePatterns, /.*/], }, }), ); diff --git a/front/apps/web/next.config.js b/front/apps/web/next.config.js index abeb7f64..c4842716 100755 --- a/front/apps/web/next.config.js +++ b/front/apps/web/next.config.js @@ -48,7 +48,8 @@ const nextConfig = { alias: { ...config.resolve.alias, "react-native$": "react-native-web", - 'react-native/Libraries/Image/AssetRegistry$': 'react-native-web/dist/modules/AssetRegistry', + "react-native/Libraries/Image/AssetRegistry$": + "react-native-web/dist/modules/AssetRegistry", }, extensions: [".web.ts", ".web.tsx", ".web.js", ".web.jsx", ...config.resolve.extensions], }; diff --git a/front/apps/web/src/pages/_app.tsx b/front/apps/web/src/pages/_app.tsx index 22d1a9b6..f4c1d7bc 100755 --- a/front/apps/web/src/pages/_app.tsx +++ b/front/apps/web/src/pages/_app.tsx @@ -23,7 +23,13 @@ import "../polyfill"; import { Hydrate, QueryClientProvider } from "@tanstack/react-query"; import { HiddenIfNoJs, SkeletonCss, ThemeSelector } from "@kyoo/primitives"; import { WebTooltip } from "@kyoo/primitives/src/tooltip.web"; -import { createQueryClient, fetchQuery, getTokenWJ, QueryIdentifier, QueryPage } from "@kyoo/models"; +import { + createQueryClient, + fetchQuery, + getTokenWJ, + QueryIdentifier, + QueryPage, +} from "@kyoo/models"; import { setSecureItem } from "@kyoo/models/src/secure-store.web"; import { useState } from "react"; import NextApp, { AppContext, type AppProps } from "next/app"; @@ -73,7 +79,11 @@ const GlobalCssTheme = () => { ::cue { background-color: transparent; - text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000; + text-shadow: + -1px -1px 0 #000, + 1px -1px 0 #000, + -1px 1px 0 #000, + 1px 1px 0 #000; } `} @@ -100,8 +110,7 @@ const App = ({ Component, pageProps }: AppProps) => { useMobileHover(); // Set the auth from the server (if the token was refreshed during SSR). - if (typeof window !== "undefined" && token) - setSecureItem("auth", JSON.stringify(token)); + if (typeof window !== "undefined" && token) setSecureItem("auth", JSON.stringify(token)); return ( diff --git a/front/apps/web/src/router.tsx b/front/apps/web/src/router.tsx index 571fa0dd..7a8760ac 100644 --- a/front/apps/web/src/router.tsx +++ b/front/apps/web/src/router.tsx @@ -21,7 +21,10 @@ import { useRouter } from "next/router"; import { ComponentType } from "react"; -export const withRoute = (Component: ComponentType, defaultProps?: Partial) => { +export const withRoute = ( + Component: ComponentType, + defaultProps?: Partial, +) => { const WithUseRoute = (props: Props) => { const router = useRouter(); diff --git a/front/package.json b/front/package.json index 3ff5d777..1a9beb00 100644 --- a/front/package.json +++ b/front/package.json @@ -9,7 +9,9 @@ "build:mobile": "yarn workspace mobile build", "build:mobile:dev": "yarn workspace mobile build:dev", "update": "yarn workspace mobile update", - "lint": "eslint ." + "lint": "eslint .", + "format": "prettier -c .", + "format:fix": "prettier -w ." }, "eslintIgnore": [ "next-env.d.ts" diff --git a/front/packages/models/src/accounts.tsx b/front/packages/models/src/accounts.tsx index f39370df..072a8d64 100644 --- a/front/packages/models/src/accounts.tsx +++ b/front/packages/models/src/accounts.tsx @@ -27,7 +27,9 @@ import { Account, loginFunc } from "./login"; export const AccountContext = createContext>({ type: "loading" }); export const useAccounts = () => { - const [accounts, setAccounts] = useState(JSON.parse(getSecureItem("accounts") ?? "[]")); + const [accounts, setAccounts] = useState( + JSON.parse(getSecureItem("accounts") ?? "[]"), + ); const [verified, setVerified] = useState<{ status: "ok" | "error" | "loading" | "unverified"; error?: string; @@ -48,7 +50,7 @@ export const useAccounts = () => { useEffect(() => { async function check() { - setVerified({status: "loading"}); + setVerified({ status: "loading" }); const selAcc = accounts![selected!]; setApiUrl(selAcc.apiUrl); const verif = await loginFunc("refresh", selAcc.refresh_token, undefined, 5_000); @@ -57,8 +59,8 @@ export const useAccounts = () => { if (accounts.length && selected !== null) check(); else setVerified({ status: "unverified" }); - // Use the length of the array and not the array directly because we don't care if the refresh token changes. - // eslint-disable-next-line react-hooks/exhaustive-deps + // Use the length of the array and not the array directly because we don't care if the refresh token changes. + // eslint-disable-next-line react-hooks/exhaustive-deps }, [accounts.length, selected, retryCount]); useMMKVListener((key) => { @@ -87,4 +89,3 @@ export const useAccounts = () => { setSelected, } as const; }; - diff --git a/front/packages/models/src/accounts.web.ts b/front/packages/models/src/accounts.web.ts index ff6eb64a..d40e258e 100644 --- a/front/packages/models/src/accounts.web.ts +++ b/front/packages/models/src/accounts.web.ts @@ -20,6 +20,6 @@ import { createContext } from "react"; -export const useAccounts = () => {} +export const useAccounts = () => {}; export const AccountContext = createContext({}); diff --git a/front/packages/models/src/index.ts b/front/packages/models/src/index.ts index cfbd8dbe..2fbbad44 100644 --- a/front/packages/models/src/index.ts +++ b/front/packages/models/src/index.ts @@ -23,7 +23,7 @@ export * from "./resources"; export * from "./traits"; export * from "./page"; export * from "./kyoo-errors"; -export * from "./utils" -export * from "./login" +export * from "./utils"; +export * from "./login"; export * from "./query"; diff --git a/front/packages/models/src/resources/episode.ts b/front/packages/models/src/resources/episode.ts index 1d87131b..3bfaba11 100644 --- a/front/packages/models/src/resources/episode.ts +++ b/front/packages/models/src/resources/episode.ts @@ -85,7 +85,7 @@ export const EpisodeP = BaseEpisodeP.extend({ nextEpisode: BaseEpisodeP.nullable().optional(), show: ShowP.optional(), -}) +}); /** * A class to represent a single show's episode. diff --git a/front/packages/models/src/secure-store.ts b/front/packages/models/src/secure-store.ts index cbd09592..7a2886f0 100644 --- a/front/packages/models/src/secure-store.ts +++ b/front/packages/models/src/secure-store.ts @@ -18,19 +18,17 @@ * along with Kyoo. If not, see . */ -import { MMKV } from 'react-native-mmkv' +import { MMKV } from "react-native-mmkv"; export const storage = new MMKV(); export const setSecureItem = (key: string, value: string | null) => { - if (value === null) - storage.delete(key); - else - storage.set(key, value); -} + if (value === null) storage.delete(key); + else storage.set(key, value); +}; export const deleteSecureItem = (key: string) => setSecureItem(key, null); export const getSecureItem = (key: string, _cookies?: string): string | null => { return storage.getString(key) || null; -} +}; diff --git a/front/packages/models/src/traits/images.ts b/front/packages/models/src/traits/images.ts index 969bfd8b..eed6b026 100644 --- a/front/packages/models/src/traits/images.ts +++ b/front/packages/models/src/traits/images.ts @@ -22,10 +22,7 @@ import { Platform } from "react-native"; import { z } from "zod"; import { kyooApiUrl } from ".."; -export const imageFn = (url: string) => - Platform.OS === "web" - ? `/api${url}` - : kyooApiUrl + url; +export const imageFn = (url: string) => (Platform.OS === "web" ? `/api${url}` : kyooApiUrl + url); export const Img = z.object({ source: z.string(), diff --git a/front/packages/primitives/src/alert.tsx b/front/packages/primitives/src/alert.tsx index 332a6d25..d87f147e 100644 --- a/front/packages/primitives/src/alert.tsx +++ b/front/packages/primitives/src/alert.tsx @@ -18,14 +18,9 @@ * along with Kyoo. If not, see . */ - // Stolen from https://github.com/necolas/react-native-web/issues/1026#issuecomment-1458279681 -import { - Alert as RNAlert, - type AlertOptions, - type AlertButton, -} from "react-native"; +import { Alert as RNAlert, type AlertOptions, type AlertButton } from "react-native"; import { type SweetAlertIcon } from "sweetalert2"; export interface ExtendedAlertStatic { @@ -38,4 +33,3 @@ export interface ExtendedAlertStatic { } export const Alert: ExtendedAlertStatic = RNAlert as ExtendedAlertStatic; - diff --git a/front/packages/primitives/src/alert.web.tsx b/front/packages/primitives/src/alert.web.tsx index 3c16b02b..6ba044e0 100644 --- a/front/packages/primitives/src/alert.web.tsx +++ b/front/packages/primitives/src/alert.web.tsx @@ -33,10 +33,10 @@ export class Alert { const confirmButton = buttons ? buttons.find((button) => button.style === "default") : undefined; - const denyButton = buttons ? buttons.find((button) => button.style === "destructive") : undefined; - const cancelButton = buttons - ? buttons.find((button) => button.style === "cancel") + const denyButton = buttons + ? buttons.find((button) => button.style === "destructive") : undefined; + const cancelButton = buttons ? buttons.find((button) => button.style === "cancel") : undefined; Swal.fire({ title: title, diff --git a/front/packages/primitives/src/avatar.tsx b/front/packages/primitives/src/avatar.tsx index 97f021dd..584a55d3 100644 --- a/front/packages/primitives/src/avatar.tsx +++ b/front/packages/primitives/src/avatar.tsx @@ -99,12 +99,7 @@ export const Avatar = forwardRef< )} > {src || isLoading ? ( - {alt} + {alt} ) : placeholder ? (

theme.overlay0, borderWidth: 0, }, diff --git a/front/packages/primitives/src/image/base-image.tsx b/front/packages/primitives/src/image/base-image.tsx index 1e3a9179..5a7b7de2 100644 --- a/front/packages/primitives/src/image/base-image.tsx +++ b/front/packages/primitives/src/image/base-image.tsx @@ -25,8 +25,8 @@ import { YoshikiStyle } from "yoshiki/src/type"; export type YoshikiEnhanced