From 0e53cc0e8c299a9fcf1ce3eb179474a4cb6e3bc0 Mon Sep 17 00:00:00 2001 From: AkaraChen Date: Tue, 22 Oct 2024 14:15:22 +0800 Subject: [PATCH 1/4] fix: eslint indent --- web/eslint.config.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/eslint.config.mjs b/web/eslint.config.mjs index efd3cac12a..e8ab0fd8b3 100644 --- a/web/eslint.config.mjs +++ b/web/eslint.config.mjs @@ -51,7 +51,7 @@ export default combine( jsx: false, overrides: { // original config - "style/indent": "off", + "style/indent": ["error", 2], // these options does not exist in old version // maybe useless From 510ce057f7f8154a087bfd3d4a0694efb03827d2 Mon Sep 17 00:00:00 2001 From: nite-knite Date: Tue, 22 Oct 2024 14:18:55 +0800 Subject: [PATCH 2/4] chore: add package manager setting to vscode setting example --- web/.vscode/settings.example.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/web/.vscode/settings.example.json b/web/.vscode/settings.example.json index a2dfe7c669..ce5c9d6b01 100644 --- a/web/.vscode/settings.example.json +++ b/web/.vscode/settings.example.json @@ -21,5 +21,6 @@ "editor.defaultFormatter": "vscode.json-language-features" }, "typescript.tsdk": "node_modules/typescript/lib", - "typescript.enablePromptUseWorkspaceTsdk": true + "typescript.enablePromptUseWorkspaceTsdk": true, + "npm.packageManager": "pnpm" } From 4873e6e2a1486ad6e2d7e9a9d6d36ce137ee4eb7 Mon Sep 17 00:00:00 2001 From: AkaraChen Date: Tue, 22 Oct 2024 15:32:48 +0800 Subject: [PATCH 3/4] build: fix eslint stylistic --- web/eslint.config.mjs | 126 ++++++++++++++++++++++++------------------ 1 file changed, 73 insertions(+), 53 deletions(-) diff --git a/web/eslint.config.mjs b/web/eslint.config.mjs index e8ab0fd8b3..2ff4d704fd 100644 --- a/web/eslint.config.mjs +++ b/web/eslint.config.mjs @@ -1,7 +1,7 @@ import { - GLOB_JSX, GLOB_TESTS, GLOB_TSX, combine, javascript, node, - stylistic, typescript, unicorn - } from '@antfu/eslint-config' + GLOB_TESTS, combine, javascript, node, + stylistic, typescript, unicorn, +} from '@antfu/eslint-config' import path from 'node:path' import { fileURLToPath } from 'node:url' import js from '@eslint/js' @@ -21,27 +21,27 @@ const storybook = [ { plugins: ['storybook'], files: ['*.stories.@(ts|tsx|js|jsx|mjs|cjs)', '*.story.@(ts|tsx|js|jsx|mjs|cjs)'], - rules: { - 'react-hooks/rules-of-hooks': 'off', - 'import/no-anonymous-default-export': 'off', - 'storybook/await-interactions': 'error', - 'storybook/context-in-play-function': 'error', - 'storybook/default-exports': 'error', - 'storybook/hierarchy-separator': 'warn', - 'storybook/no-redundant-story-name': 'warn', - 'storybook/prefer-pascal-case': 'warn', - 'storybook/story-exports': 'error', - 'storybook/use-storybook-expect': 'error', - 'storybook/use-storybook-testing-library': 'error', - } + rules: { + 'react-hooks/rules-of-hooks': 'off', + 'import/no-anonymous-default-export': 'off', + 'storybook/await-interactions': 'error', + 'storybook/context-in-play-function': 'error', + 'storybook/default-exports': 'error', + 'storybook/hierarchy-separator': 'warn', + 'storybook/no-redundant-story-name': 'warn', + 'storybook/prefer-pascal-case': 'warn', + 'storybook/story-exports': 'error', + 'storybook/use-storybook-expect': 'error', + 'storybook/use-storybook-testing-library': 'error', + }, }, { plugins: ['storybook'], files: ['*.stories.@(ts|tsx|js|jsx|mjs|cjs)', '*.story.@(ts|tsx|js|jsx|mjs|cjs)'], - rules: { - 'storybook/no-uninstalled-addons': 'error', - } - } + rules: { + 'storybook/no-uninstalled-addons': 'error', + }, + }, ] export default combine( @@ -49,27 +49,41 @@ export default combine( lessOpinionated: true, // original @antfu/eslint-config does not support jsx jsx: false, + semi: false, + quotes: 'single', overrides: { // original config - "style/indent": ["error", 2], + 'style/indent': ['error', 2], + 'style/quotes': ['error', 'single'], + 'curly': ['error', 'multi-line'], + 'style/comma-spacing': ['error', { before: false, after: true }], + 'style/quote-props': ['warn', 'consistent-as-needed'], // these options does not exist in old version // maybe useless - "style/indent-binary-ops": "off", - "style/multiline-ternary": "off", + 'style/indent-binary-ops': 'off', + 'style/multiline-ternary': 'off', + 'antfu/top-level-function': 'off', + 'antfu/curly': 'off', + 'antfu/consistent-chaining': 'off', + + // copy from eslint-config-antfu 0.36.0 + 'style/brace-style': ['error', 'stroustrup', { allowSingleLine: true }], + 'style/dot-location': ['error', 'property'], + 'style/object-curly-newline': ['error', { consistent: true, multiline: true }], + 'style/object-property-newline': ['error', { allowMultiplePropertiesPerLine: true }], + 'style/template-curly-spacing': ['error', 'never'], + 'style/keyword-spacing': 'off', // not exist in old version, and big change - "style/quote-props": "off", - "style/member-delimiter-style": "off", - "style/quotes": "off", - "style/comma-dangle": "off", - } + 'style/member-delimiter-style': 'off', + }, }), typescript({ overrides: { // useful, but big change - "ts/no-empty-object-type": "off", - } + 'ts/no-empty-object-type': 'off', + }, }), javascript({ overrides: { @@ -77,8 +91,8 @@ export default combine( 'no-unused-vars': 'off', // useless - 'no-use-before-define': 'warn' - } + 'no-use-before-define': 'warn', + }, }), unicorn(), node(), @@ -96,30 +110,36 @@ export default combine( '**/.next/', '**/public/*', '**/*.json', - ] + ], }, { // orignal config rules: { // from old version of antfu/eslint-config // typescript will handle this, see https://typescript-eslint.io/troubleshooting/faqs/eslint/#i-get-errors-from-the-no-undef-rule-about-global-variables-not-being-defined-even-though-there-are-no-typescript-errors - "no-undef": "off", + 'no-undef': 'off', 'ts/consistent-type-definitions': ['error', 'type'], // orignal ts/no-var-requires 'ts/no-require-imports': 'off', - "no-console": 'off', - "react-hooks/exhaustive-deps": "warn", - "react/display-name": "off", + 'no-console': 'off', + 'react-hooks/exhaustive-deps': 'warn', + 'react/display-name': 'off', + 'array-callback-return': ['error', { + allowImplicit: false, + checkForEach: false, + }], - // orignal config, but removed in new version antfu/eslint-config - // big change - "curly": "off", + // copy from eslint-config-antfu 0.36.0 + 'camelcase': 'off', + 'curly': ['error', 'multi-or-nest', 'consistent'], + 'default-case-last': 'error', + 'dot-notation': ['error', { allowKeywords: true }], + 'new-cap': ['error', { newIsCap: true, capIsNew: false, properties: true }], // antfu use eslint-plugin-perfectionist to replace this - // will cause big change, so keep the original - // sort-imports - "sort-imports": [ + // will cause big change, so keep the original sort-imports + 'sort-imports': [ 'error', { ignoreCase: false, @@ -131,8 +151,8 @@ export default combine( ], // antfu migrate to eslint-plugin-unused-imports - "unused-imports/no-unused-vars": "warn", - "unused-imports/no-unused-imports": "warn", + 'unused-imports/no-unused-vars': 'warn', + 'unused-imports/no-unused-imports': 'warn', }, languageOptions: { @@ -140,25 +160,25 @@ export default combine( ...globals.browser, ...globals.es2025, ...globals.node, - 'React': 'readable', - 'JSX': 'readable', - } - } + React: 'readable', + JSX: 'readable', + }, + }, }, storybook, // need futher research { rules: { // not exist in old version - "antfu/consistent-list-newline": "off", + 'antfu/consistent-list-newline': 'off', 'node/prefer-global/process': 'off', 'node/prefer-global/buffer': 'off', 'node/no-callback-literal': 'off', // useful, but big change - "unicorn/prefer-number-properties": "warn", - "unicorn/no-new-array": "warn" - } + 'unicorn/prefer-number-properties': 'warn', + 'unicorn/no-new-array': 'warn', + }, }, // suppress error for `no-undef` rule { From ff31f0540a6199daf78d586c5b5920e6c691ec97 Mon Sep 17 00:00:00 2001 From: AkaraChen Date: Tue, 22 Oct 2024 15:32:58 +0800 Subject: [PATCH 4/4] style: lint --- web/.storybook/main.ts | 28 ++++++------- web/.storybook/preview.tsx | 40 +++++++++---------- web/app/components/app/overview/appChart.tsx | 6 +-- .../app/overview/embedded/index.tsx | 8 ++-- .../base/portal-to-follow-elem/index.tsx | 6 +-- .../install-from-github/index.tsx | 2 +- web/hooks/use-metadata.ts | 28 ++++++------- 7 files changed, 59 insertions(+), 59 deletions(-) diff --git a/web/.storybook/main.ts b/web/.storybook/main.ts index 74e95821de..fecf774e98 100644 --- a/web/.storybook/main.ts +++ b/web/.storybook/main.ts @@ -1,19 +1,19 @@ import type { StorybookConfig } from '@storybook/nextjs' const config: StorybookConfig = { - // stories: ['../stories/**/*.mdx', '../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)'], - stories: ['../app/components/**/*.stories.@(js|jsx|mjs|ts|tsx)'], - addons: [ - '@storybook/addon-onboarding', - '@storybook/addon-links', - '@storybook/addon-essentials', - '@chromatic-com/storybook', - '@storybook/addon-interactions', - ], - framework: { - name: '@storybook/nextjs', - options: {}, - }, - staticDirs: ['../public'], + // stories: ['../stories/**/*.mdx', '../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)'], + stories: ['../app/components/**/*.stories.@(js|jsx|mjs|ts|tsx)'], + addons: [ + '@storybook/addon-onboarding', + '@storybook/addon-links', + '@storybook/addon-essentials', + '@chromatic-com/storybook', + '@storybook/addon-interactions', + ], + framework: { + name: '@storybook/nextjs', + options: {}, + }, + staticDirs: ['../public'], } export default config diff --git a/web/.storybook/preview.tsx b/web/.storybook/preview.tsx index 7a254bc79c..55328602f9 100644 --- a/web/.storybook/preview.tsx +++ b/web/.storybook/preview.tsx @@ -8,30 +8,30 @@ import '../app/styles/markdown.scss' import './storybook.css' export const decorators = [ - withThemeByDataAttribute({ - themes: { - light: 'light', - dark: 'dark', - }, - defaultTheme: 'light', - attributeName: 'data-theme', - }), - (Story) => { - return - - - } - ] + withThemeByDataAttribute({ + themes: { + light: 'light', + dark: 'dark', + }, + defaultTheme: 'light', + attributeName: 'data-theme', + }), + (Story) => { + return + + + }, +] const preview: Preview = { parameters: { - controls: { - matchers: { - color: /(background|color)$/i, - date: /Date$/i, - }, - }, + controls: { + matchers: { + color: /(background|color)$/i, + date: /Date$/i, + }, }, + }, } export default preview diff --git a/web/app/components/app/overview/appChart.tsx b/web/app/components/app/overview/appChart.tsx index e0788bcda3..d1426caa27 100644 --- a/web/app/components/app/overview/appChart.tsx +++ b/web/app/components/app/overview/appChart.tsx @@ -216,8 +216,8 @@ const Chart: React.FC = ({ return `
${params.name}
${valueFormatter((params.data as any)[yField])} ${!CHART_TYPE_CONFIG[chartType].showTokens - ? '' - : ` + ? '' + : ` ( ~$${get(params.data, 'total_price', 0)} ) @@ -243,7 +243,7 @@ const Chart: React.FC = ({ ? '' : {t('appOverview.analysis.tokenUsage.consumed')} Tokens ( - ~{sum(statistics.map(item => parseFloat(get(item, 'total_price', '0')))).toLocaleString('en-US', { style: 'currency', currency: 'USD', minimumFractionDigits: 4 })} + ~{sum(statistics.map(item => Number.parseFloat(get(item, 'total_price', '0')))).toLocaleString('en-US', { style: 'currency', currency: 'USD', minimumFractionDigits: 4 })} ) } textStyle={{ main: `!text-3xl !font-normal ${sumData === 0 ? '!text-gray-300' : ''}` }} /> diff --git a/web/app/components/app/overview/embedded/index.tsx b/web/app/components/app/overview/embedded/index.tsx index b71a3c3fdf..1e8fb68e49 100644 --- a/web/app/components/app/overview/embedded/index.tsx +++ b/web/app/components/app/overview/embedded/index.tsx @@ -35,12 +35,12 @@ const OPTION_MAP = { `