From 1f1868dfdd31a87cd8da36b682293d4c44d33720 Mon Sep 17 00:00:00 2001 From: james Date: Wed, 25 Oct 2023 10:39:36 +0800 Subject: [PATCH] Enforce prettier and eslint at commit, ran on all files --- .pre-commit-config.yaml | 35 ++++++++++++- frontend/package-lock.json | 45 +++++++++------- frontend/package.json | 8 +-- frontend/src/app.d.ts | 2 +- frontend/src/lib/utils/generateIds.ts | 2 +- frontend/src/routes/+layout.server.ts | 51 +++++++++---------- frontend/src/routes/+page.server.ts | 4 +- frontend/src/routes/apps/[id]/+page.server.ts | 6 +-- .../collections/[collection]/+page.server.ts | 45 ++++++++-------- .../collections/[collection]/+page.svelte | 1 + frontend/src/stores.ts | 2 +- frontend/tailwind.config.ts | 17 +++---- 12 files changed, 123 insertions(+), 95 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 81ce144..a7a134f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,12 +1,12 @@ repos: # Black - repo: https://github.com/psf/black - rev: 23.10.0 + rev: 23.10.1 hooks: - id: black # Ruff - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: v0.1.1 + rev: v0.1.2 hooks: - id: ruff # Mypy @@ -15,3 +15,34 @@ repos: hooks: - id: mypy additional_dependencies: ["types-requests", "types-PyYAML"] + ## JS ## + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v3.0.3 + hooks: + - id: prettier + args: ['--config', 'frontend/.prettierrc', '--ignore-unknown', '--write', '--check'] + language: node + entry: frontend/node_modules/.bin/prettier + require_serial: true + files: ^frontend/.*\.(js|jsx|ts|tsx|css|svelte)$ + additional_dependencies: + - prettier@2.8.8 + - prettier-plugin-svelte@2.10.1 + - repo: https://github.com/pre-commit/mirrors-eslint + rev: v8.52.0 + hooks: + - id: eslint + name: eslint + language: node + entry: frontend/node_modules/eslint/bin/eslint.js + #args: ['--fix'] #lets wait before using this + require_serial: true + files: \.(js|ts|svelte)$ + additional_dependencies: + - eslint + - svelte + - typescript + - eslint-plugin-svelte + - "@typescript-eslint/eslint-plugin" + - "@typescript-eslint/parser" + - svelte-eslint-parser diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 04f6187..22524be 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -20,14 +20,14 @@ "@typescript-eslint/eslint-plugin": "^6.0.0", "@typescript-eslint/parser": "^6.0.0", "autoprefixer": "^10.4.14", - "eslint": "^8.28.0", + "eslint": "^8.52.0", "eslint-config-prettier": "^8.5.0", - "eslint-plugin-svelte": "^2.30.0", + "eslint-plugin-svelte": "^2.34.0", "postcss": "^8.4.24", "postcss-load-config": "^4.0.1", - "prettier": "^2.8.0", + "prettier": "^2.8.8", "prettier-plugin-svelte": "^2.10.1", - "svelte": "^4.0.5", + "svelte": "^4.2.2", "svelte-check": "^3.4.3", "tailwindcss": "^3.3.2", "tslib": "^2.4.1", @@ -469,9 +469,9 @@ } }, "node_modules/@eslint/js": { - "version": "8.51.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.51.0.tgz", - "integrity": "sha512-HxjQ8Qn+4SI3/AFv6sOrDB+g6PpUTDwSJiQqOrnneEk8L71161srI9gjzzZvYVbzHiVg/BvcH95+cK/zfIt4pg==", + "version": "8.52.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.52.0.tgz", + "integrity": "sha512-mjZVbpaeMZludF2fsWLD0Z9gCref1Tk4i9+wddjRvpUNqqcndPkBD09N/Mapey0b3jaXbLm2kICwFv2E64QinA==", "dev": true, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" @@ -487,12 +487,12 @@ } }, "node_modules/@humanwhocodes/config-array": { - "version": "0.11.12", - "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.12.tgz", - "integrity": "sha512-NlGesA1usRNn6ctHCZ21M4/dKPgW9Nn1FypRdIKKgZOKzkVV4T1FlK5mBiLhHBCDmEbdQG0idrcXlbZfksJ+RA==", + "version": "0.11.13", + "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.13.tgz", + "integrity": "sha512-JSBDMiDKSzQVngfRjOdFXgFfklaXI4K9nLF49Auh21lmBWRLIK3+xTErTWD4KU54pb6coM6ESE7Awz/FNU3zgQ==", "dev": true, "dependencies": { - "@humanwhocodes/object-schema": "^2.0.0", + "@humanwhocodes/object-schema": "^2.0.1", "debug": "^4.1.1", "minimatch": "^3.0.5" }, @@ -514,9 +514,9 @@ } }, "node_modules/@humanwhocodes/object-schema": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-2.0.0.tgz", - "integrity": "sha512-9S9QrXY2K0L4AGDcSgTi9vgiCcG8VcBv4Mp7/1hDPYoswIy6Z6KO5blYto82BT8M0MZNRWmCFLpCs3HlpYGGdw==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-2.0.1.tgz", + "integrity": "sha512-dvuCeX5fC9dXgJn9t+X5atfmgQAzUOWqS1254Gh0m6i8wKd10ebXkfNKiRK+1GWi/yTvvLDHpoxLr0xxxeslWw==", "dev": true }, "node_modules/@jridgewell/gen-mapping": { @@ -1114,6 +1114,12 @@ "url": "https://opencollective.com/typescript-eslint" } }, + "node_modules/@ungap/structured-clone": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.0.tgz", + "integrity": "sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==", + "dev": true + }, "node_modules/acorn": { "version": "8.10.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.10.0.tgz", @@ -1716,18 +1722,19 @@ } }, "node_modules/eslint": { - "version": "8.51.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.51.0.tgz", - "integrity": "sha512-2WuxRZBrlwnXi+/vFSJyjMqrNjtJqiasMzehF0shoLaW7DzS3/9Yvrmq5JiT66+pNjiX4UBnLDiKHcWAr/OInA==", + "version": "8.52.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.52.0.tgz", + "integrity": "sha512-zh/JHnaixqHZsolRB/w9/02akBk9EPrOs9JwcTP2ek7yL5bVvXuRariiaAjjoJ5DvuwQ1WAE/HsMz+w17YgBCg==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.6.1", "@eslint/eslintrc": "^2.1.2", - "@eslint/js": "8.51.0", - "@humanwhocodes/config-array": "^0.11.11", + "@eslint/js": "8.52.0", + "@humanwhocodes/config-array": "^0.11.13", "@humanwhocodes/module-importer": "^1.0.1", "@nodelib/fs.walk": "^1.2.8", + "@ungap/structured-clone": "^1.2.0", "ajv": "^6.12.4", "chalk": "^4.0.0", "cross-spawn": "^7.0.2", diff --git a/frontend/package.json b/frontend/package.json index b3155a0..ddacec4 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -21,14 +21,14 @@ "@typescript-eslint/eslint-plugin": "^6.0.0", "@typescript-eslint/parser": "^6.0.0", "autoprefixer": "^10.4.14", - "eslint": "^8.28.0", + "eslint": "^8.52.0", "eslint-config-prettier": "^8.5.0", - "eslint-plugin-svelte": "^2.30.0", + "eslint-plugin-svelte": "^2.34.0", "postcss": "^8.4.24", "postcss-load-config": "^4.0.1", - "prettier": "^2.8.0", + "prettier": "^2.8.8", "prettier-plugin-svelte": "^2.10.1", - "svelte": "^4.0.5", + "svelte": "^4.2.2", "svelte-check": "^3.4.3", "tailwindcss": "^3.3.2", "tslib": "^2.4.1", diff --git a/frontend/src/app.d.ts b/frontend/src/app.d.ts index 712552b..73d6146 100644 --- a/frontend/src/app.d.ts +++ b/frontend/src/app.d.ts @@ -10,4 +10,4 @@ declare global { } } -export { }; +export {}; diff --git a/frontend/src/lib/utils/generateIds.ts b/frontend/src/lib/utils/generateIds.ts index a501e65..c74ccb1 100644 --- a/frontend/src/lib/utils/generateIds.ts +++ b/frontend/src/lib/utils/generateIds.ts @@ -1,5 +1,5 @@ let n: number = Date.now(); export default function (): string { - return (++n).toString(36); + return (++n).toString(36); } diff --git a/frontend/src/routes/+layout.server.ts b/frontend/src/routes/+layout.server.ts index 2be7f4e..c7f9ad0 100644 --- a/frontend/src/routes/+layout.server.ts +++ b/frontend/src/routes/+layout.server.ts @@ -2,36 +2,31 @@ export const ssr = true; export const csr = false; export interface Categories { - mycats: any; - status?: number; - error?: string; + mycats: any; + status?: number; + error?: string; } - - /** @type {import('./$types').PageServerLoad} */ export async function load(): Promise { - console.log(`load categories start`); - try { - - const res = await fetch(`http://localhost:8000/api/categories`); - - if (!res.ok) { - throw new Error(`Failed to fetch categories with status ${res.status}`); - } - - const categories = await res.json(); - - console.log(`load categories len: ${Object.keys(categories).length}`); - return { mycats: categories }; - - } catch (error) { - console.error('Failed to load layout categories data:', error); - return { - mycats: null, - status: 500, - error: 'Failed to load categories' - }; - } + console.log(`load categories start`); + try { + const res = await fetch(`http://localhost:8000/api/categories`); + + if (!res.ok) { + throw new Error(`Failed to fetch categories with status ${res.status}`); + } + + const categories = await res.json(); + + console.log(`load categories len: ${Object.keys(categories).length}`); + return { mycats: categories }; + } catch (error) { + console.error('Failed to load layout categories data:', error); + return { + mycats: null, + status: 500, + error: 'Failed to load categories' + }; + } } - diff --git a/frontend/src/routes/+page.server.ts b/frontend/src/routes/+page.server.ts index 8d06c29..db1a3be 100644 --- a/frontend/src/routes/+page.server.ts +++ b/frontend/src/routes/+page.server.ts @@ -1,5 +1,5 @@ import { redirect } from '@sveltejs/kit'; export function load() { - throw redirect(307, '/collections/new_weekly'); -} \ No newline at end of file + throw redirect(307, '/collections/new_weekly'); +} diff --git a/frontend/src/routes/apps/[id]/+page.server.ts b/frontend/src/routes/apps/[id]/+page.server.ts index 70e04f5..19751d7 100644 --- a/frontend/src/routes/apps/[id]/+page.server.ts +++ b/frontend/src/routes/apps/[id]/+page.server.ts @@ -3,7 +3,8 @@ export const csr = false; /** @type {import('../[id]/$types').PageServerLoad} */ export async function load({ params }) { - console.log('load app started'); try { + console.log('load app started'); + try { const id = params.id; const res = await fetch(`http://localhost:8000/api/apps/${id}`); @@ -15,7 +16,6 @@ export async function load({ params }) { const app_detail = await res.json(); console.log(`loaded app_detail with len: ${Object.keys(app_detail).length}`); return { myapp: app_detail }; - } catch (error) { console.error('Failed to load app data:', error); return { @@ -24,5 +24,3 @@ export async function load({ params }) { }; } } - - diff --git a/frontend/src/routes/collections/[collection]/+page.server.ts b/frontend/src/routes/collections/[collection]/+page.server.ts index fbd8a94..fda2609 100644 --- a/frontend/src/routes/collections/[collection]/+page.server.ts +++ b/frontend/src/routes/collections/[collection]/+page.server.ts @@ -4,31 +4,32 @@ export const csr: boolean = true; console.log('Script executed'); interface LoadResponse { - myapps: any; - status?: number; - error?: string; + myapps: any; + status?: number; + error?: string; } + /** @type {import('../[collection]/$types').PageServerLoad} */ export async function load({ params }): Promise { - const collectionValue = params.collection - console.log(`load started collection=${collectionValue}`); - try { - const res = await fetch(`http://localhost:8000/api/apps/collections/${collectionValue}`); + const collectionValue = params.collection; + console.log(`load started collection=${collectionValue}`); + try { + const res = await fetch(`http://localhost:8000/api/apps/collections/${collectionValue}`); - if (!res.ok) { - const text = await res.text(); - throw new Error(`Failed to fetch collections status ${res.status} ${text}`); - } + if (!res.ok) { + const text = await res.text(); + throw new Error(`Failed to fetch collections status ${res.status} ${text}`); + } - const app_collections: any = await res.json(); - console.log(`loaded collections with len: ${Object.keys(app_collections).length}`); - return { myapps: app_collections }; - } catch (error) { - console.error('Failed to load data:', error); - return { - myapps: {}, - status: 500, - error: 'Failed to load trending apps' - }; - } + const app_collections: any = await res.json(); + console.log(`loaded collections with len: ${Object.keys(app_collections).length}`); + return { myapps: app_collections }; + } catch (error) { + console.error('Failed to load data:', error); + return { + myapps: {}, + status: 500, + error: 'Failed to load trending apps' + }; + } } diff --git a/frontend/src/routes/collections/[collection]/+page.svelte b/frontend/src/routes/collections/[collection]/+page.svelte index dfa44ee..df79350 100644 --- a/frontend/src/routes/collections/[collection]/+page.svelte +++ b/frontend/src/routes/collections/[collection]/+page.svelte @@ -5,6 +5,7 @@ function getClass(app) { return app.featured_image_url && app.featured_image_url !== 'null' ? 'col-span-2' : ''; } + import { myStoreSelection } from '../../../stores'; import { myCategorySelection } from '../../../stores'; diff --git a/frontend/src/stores.ts b/frontend/src/stores.ts index 7acaa5c..deee3a7 100644 --- a/frontend/src/stores.ts +++ b/frontend/src/stores.ts @@ -4,4 +4,4 @@ export const myCollectionStore = writable('new_weekly'); export const myStoreSelection = writable('google'); export const myCategorySelection = writable('overall'); -export const myCategoryMap = writable(); \ No newline at end of file +export const myCategoryMap = writable(); diff --git a/frontend/tailwind.config.ts b/frontend/tailwind.config.ts index ef3143d..41e065d 100644 --- a/frontend/tailwind.config.ts +++ b/frontend/tailwind.config.ts @@ -1,4 +1,3 @@ - import { join } from 'path'; import type { Config } from 'tailwindcss'; @@ -11,23 +10,20 @@ const config = { content: [ './src/**/*.{html,js,svelte,ts}', // 3. Append the path to the Skeleton package - join(require.resolve( - '@skeletonlabs/skeleton'), - '../**/*.{html,js,svelte,ts}' - ) + join(require.resolve('@skeletonlabs/skeleton'), '../**/*.{html,js,svelte,ts}') ], theme: { - extend: {}, + extend: {} }, plugins: [ // 4. Append the Skeleton plugin (after other plugins) skeleton({ themes: { preset: [ - { name: "skeleton", enhancements: true }, - { name: "vintage", enhancements: true }, - { name: "wintry", enhancements: true }, - { name: "modern", enhancements: true }, + { name: 'skeleton', enhancements: true }, + { name: 'vintage', enhancements: true }, + { name: 'wintry', enhancements: true }, + { name: 'modern', enhancements: true } ] } }) @@ -35,4 +31,3 @@ const config = { } satisfies Config; export default config; -