Fix all biome linter errors (#541)

This commit is contained in:
Jared Palmer 2024-11-15 12:18:17 -05:00 committed by GitHub
parent f23c73f6a5
commit e5d654bf41
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
46 changed files with 317 additions and 275 deletions

View file

@ -8,11 +8,11 @@ import postgres from 'postgres';
import {
user,
chat,
User,
type User,
document,
Suggestion,
type Suggestion,
suggestion,
Message,
type Message,
message,
vote,
} from './schema';
@ -20,8 +20,8 @@ import {
// Optionally, if not using email/pass login, you can
// use the Drizzle adapter for Auth.js / NextAuth
// https://authjs.dev/reference/adapter/drizzle
let client = postgres(`${process.env.POSTGRES_URL!}?sslmode=require`);
let db = drizzle(client);
const client = postgres(`${process.env.POSTGRES_URL!}?sslmode=require`);
const db = drizzle(client);
export async function getUser(email: string): Promise<Array<User>> {
try {
@ -33,8 +33,8 @@ export async function getUser(email: string): Promise<Array<User>> {
}
export async function createUser(email: string, password: string) {
let salt = genSaltSync(10);
let hash = hashSync(password, salt);
const salt = genSaltSync(10);
const hash = hashSync(password, salt);
try {
return await db.insert(user).values({ email, password: hash });
@ -141,15 +141,14 @@ export async function voteMessage({
if (existingVote) {
return await db
.update(vote)
.set({ isUpvoted: type === 'up' ? true : false })
.set({ isUpvoted: type === 'up' })
.where(and(eq(vote.messageId, messageId), eq(vote.chatId, chatId)));
} else {
return await db.insert(vote).values({
chatId,
messageId,
isUpvoted: type === 'up' ? true : false,
});
}
return await db.insert(vote).values({
chatId,
messageId,
isUpvoted: type === 'up',
});
} catch (error) {
console.error('Failed to upvote message in database', error);
throw error;

View file

@ -1,4 +1,4 @@
import { InferSelectModel } from 'drizzle-orm';
import type { InferSelectModel } from 'drizzle-orm';
import {
pgTable,
varchar,

View file

@ -2,9 +2,9 @@ import { textblockTypeInputRule } from 'prosemirror-inputrules';
import { Schema } from 'prosemirror-model';
import { schema } from 'prosemirror-schema-basic';
import { addListNodes } from 'prosemirror-schema-list';
import { Transaction } from 'prosemirror-state';
import { EditorView } from 'prosemirror-view';
import { MutableRefObject } from 'react';
import type { Transaction } from 'prosemirror-state';
import type { EditorView } from 'prosemirror-view';
import type { MutableRefObject } from 'react';
import { buildContentFromDocument } from './functions';

View file

@ -248,18 +248,16 @@ export const patchTextNodes = (schema, oldNode, newNode) => {
});
// Map diffs to nodes
const res = diffs
.map(([type, sentences]) => {
return sentences.map((sentence) => {
const node = createTextNode(
schema,
sentence,
type !== DiffType.Unchanged ? [createDiffMark(schema, type)] : []
);
return node;
});
})
.flat();
const res = diffs.flatMap(([type, sentences]) => {
return sentences.map((sentence) => {
const node = createTextNode(
schema,
sentence,
type !== DiffType.Unchanged ? [createDiffMark(schema, type)] : []
);
return node;
});
});
return res;
};
@ -278,28 +276,26 @@ const sentencesToChars = (oldSentences, newSentences) => {
const chars1 = oldSentences
.map((sentence) => {
const line = sentence;
if (lineHash.hasOwnProperty(line)) {
return String.fromCharCode(lineHash[line]);
} else {
lineHash[line] = lineStart;
lineArray[lineStart] = line;
lineStart++;
if (line in lineHash) {
return String.fromCharCode(lineHash[line]);
}
lineHash[line] = lineStart;
lineArray[lineStart] = line;
lineStart++;
return String.fromCharCode(lineHash[line]);
})
.join('');
const chars2 = newSentences
.map((sentence) => {
const line = sentence;
if (lineHash.hasOwnProperty(line)) {
return String.fromCharCode(lineHash[line]);
} else {
lineHash[line] = lineStart;
lineArray[lineStart] = line;
lineStart++;
if (line in lineHash) {
return String.fromCharCode(lineHash[line]);
}
lineHash[line] = lineStart;
lineArray[lineStart] = line;
lineStart++;
return String.fromCharCode(lineHash[line]);
})
.join('');

View file

@ -1,14 +1,14 @@
'use client';
import { defaultMarkdownSerializer } from 'prosemirror-markdown';
import { DOMParser, Node } from 'prosemirror-model';
import { Decoration, DecorationSet, EditorView } from 'prosemirror-view';
import { DOMParser, type Node } from 'prosemirror-model';
import { Decoration, DecorationSet, type EditorView } from 'prosemirror-view';
import { renderToString } from 'react-dom/server';
import { Markdown } from '@/components/markdown';
import { documentSchema } from './config';
import { createSuggestionWidget, UISuggestion } from './suggestions';
import { createSuggestionWidget, type UISuggestion } from './suggestions';
export const buildDocumentFromContent = (content: string) => {
const parser = DOMParser.fromSchema(documentSchema);
@ -28,7 +28,7 @@ export const createDecorations = (
) => {
const decorations: Array<Decoration> = [];
suggestions.forEach((suggestion) => {
for (const suggestion of suggestions) {
decorations.push(
Decoration.inline(
suggestion.selectionStart,
@ -56,7 +56,7 @@ export const createDecorations = (
}
)
);
});
}
return DecorationSet.create(view.state.doc, decorations);
};

View file

@ -1,10 +1,14 @@
import { Node } from 'prosemirror-model';
import { PluginKey, Plugin } from 'prosemirror-state';
import { Decoration, DecorationSet, EditorView } from 'prosemirror-view';
import type { Node } from 'prosemirror-model';
import { Plugin, PluginKey } from 'prosemirror-state';
import {
type Decoration,
DecorationSet,
type EditorView,
} from 'prosemirror-view';
import { createRoot } from 'react-dom/client';
import { Suggestion as PreviewSuggestion } from '@/components/suggestion';
import { Suggestion } from '@/lib/db/schema';
import type { Suggestion } from '@/lib/db/schema';
export interface UISuggestion extends Suggestion {
selectionStart: number;
@ -77,7 +81,7 @@ export function createSuggestionWidget(
const onApply = () => {
const { state, dispatch } = view;
let decorationTransaction = state.tr;
const decorationTransaction = state.tr;
const currentState = suggestionsPluginKey.getState(state);
const currentDecorations = currentState?.decorations;

View file

@ -1,14 +1,14 @@
import {
import type {
CoreAssistantMessage,
CoreMessage,
CoreToolMessage,
Message,
ToolInvocation,
} from 'ai';
import { clsx, type ClassValue } from 'clsx';
import { type ClassValue, clsx } from 'clsx';
import { twMerge } from 'tailwind-merge';
import { Message as DBMessage, Document } from '@/lib/db/schema';
import type { Message as DBMessage, Document } from '@/lib/db/schema';
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs));
@ -44,7 +44,7 @@ export function getLocalStorage(key: string) {
}
export function generateUUID(): string {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
const r = (Math.random() * 16) | 0;
const v = c === 'x' ? r : (r & 0x3) | 0x8;
return v.toString(16);
@ -96,7 +96,7 @@ export function convertToUIMessages(
}
let textContent = '';
let toolInvocations: Array<ToolInvocation> = [];
const toolInvocations: Array<ToolInvocation> = [];
if (typeof message.content === 'string') {
textContent = message.content;
@ -129,7 +129,7 @@ export function convertToUIMessages(
export function sanitizeResponseMessages(
messages: Array<CoreToolMessage | CoreAssistantMessage>
): Array<CoreToolMessage | CoreAssistantMessage> {
let toolResultIds: Array<string> = [];
const toolResultIds: Array<string> = [];
for (const message of messages) {
if (message.role === 'tool') {
@ -171,7 +171,7 @@ export function sanitizeUIMessages(messages: Array<Message>): Array<Message> {
if (!message.toolInvocations) return message;
let toolResultIds: Array<string> = [];
const toolResultIds: Array<string> = [];
for (const toolInvocation of message.toolInvocations) {
if (toolInvocation.state === 'result') {