Skip to content

Commit

Permalink
fix: lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kwaa committed Jan 22, 2025
1 parent ebc5227 commit 796154b
Show file tree
Hide file tree
Showing 28 changed files with 67 additions and 76 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ import { generateText } from '@xsai/generate-text'
import { createOpenAI } from '@xsai/providers'
import { env } from 'node:process'

const openai = createOpenAI({
apiKey: env.OPENAI_API_KEY
})
const openai = createOpenAI({ apiKey: env.OPENAI_API_KEY! })

const { text } = await generateText({
...openai.chat('gpt-4o'),
Expand Down
8 changes: 4 additions & 4 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: "0.2"
version: '0.2'
ignorePaths: []
dictionaryDefinitions: []
dictionaries: []
Expand All @@ -14,21 +14,21 @@ words:
- importantimport
- koemotion
- masknet
- Moeru
- moeru
- moeru-ai
- mxbai-embed-large
- nemo
- nemotron
- nomic-embed-text
- Ollama
- ollama
- pkgroll
- qwen
- sonarjs
- twoslash
- typeschema
- unspeech
- valibot
- Vitest
- vitest
- xsai
ignoreWords: []
import: []
36 changes: 18 additions & 18 deletions docs/app/docs/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ import {
} from 'fumadocs-ui/page'
import { notFound } from 'next/navigation'

export const generateStaticParams = async () =>
source.generateParams()

export const generateMetadata = async (props: {
params: Promise<{ slug?: string[] }>
}) => {
const params = await props.params
const page = source.getPage(params.slug)
if (!page)
notFound()

return metadataImage.withImage(page.slugs, {
description: page.data.description,
metadataBase: new URL('https://xsai.js.org'),
title: page.data.title,
})
}

export default async (props: {
params: Promise<{ slug?: string[] }>
}) => {
Expand Down Expand Up @@ -54,21 +72,3 @@ export default async (props: {
</DocsPage>
)
}

export const generateStaticParams = async () =>
source.generateParams()

export const generateMetadata = async (props: {
params: Promise<{ slug?: string[] }>
}) => {
const params = await props.params
const page = source.getPage(params.slug)
if (!page)
notFound()

return metadataImage.withImage(page.slugs, {
description: page.data.description,
metadataBase: new URL('https://xsai.js.org'),
title: page.data.title,
})
}
1 change: 1 addition & 0 deletions docs/components/shadcn/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const Button = forwardRef<HTMLButtonElement, ButtonProps>(
)
},
)
// eslint-disable-next-line @masknet/no-top-level
Button.displayName = 'Button'

export { Button, buttonVariants }
9 changes: 7 additions & 2 deletions docs/components/ui/background-lines.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line @masknet/no-top-level
'use client'
import { cn } from '@/lib/utils'
import { motion } from 'framer-motion'
Expand Down Expand Up @@ -86,10 +87,12 @@ const SVG = ({
strokeLinecap="round"
strokeWidth="2.3"
transition={{
// eslint-disable-next-line sonarjs/pseudo-random
delay: Math.floor(Math.random() * 10),
duration: svgOptions?.duration || 10,
duration: svgOptions?.duration ?? 10,
ease: 'linear',
repeat: Infinity,
// eslint-disable-next-line sonarjs/pseudo-random
repeatDelay: Math.floor(Math.random() * 10 + 2),
repeatType: 'loop',
}}
Expand All @@ -108,10 +111,12 @@ const SVG = ({
strokeLinecap="round"
strokeWidth="2.3"
transition={{
// eslint-disable-next-line sonarjs/pseudo-random
delay: Math.floor(Math.random() * 10),
duration: svgOptions?.duration || 10,
duration: svgOptions?.duration ?? 10,
ease: 'linear',
repeat: Infinity,
// eslint-disable-next-line sonarjs/pseudo-random
repeatDelay: Math.floor(Math.random() * 10 + 2),
repeatType: 'loop',
}}
Expand Down
3 changes: 3 additions & 0 deletions docs/components/ui/hover-border-gradient.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// eslint-disable-next-line @masknet/no-top-level
'use client'
import { cn } from '@/lib/utils'
import { motion } from 'framer-motion'
Expand Down Expand Up @@ -49,9 +50,11 @@ export function HoverBorderGradient({
useEffect(() => {
if (hovered)
return
// eslint-disable-next-line @masknet/no-timer
const interval = setInterval(() => {
setDirection(prevState => rotateDirection(prevState))
}, duration * 1000)
// eslint-disable-next-line @masknet/no-timer
return () => clearInterval(interval)
}, [hovered])
return (
Expand Down
2 changes: 1 addition & 1 deletion docs/components/ui/spotlight.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const Spotlight = ({ className, fill }: SpotlightProps) => (
<ellipse
cx="1924.71"
cy="273.501"
fill={fill || 'white'}
fill={fill ?? 'white'}
fillOpacity="0.21"
rx="1924.71"
ry="273.501"
Expand Down
1 change: 1 addition & 0 deletions docs/generate-files.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { generateFiles } from 'fumadocs-typescript'
import * as path from 'node:path'

// eslint-disable-next-line @masknet/no-top-level
void generateFiles({
input: ['./content/docs/**/*.model.mdx'],
// Rename x.model.mdx to x.mdx
Expand Down
3 changes: 3 additions & 0 deletions docs/tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import animate from 'tailwindcss-animate'
import flattenColorPalette from 'tailwindcss/lib/util/flattenColorPalette'

function addVariablesForColors({ addBase, theme }: any) {
// eslint-disable-next-line ts/no-unsafe-assignment, ts/no-unsafe-call
const allColors = flattenColorPalette(theme('colors'))
const newVars = Object.fromEntries(
// eslint-disable-next-line ts/no-unsafe-argument
Object.entries(allColors)
.map(([key, val]) => [`--${key}`, val]),
)

// eslint-disable-next-line ts/no-unsafe-call
addBase({
':root': newVars,
})
Expand Down
28 changes: 24 additions & 4 deletions eslint.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
import { defineConfig } from '@importantimport/eslint-config'
// import { defineConfig } from '@importantimport/eslint-config'

export default defineConfig({
typescript: { tsconfigPath: './tsconfig.json' },
})
// export default defineConfig({
// typescript: { tsconfigPath: './tsconfig.json' },
// })

import antfu, { GLOB_MARKDOWN_CODE, GLOB_TESTS } from '@antfu/eslint-config'
import { ii } from '@importantimport/eslint-config'

export default antfu({ typescript: { tsconfigPath: './tsconfig.json' } })
.append(ii({ typescript: { tsconfigPath: './tsconfig.json' } }))
.append({
rules: {
'@masknet/no-default-error': 'off',
'@masknet/no-then': 'off',
'sonarjs/todo-tag': 'warn',
},
})
.append({
files: [...GLOB_TESTS, GLOB_MARKDOWN_CODE],
rules: {
'@masknet/no-top-level': 'off',
'@masknet/unicode-specific-set': 'off',
},
})
1 change: 1 addition & 0 deletions packages/embed/src/utils/embed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface EmbedResponse {
object: 'embedding'
}[]
model: string
// eslint-disable-next-line sonarjs/no-useless-intersection
object: 'list' | (string & {})
system_fingerprint?: string
usage: EmbedResponseUsage
Expand Down
2 changes: 1 addition & 1 deletion packages/embed/test/embed-many.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { embedMany } from '../src'
describe('@xsai/embed', () => {
it('array', async () => {
const { embeddings, usage } = await embedMany({
...ollama.embeddings('nomic-embed-text'),
...ollama.embed('nomic-embed-text'),
input: ['why is the sky blue?', 'why is the grass green?'],
})

Expand Down
2 changes: 1 addition & 1 deletion packages/embed/test/embed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { embed } from '../src'
describe('@xsai/embed', () => {
it('embed', async () => {
const { embedding, usage } = await embed({
...ollama.embeddings('nomic-embed-text'),
...ollama.embed('nomic-embed-text'),
input: 'sunny day at the beach',
})

Expand Down
1 change: 0 additions & 1 deletion packages/generate-object/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export interface GenerateObjectResult<T extends Schema> extends Omit<GenerateTex

/** @experimental WIP */
export const generateObject = async <T extends Schema>(options: GenerateObjectOptions<T>): Promise<GenerateObjectResult<T>> =>
// eslint-disable-next-line @masknet/no-then
generateText({
...options,
response_format: {
Expand Down
1 change: 0 additions & 1 deletion packages/generate-object/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { describe, expect, it } from 'vitest'

import { generateObject } from '../src'

// eslint-disable-next-line @masknet/no-top-level
describe('@xsai/generate-object', () => {
it('basic', async () => {
const { object } = await generateObject({
Expand Down
2 changes: 0 additions & 2 deletions packages/generate-speech/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { describe, expect, it } from 'vitest'

import { generateSpeech } from '../src'

// eslint-disable-next-line @masknet/no-top-level
describe('@xsai/generate-speech', () => {
it('basic', async () => {
const speech = await generateSpeech({
Expand All @@ -18,7 +17,6 @@ describe('@xsai/generate-speech', () => {
it('chinese', async () => {
const speech = await generateSpeech({
baseURL: new URL('http://localhost:5050'),
// eslint-disable-next-line @masknet/unicode-specific-set
input: '我能吞下玻璃而不伤身体。',
model: 'tts-1',
voice: 'zh-CN-XiaoyiNeural',
Expand Down
1 change: 0 additions & 1 deletion packages/generate-text/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ type RawGenerateTextTrampoline<T> = Promise<(() => RawGenerateTextTrampoline<T>)

/** @internal */
const rawGenerateText: RawGenerateText = async (options: GenerateTextOptions) =>
// eslint-disable-next-line @masknet/no-then
chat({
...options,
maxSteps: undefined,
Expand Down
1 change: 0 additions & 1 deletion packages/generate-transcription/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const generateTranscription = async (options: GenerateTranscriptionOption
body.append('model', options.model)
body.append('file', options.file, options.fileName)

// eslint-disable-next-line @masknet/no-then
return (options.fetch ?? globalThis.fetch)(requestURL('audio/transcriptions', options.baseURL), {
body,
headers: requestHeaders(options.headers, options.apiKey),
Expand Down
1 change: 0 additions & 1 deletion packages/generate-transcription/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { describe, expect, it } from 'vitest'

import { generateTranscription } from '../src'

// eslint-disable-next-line @masknet/no-top-level
describe('@xsai/generate-transcription', () => {
it('basic', async () => {
const { text } = await generateTranscription({
Expand Down
1 change: 0 additions & 1 deletion packages/model/src/utils/list-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export interface ListModelsResponse {
}

export const listModels = async (options: ListModelsOptions): Promise<Model[]> =>
// eslint-disable-next-line @masknet/no-then
(options.fetch ?? globalThis.fetch)(requestURL('models', options.baseURL), {
headers: requestHeaders({
'Content-Type': 'application/json',
Expand Down
1 change: 0 additions & 1 deletion packages/model/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { describe, expect, it } from 'vitest'

import { listModels, retrieveModel } from '../src'

// eslint-disable-next-line @masknet/no-top-level
describe('@xsai/model', () => {
it('listModels', async () => {
const models = await listModels({
Expand Down
1 change: 1 addition & 0 deletions packages/shared-chat/src/types/finish-reason.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// eslint-disable-next-line sonarjs/no-useless-intersection
export type FinishReason = 'content_filter' | 'error' | 'length' | 'other' | 'stop' | 'tool-calls' | (string & {})
1 change: 0 additions & 1 deletion packages/shared/src/utils/response-json.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { responseCatch } from './response-catch'

export const responseJSON = async <T>(res: Response) =>
// eslint-disable-next-line @masknet/no-then
responseCatch(res)
.then(async res => res.json() as Promise<T>)
1 change: 0 additions & 1 deletion packages/stream-object/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export interface StreamObjectResult<T extends Schema> extends StreamTextResult {

/** @experimental WIP */
export const streamObject = async <T extends Schema>(options: StreamObjectOptions<T>): Promise<StreamObjectResult<T>> =>
// eslint-disable-next-line @masknet/no-then
streamText({
...options,
response_format: {
Expand Down
1 change: 0 additions & 1 deletion packages/stream-object/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ declare global {
}
}

// eslint-disable-next-line @masknet/no-top-level
describe('@xsai/stream-object', () => {
it('basic', async () => {
const { partialObjectStream } = await streamObject({
Expand Down
1 change: 0 additions & 1 deletion packages/stream-text/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const chunkHeaderPrefix = 'data:'
/**
* @experimental WIP, does not support function calling (tools).
*/
// eslint-disable-next-line @masknet/no-then
export const streamText = async (options: StreamTextOptions): Promise<StreamTextResult> => chat({
...options,
stream: true,
Expand Down
1 change: 0 additions & 1 deletion packages/stream-text/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ declare global {
}
}

// eslint-disable-next-line @masknet/no-top-level
describe('@xsai/stream-text', () => {
it('basic', async () => {
const { textStream } = await streamText({
Expand Down
28 changes: 0 additions & 28 deletions packages/tool/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,6 @@ import { describe, expect, it } from 'vitest'
import { tool } from '../src'

describe('@xsai/tool', () => {
it('basic', async () => {
const t = await tool({
description: 'Get the weather in a location',
execute: ({ location }) => JSON.stringify({
location,
temperature: 72 + Math.floor(Math.random() * 21) - 10,
}),
name: 'weather',
parameters: object({
location: pipe(
string(),
description('The location to get the weather for'),
),
}),
})

expect(t.function.parameters).toStrictEqual({
properties: {
location: {
description: 'The location to get the weather for',
type: 'string',
},
},
required: ['location'],
type: 'object',
})
})

it('generateText with tool', async () => {
const weather = await tool({
description: 'Get the weather in a location',
Expand Down

0 comments on commit 796154b

Please sign in to comment.