chore: upgrade to eslint9 (#9163)

This commit is contained in:
Brooooooklyn
2024-12-14 10:29:04 +00:00
parent f49bef4915
commit aaaea8918f
37 changed files with 681 additions and 736 deletions

View File

@@ -253,7 +253,7 @@ export class FalProvider
metrics.ai.counter('chat_text_stream_calls').add(1, { model });
const result = await this.generateText(messages, model, options);
for await (const content of result) {
for (const content of result) {
if (content) {
yield content;
if (options.signal?.aborted) {

View File

@@ -178,6 +178,7 @@ export class OIDCProvider
super();
}
// eslint-disable-next-line @typescript-eslint/no-misused-promises
override async onModuleInit() {
const config = this.optionalConfig as OAuthOIDCProviderConfig;
if (config && config.issuer && config.clientId && config.clientSecret) {

View File

@@ -100,7 +100,7 @@ export class MockCopilotTestProvider
// make some time gap for history test case
await sleep(100);
const result = 'generate text to text stream';
for await (const message of result) {
for (const message of result) {
yield message;
if (options.signal?.aborted) {
break;

View File

@@ -1,7 +1,6 @@
import { CONSTRUCTOR_CONTEXT } from '../constructor-context';
import type { FrameworkProvider } from '../provider';
// eslint-disable-next-line @typescript-eslint/ban-types
export class Component<Props = {}> {
readonly framework: FrameworkProvider;

View File

@@ -1,6 +1,5 @@
import { Component } from './component';
// eslint-disable-next-line @typescript-eslint/ban-types
export class Entity<Props = {}> extends Component<Props> {
readonly __isEntity = true;
}

View File

@@ -1,6 +1,5 @@
import { Component } from './component';
// eslint-disable-next-line @typescript-eslint/ban-types
export class Scope<Props = {}> extends Component<Props> {
readonly __injectable = true;

View File

@@ -1,6 +1,5 @@
import type { FrameworkProvider } from './provider';
// eslint-disable-next-line @typescript-eslint/ban-types
export type Type<T = any> = abstract new (...args: any) => T;
export type ComponentFactory<T = any> = (provider: FrameworkProvider) => T;

View File

@@ -18,6 +18,7 @@ export function useFramework(): FrameworkProvider {
export function useService<T extends Service>(
identifier: GeneralIdentifier<T>
): T {
// eslint-disable-next-line react-hooks/rules-of-hooks
const stack = useContext(FrameworkStackContext);
let service: T | undefined = undefined;
@@ -85,6 +86,7 @@ export function useServices<
export function useServiceOptional<T extends Service>(
identifier: Type<T>
): T | undefined {
// eslint-disable-next-line react-hooks/rules-of-hooks
const stack = useContext(FrameworkStackContext);
let service: T | undefined = undefined;

View File

@@ -57,7 +57,6 @@ export class WorkspaceDBService extends Service {
) as WorkspaceDBWithTables<AFFiNEWorkspaceDbSchema>;
}
// eslint-disable-next-line @typescript-eslint/ban-types
userdataDB(userId: (string & {}) | '__local__') {
// __local__ for local workspace
const userdataDb = this.userdataDBPool.get(userId);

View File

@@ -28,8 +28,8 @@ export class SpaceStorageClient extends OpClient<SpaceStorageOps> {
await this.call('disconnect');
}
override async destroy() {
await this.call('destroy');
override destroy() {
this.call('destroy').catch(console.error);
super.destroy();
}
@@ -46,8 +46,8 @@ export class SpaceStorageWorkerClient extends SpaceStorageClient {
this.worker = worker;
}
override async destroy() {
await super.destroy();
override destroy() {
super.destroy();
this.worker.terminate();
}
}

View File

@@ -1,9 +1,9 @@
import EventEmitter2 from 'eventemitter2';
import type { ConnectionStatus } from '../connection';
import { type Storage, type StorageType } from './storage';
import type { BlobStorage } from './blob';
import type { DocStorage } from './doc';
import { type Storage, type StorageType } from './storage';
import type { SyncStorage } from './sync';
type Storages = DocStorage | BlobStorage | SyncStorage;

View File

@@ -1,7 +1,7 @@
import { type PasswordLimitsFragment } from '@affine/graphql';
import { useI18n } from '@affine/i18n';
import { type Options, passwordStrength } from 'check-password-strength';
import { type FC, useEffect, useMemo, useCallback, useState } from 'react';
import { type FC, useCallback, useEffect, useMemo, useState } from 'react';
import { z, type ZodCustomIssue, ZodIssueCode } from 'zod';
import type { InputProps } from '../../../ui/input';

View File

@@ -8,7 +8,6 @@ import type React from 'react';
const DEV_MODE = process.env.NODE_ENV !== 'production';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type DistributiveOmit<T, K extends string | number | symbol> = T extends any
? K extends keyof T
? Omit<T, K>
@@ -38,7 +37,6 @@ export type WebComponentProps<I extends HTMLElement> = React.DetailedHTMLProps<
> &
ElementProps<I>;
// eslint-disable-next-line @typescript-eslint/ban-types
type EmptyObject = {};
/**

View File

@@ -51,6 +51,5 @@ export type toExternalData<D extends DNDData> = (
| 'text/plain'
| 'text/html'
| 'Files'
// eslint-disable-next-line @typescript-eslint/ban-types
| (string & {})]?: string;
};

View File

@@ -3,8 +3,8 @@ import './ask-ai-panel';
import { type EditorHost } from '@blocksuite/affine/block-std';
import {
type AIItemGroupConfig,
EdgelessRootService,
createLitPortal,
EdgelessRootService,
HoverController,
} from '@blocksuite/affine/blocks';
import { WithDisposable } from '@blocksuite/affine/global/utils';

View File

@@ -7,6 +7,7 @@ import {
} from '@blocksuite/affine/blocks';
import { WithDisposable } from '@blocksuite/affine/global/utils';
import type { BlockModel } from '@blocksuite/affine/store';
import { captureException } from '@sentry/react';
import {
css,
html,
@@ -466,39 +467,47 @@ export class ChatCards extends WithDisposable(LitElement) {
}
}
protected override async willUpdate(changedProperties: PropertyValues) {
if (changedProperties.has('temporaryParams') && this.temporaryParams) {
const params = this.temporaryParams;
await this._appendCardWithParams(params);
this.temporaryParams = null;
}
if (changedProperties.has('host')) {
if (this._currentDocId === this.host.doc.id) return;
this._currentDocId = this.host.doc.id;
this.cards = [];
const { text, images } = await this._extractAll();
const hasText = text.length > 0;
const hasImages = images.length > 0;
// Currently only supports checking on first load
if (hasText || hasImages) {
const card: CardBlock = {
id: Date.now(),
type: CardType.Doc,
};
if (hasText) {
card.text = text;
}
if (hasImages) {
card.images = images;
protected override willUpdate(changedProperties: PropertyValues) {
Promise.resolve()
.then(async () => {
if (changedProperties.has('temporaryParams') && this.temporaryParams) {
const params = this.temporaryParams;
await this._appendCardWithParams(params);
this.temporaryParams = null;
}
this.cards.push(card);
this.requestUpdate();
}
}
if (changedProperties.has('host')) {
if (this._currentDocId === this.host.doc.id) return;
this._currentDocId = this.host.doc.id;
this.cards = [];
const { text, images } = await this._extractAll();
const hasText = text.length > 0;
const hasImages = images.length > 0;
// Currently only supports checking on first load
if (hasText || hasImages) {
const card: CardBlock = {
id: Date.now(),
type: CardType.Doc,
};
if (hasText) {
card.text = text;
}
if (hasImages) {
card.images = images;
}
this.cards.push(card);
this.requestUpdate();
}
}
})
.catch(err => {
captureException(err, {
level: 'fatal',
});
});
}
override connectedCallback() {

View File

@@ -276,11 +276,14 @@ export class ChatPanelMessages extends WithDisposable(ShadowlessElement) {
: nothing} `;
}
override async connectedCallback() {
override connectedCallback() {
super.connectedCallback();
const res = await AIProvider.userInfo;
this.avatarUrl = res?.avatarUrl ?? '';
Promise.resolve(AIProvider.userInfo)
.then(res => {
this.avatarUrl = res?.avatarUrl ?? '';
})
.catch(console.error);
this.disposables.add(
AIProvider.slots.userInfo.on(userInfo => {
const { status, error } = this.chatContextValue;

View File

@@ -1,14 +1,14 @@
import {
AFFINE_AI_PANEL_WIDGET,
type AffineAIPanelWidget,
type AffineSlashMenuActionItem,
type AffineSlashMenuContext,
type AffineSlashMenuItem,
AffineSlashMenuWidget,
type AffineSlashSubMenu,
type AIItemConfig,
DocModeProvider,
AFFINE_AI_PANEL_WIDGET,
AffineSlashMenuWidget,
AIStarIcon,
DocModeProvider,
MoreHorizontalIcon,
} from '@blocksuite/affine/blocks';
import { assertExists } from '@blocksuite/affine/global/utils';

View File

@@ -5,8 +5,8 @@ import {
ConnectorMode,
DocModeProvider,
type EdgelessRootService,
TelemetryProvider,
NotificationProvider,
TelemetryProvider,
} from '@blocksuite/affine/blocks';
import {
type AIChatBlockModel,

View File

@@ -1,11 +1,11 @@
import type { EditorHost } from '@blocksuite/affine/block-std';
import {
BlocksUtils,
type CopilotTool,
EdgelessRootService,
type FrameBlockModel,
ImageBlockModel,
type SurfaceBlockComponent,
BlocksUtils,
EdgelessRootService,
} from '@blocksuite/affine/blocks';
import { assertExists } from '@blocksuite/affine/global/utils';
import {

View File

@@ -10,8 +10,8 @@ import {
import { GlobalDialogService } from '@affine/core/modules/dialogs';
import {
type CreateCheckoutSessionInput,
SubscriptionRecurring,
SubscriptionPlan,
SubscriptionRecurring,
SubscriptionStatus,
SubscriptionVariant,
} from '@affine/graphql';

View File

@@ -107,10 +107,10 @@ export const CloudWorkspaceMembersPanel = ({
return success;
}, [permissionService.permission, workspaceShareSettingService.sharePreview]);
const onInviteBatchConfirm = useCallback<
InviteTeamMemberModalProps['onConfirm']
>(
async ({ emails }) => {
const onInviteBatchConfirm = useAsyncCallback(
async ({
emails,
}: Parameters<InviteTeamMemberModalProps['onConfirm']>[0]) => {
setIsMutating(true);
const success = await permissionService.permission.inviteMembers(
emails,

View File

@@ -360,7 +360,6 @@ const ExplorerFolderNodeFolder = ({
}, [additionalOperations, folderOperations]);
const childrenOperations = useCallback(
// eslint-disable-next-line @typescript-eslint/ban-types
(type: string, node: FolderNode) => {
if (type === 'doc' || type === 'collection' || type === 'tag') {
return [

View File

@@ -1,8 +1,8 @@
import {
SubscriptionPlan,
type SubscriptionQuery,
SubscriptionRecurring,
SubscriptionVariant,
SubscriptionPlan,
} from '@affine/graphql';
import {
backoffRetry,

View File

@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/ban-types */
import type { DocMode } from '@blocksuite/affine/blocks';
import type { WorkspaceMetadata } from '@toeverything/infra';

View File

@@ -712,7 +712,6 @@ const ExplorerFolderNodeFolder = ({
}, [additionalOperations, folderOperations]);
const childrenOperations = useCallback(
// eslint-disable-next-line @typescript-eslint/ban-types
(type: string, node: FolderNode) => {
if (type === 'doc' || type === 'collection' || type === 'tag') {
return [

View File

@@ -14,7 +14,6 @@ export class FolderNode extends Entity<{
info$ = LiveData.from<{
data: string;
// eslint-disable-next-line @typescript-eslint/ban-types
type: (string & {}) | 'folder' | 'doc' | 'tag' | 'collection';
index: string;
id: string;

View File

@@ -10,8 +10,10 @@ import {
type BlobStorage,
catchErrorInto,
type DocStorage,
effect,
exhaustMapSwitchUntilChanged,
fromPromise,
getAFFiNEWorkspaceSchema,
type GlobalState,
LiveData,
ObjectPool,
@@ -24,8 +26,6 @@ import {
type WorkspaceFlavoursProvider,
type WorkspaceMetadata,
type WorkspaceProfileInfo,
effect,
getAFFiNEWorkspaceSchema,
} from '@toeverything/infra';
import { isEqual } from 'lodash-es';
import { nanoid } from 'nanoid';

View File

@@ -176,7 +176,6 @@ function createKey() {
function warning(cond: any, message: string) {
if (!cond) {
// eslint-disable-next-line no-console
if (typeof console !== 'undefined') console.warn(message);
try {
@@ -186,7 +185,6 @@ function warning(cond: any, message: string) {
// find the source for a warning that appears in the console by
// enabling "pause on exceptions" in your JavaScript debugger.
throw new Error(message);
// eslint-disable-next-line no-empty
} catch {}
}
}
@@ -201,7 +199,7 @@ type Events<F> = {
call: (arg: any) => void;
};
// eslint-disable-next-line @typescript-eslint/ban-types
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
function createEvents<F extends Function>(): Events<F> {
let handlers: F[] = [];

View File

@@ -1,6 +1,6 @@
import dayjs from 'dayjs';
import { type I18nInstance, I18n } from '../i18next';
import { I18n, type I18nInstance } from '../i18next';
export type TimeUnit =
| 'second'

View File

@@ -294,8 +294,6 @@ const PageEvents = {
property: ['addProperty'],
},
},
// remove when type added
// eslint-disable-next-line @typescript-eslint/ban-types
edgeless: {},
workspace: {
$: {
@@ -316,18 +314,12 @@ const PageEvents = {
],
},
},
// remove when type added
// eslint-disable-next-line @typescript-eslint/ban-types
collection: {
docList: {
docMenu: ['removeOrganizeItem'],
},
},
// remove when type added
// eslint-disable-next-line @typescript-eslint/ban-types
tag: {},
// remove when type added
// eslint-disable-next-line @typescript-eslint/ban-types
trash: {},
subscriptionLanding: {
$: {