mirror of
https://github.com/langgenius/dify.git
synced 2026-04-05 10:12:43 +08:00
chore(web): new lint setup (#30020)
Co-authored-by: yyh <yuanyouhuilyz@gmail.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import type { AppIconType } from '@/types/app'
|
||||
import { useAsyncEffect } from 'ahooks'
|
||||
import { appDefaultIconBackground } from '@/config'
|
||||
import { searchEmoji } from '@/utils/emoji'
|
||||
import type { AppIconType } from '@/types/app'
|
||||
|
||||
type UseAppFaviconOptions = {
|
||||
enable?: boolean
|
||||
@@ -31,11 +31,11 @@ export function useAppFavicon(options: UseAppFaviconOptions) {
|
||||
link.href = isValidImageIcon
|
||||
? icon_url
|
||||
: 'data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22>'
|
||||
+ `<rect width=%22100%25%22 height=%22100%25%22 fill=%22${encodeURIComponent(icon_background || appDefaultIconBackground)}%22 rx=%2230%22 ry=%2230%22 />`
|
||||
+ `<text x=%2212.5%22 y=%221em%22 font-size=%2275%22>${
|
||||
icon ? await searchEmoji(icon) : '🤖'
|
||||
}</text>`
|
||||
+ '</svg>'
|
||||
+ `<rect width=%22100%25%22 height=%22100%25%22 fill=%22${encodeURIComponent(icon_background || appDefaultIconBackground)}%22 rx=%2230%22 ry=%2230%22 />`
|
||||
+ `<text x=%2212.5%22 y=%221em%22 font-size=%2275%22>${
|
||||
icon ? await searchEmoji(icon) : '🤖'
|
||||
}</text>`
|
||||
+ '</svg>'
|
||||
|
||||
link.rel = 'shortcut icon'
|
||||
link.type = 'image/svg'
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { act, renderHook } from '@testing-library/react'
|
||||
import { useGlobalPublicStore } from '@/context/global-public-context'
|
||||
/**
|
||||
* Test suite for useDocumentTitle hook
|
||||
*
|
||||
@@ -11,9 +13,7 @@
|
||||
* If no page title: "[Brand Name]"
|
||||
*/
|
||||
import { defaultSystemFeatures } from '@/types/feature'
|
||||
import { act, renderHook } from '@testing-library/react'
|
||||
import useDocumentTitle from './use-document-title'
|
||||
import { useGlobalPublicStore } from '@/context/global-public-context'
|
||||
|
||||
vi.mock('@/service/common', () => ({
|
||||
getSystemFeatures: vi.fn(() => ({ ...defaultSystemFeatures })),
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
'use client'
|
||||
import { useGlobalPublicStore } from '@/context/global-public-context'
|
||||
import { useFavicon, useTitle } from 'ahooks'
|
||||
import { basePath } from '@/utils/var'
|
||||
import { useEffect } from 'react'
|
||||
import { useGlobalPublicStore } from '@/context/global-public-context'
|
||||
import { basePath } from '@/utils/var'
|
||||
|
||||
export default function useDocumentTitle(title: string) {
|
||||
const isPending = useGlobalPublicStore(s => s.isGlobalPending)
|
||||
|
||||
@@ -13,6 +13,9 @@ import type { Mock } from 'vitest'
|
||||
* - Returns human-readable relative time strings
|
||||
*/
|
||||
import { renderHook } from '@testing-library/react'
|
||||
// Import after mock to get the mocked version
|
||||
import { useI18N } from '@/context/i18n'
|
||||
|
||||
import { useFormatTimeFromNow } from './use-format-time-from-now'
|
||||
|
||||
// Mock the i18n context
|
||||
@@ -22,9 +25,6 @@ vi.mock('@/context/i18n', () => ({
|
||||
})),
|
||||
}))
|
||||
|
||||
// Import after mock to get the mocked version
|
||||
import { useI18N } from '@/context/i18n'
|
||||
|
||||
describe('useFormatTimeFromNow', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
@@ -315,10 +315,27 @@ describe('useFormatTimeFromNow', () => {
|
||||
*/
|
||||
it('should handle all mapped locales', () => {
|
||||
const locales = [
|
||||
'en-US', 'zh-Hans', 'zh-Hant', 'pt-BR', 'es-ES', 'fr-FR',
|
||||
'de-DE', 'ja-JP', 'ko-KR', 'ru-RU', 'it-IT', 'th-TH',
|
||||
'id-ID', 'uk-UA', 'vi-VN', 'ro-RO', 'pl-PL', 'hi-IN',
|
||||
'tr-TR', 'fa-IR', 'sl-SI',
|
||||
'en-US',
|
||||
'zh-Hans',
|
||||
'zh-Hant',
|
||||
'pt-BR',
|
||||
'es-ES',
|
||||
'fr-FR',
|
||||
'de-DE',
|
||||
'ja-JP',
|
||||
'ko-KR',
|
||||
'ru-RU',
|
||||
'it-IT',
|
||||
'th-TH',
|
||||
'id-ID',
|
||||
'uk-UA',
|
||||
'vi-VN',
|
||||
'ro-RO',
|
||||
'pl-PL',
|
||||
'hi-IN',
|
||||
'tr-TR',
|
||||
'fa-IR',
|
||||
'sl-SI',
|
||||
]
|
||||
|
||||
const now = Date.now()
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import type { Locale } from '@/i18n-config'
|
||||
import dayjs from 'dayjs'
|
||||
import relativeTime from 'dayjs/plugin/relativeTime'
|
||||
import { useCallback } from 'react'
|
||||
import { useI18N } from '@/context/i18n'
|
||||
import type { Locale } from '@/i18n-config'
|
||||
import 'dayjs/locale/de'
|
||||
import 'dayjs/locale/es'
|
||||
import 'dayjs/locale/fa'
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
import type {
|
||||
DSLImportMode,
|
||||
DSLImportResponse,
|
||||
} from '@/models/app'
|
||||
import type { AppIconType } from '@/types/app'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import {
|
||||
useCallback,
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import type {
|
||||
DSLImportMode,
|
||||
DSLImportResponse,
|
||||
} from '@/models/app'
|
||||
import { useToastContext } from '@/app/components/base/toast'
|
||||
import { usePluginDependencies } from '@/app/components/workflow/plugin-dependency/hooks'
|
||||
import { NEED_REFRESH_APP_LIST_KEY } from '@/config'
|
||||
import { useSelector } from '@/context/app-context'
|
||||
import { DSLImportStatus } from '@/models/app'
|
||||
import {
|
||||
importDSL,
|
||||
importDSLConfirm,
|
||||
} from '@/service/apps'
|
||||
import type { AppIconType } from '@/types/app'
|
||||
import { useToastContext } from '@/app/components/base/toast'
|
||||
import { usePluginDependencies } from '@/app/components/workflow/plugin-dependency/hooks'
|
||||
import { getRedirection } from '@/utils/app-redirection'
|
||||
import { useSelector } from '@/context/app-context'
|
||||
import { NEED_REFRESH_APP_LIST_KEY } from '@/config'
|
||||
|
||||
type DSLPayload = {
|
||||
mode: DSLImportMode
|
||||
@@ -43,7 +43,7 @@ export const useImportDSL = () => {
|
||||
const { handleCheckPluginDependencies } = usePluginDependencies()
|
||||
const isCurrentWorkspaceEditor = useSelector(s => s.isCurrentWorkspaceEditor)
|
||||
const { push } = useRouter()
|
||||
const [versions, setVersions] = useState<{ importedVersion: string; systemVersion: string }>()
|
||||
const [versions, setVersions] = useState<{ importedVersion: string, systemVersion: string }>()
|
||||
const importIdRef = useRef<string>('')
|
||||
|
||||
const handleImportDSL = useCallback(async (
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
'use client'
|
||||
import type { DocType } from '@/models/datasets'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { formatFileSize, formatNumber, formatTime } from '@/utils/format'
|
||||
import { ChunkingMode, type DocType } from '@/models/datasets'
|
||||
import useTimestamp from '@/hooks/use-timestamp'
|
||||
import { ChunkingMode } from '@/models/datasets'
|
||||
import { formatFileSize, formatNumber, formatTime } from '@/utils/format'
|
||||
|
||||
export type inputType = 'input' | 'select' | 'textarea'
|
||||
export type metadataType = DocType | 'originInfo' | 'technicalParameters'
|
||||
|
||||
@@ -12,10 +12,10 @@ export type _Events = Record<EventType, unknown>
|
||||
|
||||
export type UseSubscribeOption = {
|
||||
/**
|
||||
* Whether the subscription is enabled.
|
||||
* @default true
|
||||
*/
|
||||
enabled: boolean;
|
||||
* Whether the subscription is enabled.
|
||||
* @default true
|
||||
*/
|
||||
enabled: boolean
|
||||
}
|
||||
|
||||
export type ExtendedOn<Events extends _Events> = {
|
||||
@@ -23,17 +23,17 @@ export type ExtendedOn<Events extends _Events> = {
|
||||
type: Key,
|
||||
handler: Handler<Events[Key]>,
|
||||
options?: UseSubscribeOption,
|
||||
): void;
|
||||
): void
|
||||
(
|
||||
type: '*',
|
||||
handler: WildcardHandler<Events>,
|
||||
option?: UseSubscribeOption,
|
||||
): void;
|
||||
): void
|
||||
}
|
||||
|
||||
export type UseMittReturn<Events extends _Events> = {
|
||||
useSubscribe: ExtendedOn<Events>;
|
||||
emit: Emitter<Events>['emit'];
|
||||
useSubscribe: ExtendedOn<Events>
|
||||
emit: Emitter<Events>['emit']
|
||||
}
|
||||
|
||||
const defaultSubscribeOption: UseSubscribeOption = {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import type { ModerationService } from '@/models/common'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
|
||||
function splitStringByLength(inputString: string, chunkLength: number) {
|
||||
const resultArray = []
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
'use client'
|
||||
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import { useRouter, useSearchParams } from 'next/navigation'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import type { IConfirm } from '@/app/components/base/confirm'
|
||||
import { useRouter, useSearchParams } from 'next/navigation'
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import Confirm from '@/app/components/base/confirm'
|
||||
import { useNotionBinding } from '@/service/use-common'
|
||||
|
||||
@@ -102,7 +102,7 @@ export const CheckModal = () => {
|
||||
onCancel={handleCancelShowPayStatusModal}
|
||||
onConfirm={handleCancelShowPayStatusModal}
|
||||
showCancel={false}
|
||||
type={confirmInfo.type === 'info' ? 'info' : 'warning' }
|
||||
type={confirmInfo.type === 'info' ? 'info' : 'warning'}
|
||||
title={confirmInfo.title}
|
||||
content={(confirmInfo as unknown as { desc: string }).desc || ''}
|
||||
confirmText={(confirmInfo.type === 'info' && t('common.operation.ok')) || ''}
|
||||
|
||||
@@ -12,6 +12,9 @@ import type { Mock } from 'vitest'
|
||||
* navigation persistent and shareable across sessions.
|
||||
*/
|
||||
import { act, renderHook } from '@testing-library/react'
|
||||
// Import after mocks
|
||||
import { usePathname } from 'next/navigation'
|
||||
|
||||
import { useTabSearchParams } from './use-tab-searchparams'
|
||||
|
||||
// Mock Next.js navigation hooks
|
||||
@@ -29,9 +32,6 @@ vi.mock('next/navigation', () => ({
|
||||
useSearchParams: vi.fn(() => mockSearchParams),
|
||||
}))
|
||||
|
||||
// Import after mocks
|
||||
import { usePathname } from 'next/navigation'
|
||||
|
||||
describe('useTabSearchParams', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Theme } from '@/types/app'
|
||||
import { useTheme as useBaseTheme } from 'next-themes'
|
||||
import { Theme } from '@/types/app'
|
||||
|
||||
const useTheme = () => {
|
||||
const { theme, resolvedTheme, ...rest } = useBaseTheme()
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
'use client'
|
||||
import { useCallback } from 'react'
|
||||
import dayjs from 'dayjs'
|
||||
import utc from 'dayjs/plugin/utc'
|
||||
import timezone from 'dayjs/plugin/timezone'
|
||||
import utc from 'dayjs/plugin/utc'
|
||||
import { useCallback } from 'react'
|
||||
import { useAppContext } from '@/context/app-context'
|
||||
|
||||
dayjs.extend(utc)
|
||||
|
||||
Reference in New Issue
Block a user