There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
style: add ban-ts-comment rule (#2738)
LongYinan2e975e79dd31
diff --git a/.eslintignore b/.eslintignoreindex 42a9f2783a..64aa933543 100644--- a/.eslintignore+++ b/.eslintignore@@ -7,3 +7,4 @@ affine-out_nextlib.eslintrc.js+packages/i18n/src/i18n-generated.tsdiff --git a/.eslintrc.js b/.eslintrc.jsindex 02bc257217..5f8aac2b35 100644--- a/.eslintrc.js+++ b/.eslintrc.js@@ -103,7 +103,15 @@ const config = {'unused-imports/no-unused-imports': 'error','simple-import-sort/imports': 'error','simple-import-sort/exports': 'error',- '@typescript-eslint/ban-ts-comment': 0,+ '@typescript-eslint/ban-ts-comment': [+ 'error',+ {+ 'ts-expect-error': 'allow-with-description',+ 'ts-ignore': true,+ 'ts-nocheck': true,+ 'ts-check': false,+ },+ ],'@typescript-eslint/no-restricted-imports': ['error',{@@ -143,9 +151,26 @@ const config = {},},{- files: ['**/__tests__/**/*', '**/*.stories.tsx'],+ files: [+ '**/__tests__/**/*',+ '**/*.stories.tsx',+ '**/*.spec.ts',+ '**/tests/**/*',+ 'scripts/**/*',+ '**/benchmark/**/*',+ '**/__debug__/**/*',+ ],rules: {'@typescript-eslint/no-non-null-assertion': 0,+ '@typescript-eslint/ban-ts-comment': [+ 'error',+ {+ 'ts-expect-error': false,+ 'ts-ignore': true,+ 'ts-nocheck': true,+ 'ts-check': false,+ },+ ],},},...allPackages.map(pkg => ({diff --git a/apps/electron/layers/main/src/__tests__/integration.spec.ts b/apps/electron/layers/main/src/__tests__/integration.spec.tsindex 0c65464b5d..9ff3ecde53 100644--- a/apps/electron/layers/main/src/__tests__/integration.spec.ts+++ b/apps/electron/layers/main/src/__tests__/integration.spec.ts@@ -27,11 +27,11 @@ async function dispatch<>(namespace: T,functionName: F,- // @ts-ignore+ // @ts-expect-error...args: Parameters<WithoutFirstParameter<MainIPCHandlerMap[T][F]>>-): // @ts-ignore+): // @ts-expect-errorReturnType<MainIPCHandlerMap[T][F]> {- // @ts-ignore+ // @ts-expect-errorconst handlers = registeredHandlers.get(namespace + ':' + functionName);assert(handlers);@@ -108,7 +108,7 @@ const electronModule = {registeredHandlers.set(name, handlers);},addListener: (...args: any[]) => {- // @ts-ignore+ // @ts-expect-errorelectronModule.app.on(...args);},removeListener: () => {},diff --git a/apps/electron/layers/main/src/application-menu/create.ts b/apps/electron/layers/main/src/application-menu/create.tsindex 930a11cfff..023026a0da 100644--- a/apps/electron/layers/main/src/application-menu/create.ts+++ b/apps/electron/layers/main/src/application-menu/create.ts@@ -132,9 +132,9 @@ export function createApplicationMenu() {},];- // @ts-ignore The snippet is copied from Electron official docs.- // It's working as expected. No idea why it contains type errors.- // Just ignore for now.+ // @ts-expect-error: The snippet is copied from Electron official docs.+ // It's working as expected. No idea why it contains type errors.+ // Just ignore for now.const menu = Menu.buildFromTemplate(template);Menu.setApplicationMenu(menu);diff --git a/apps/electron/layers/main/src/db/__tests__/ensure-db.spec.ts b/apps/electron/layers/main/src/db/__tests__/ensure-db.spec.tsindex 64d639d304..ebc369d9b5 100644--- a/apps/electron/layers/main/src/db/__tests__/ensure-db.spec.ts+++ b/apps/electron/layers/main/src/db/__tests__/ensure-db.spec.ts@@ -32,7 +32,7 @@ const electronModule = {registeredHandlers.set(name, handlers);},addListener: (...args: any[]) => {- // @ts-ignore+ // @ts-expect-errorelectronModule.app.on(...args);},removeListener: () => {},diff --git a/apps/web/src/components/__debug__/client/editor.tsx b/apps/web/src/components/__debug__/client/editor.tsxindex 7749a490ff..782b9a9ddf 100644--- a/apps/web/src/components/__debug__/client/editor.tsx+++ b/apps/web/src/components/__debug__/client/editor.tsx@@ -21,9 +21,9 @@ const page = blockSuiteWorkspace.createPage({ id: 'page0' });const Editor: React.FC = () => {const onLoad = useCallback((page: Page, editor: EditorContainer) => {- // @ts-ignore+ // @ts-expect-errorglobalThis.page = page;- // @ts-ignore+ // @ts-expect-errorglobalThis.editor = editor;return () => void 0;}, []);diff --git a/apps/web/src/components/affine/create-workspace-modal/index.tsx b/apps/web/src/components/affine/create-workspace-modal/index.tsxindex 1550adb0ca..3e1826d3bb 100644--- a/apps/web/src/components/affine/create-workspace-modal/index.tsx+++ b/apps/web/src/components/affine/create-workspace-modal/index.tsx@@ -147,7 +147,7 @@ const SetDBLocationContent = ({if (result?.filePath) {onConfirmLocation(result.filePath);} else if (result?.error) {- // @ts-expect-error+ // @ts-expect-error: result.error is dynamic so the type is unknowntoast(t[result.error]());}};@@ -278,7 +278,7 @@ export const CreateWorkspaceModal = ({setStep('set-syncing-mode');} else if (result.error || result.canceled) {if (result.error) {- // @ts-expect-error+ // @ts-expect-error: result.error is dynamic so the type is unknowntoast(t[result.error]());}onClose();@@ -294,71 +294,92 @@ export const CreateWorkspaceModal = ({};}, [mode, onClose, t]);+ const onConfirmEnableCloudSyncing = useCallback(+ (enableCloudSyncing: boolean) => {+ (async function () {+ if (!config.enableLegacyCloud && enableCloudSyncing) {+ setOpenDisableCloudAlertModal(true);+ } else {+ let id = addedId;+ // syncing mode is also the last step+ if (addedId && mode === 'add') {+ await addLocalWorkspace(addedId);+ } else if (mode === 'new' && workspaceName) {+ id = await createLocalWorkspace(workspaceName);+ // if dbFileLocation is set, move db file to that location+ if (dbFileLocation) {+ await window.apis?.dialog.moveDBFile(id, dbFileLocation);+ }+ } else {+ logger.error('invalid state');+ return;+ }+ if (id) {+ onCreate(id);+ }+ }+ })().catch(e => {+ logger.error(e);+ });+ },+ [+ addLocalWorkspace,+ addedId,+ createLocalWorkspace,+ dbFileLocation,+ mode,+ onCreate,+ setOpenDisableCloudAlertModal,+ workspaceName,+ ]+ );++ const nameWorkspaceNode =+ step === 'name-workspace' ? (+ <NameWorkspaceContent+ // go to previous step instead?+ onClose={onClose}+ onConfirmName={async name => {+ setWorkspaceName(name);+ if (environment.isDesktop) {+ setStep('set-syncing-mode');+ } else {+ // this will be the last step for web for now+ // fix me later+ const id = await createLocalWorkspace(name);+ onCreate(id);+ }+ }}+ />+ ) : null;++ const setDBLocationNode =+ step === 'set-db-location' ? (+ <SetDBLocationContent+ onConfirmLocation={dir => {+ setDBFileLocation(dir);+ setStep('name-workspace');+ }}+ />+ ) : null;++ const setSyncingModeNode =+ step === 'set-syncing-mode' ? (+ <SetSyncingModeContent+ mode={mode}+ onConfirmMode={onConfirmEnableCloudSyncing}+ />+ ) : null;+return (<Modal open={mode !== false && !!step} onClose={onClose}><ModalWrapper width={560} style={{ padding: '10px' }}><div className={style.header}>- <ModalCloseButton- top={6}- right={6}- onClick={() => {- onClose();- }}- />+ <ModalCloseButton top={6} right={6} onClick={onClose} /></div>- {step === 'name-workspace' && (- <NameWorkspaceContent- // go to previous step instead?- onClose={onClose}- onConfirmName={async name => {- setWorkspaceName(name);- if (environment.isDesktop) {- setStep('set-syncing-mode');- } else {- // this will be the last step for web for now- // fix me later- const id = await createLocalWorkspace(name);- onCreate(id);- }- }}- />- )}- {step === 'set-db-location' && (- <SetDBLocationContent- onConfirmLocation={dir => {- setDBFileLocation(dir);- setStep('name-workspace');- }}- />- )}- {step === 'set-syncing-mode' && (- <SetSyncingModeContent- mode={mode}- onConfirmMode={async enableCloudSyncing => {- if (!config.enableLegacyCloud && enableCloudSyncing) {- setOpenDisableCloudAlertModal(true);- } else {- let id = addedId;- // syncing mode is also the last step- if (addedId && mode === 'add') {- await addLocalWorkspace(addedId);- } else if (mode === 'new' && workspaceName) {- id = await createLocalWorkspace(workspaceName);- // if dbFileLocation is set, move db file to that location- if (dbFileLocation) {- await window.apis?.dialog.moveDBFile(id, dbFileLocation);- }- } else {- logger.error('invalid state');- return;- }- if (id) {- onCreate(id);- }- }- }}- />- )}+ {nameWorkspaceNode}+ {setDBLocationNode}+ {setSyncingModeNode}</ModalWrapper></Modal>);diff --git a/apps/web/src/components/affine/workspace-setting-detail/panel/collaboration/index.tsx b/apps/web/src/components/affine/workspace-setting-detail/panel/collaboration/index.tsxindex 9e18022f48..af3f3a834a 100644--- a/apps/web/src/components/affine/workspace-setting-detail/panel/collaboration/index.tsx+++ b/apps/web/src/components/affine/workspace-setting-detail/panel/collaboration/index.tsx@@ -109,8 +109,7 @@ const AffineRemoteCollaborationPanel: React.FC<onClick={async () => {// FIXME: remove ignore- // @ts-ignore- await removeMember(member.id);+ await removeMember(Number(member.id));toast(t['Member has been removed']({name: user.name,diff --git a/apps/web/src/components/affine/workspace-setting-detail/panel/export/index.tsx b/apps/web/src/components/affine/workspace-setting-detail/panel/export/index.tsxindex 7fc0355dff..50682ee950 100644--- a/apps/web/src/components/affine/workspace-setting-detail/panel/export/index.tsx+++ b/apps/web/src/components/affine/workspace-setting-detail/panel/export/index.tsx@@ -18,7 +18,7 @@ export const ExportPanel = () => {if (id) {const result = await window.apis?.dialog.saveDBFileAs(id);if (result?.error) {- // @ts-expect-error+ // @ts-expect-error: result.error is dynamictoast(t[result.error]());} else if (!result?.canceled) {toast(t['Export success']());diff --git a/apps/web/src/components/affine/workspace-setting-detail/panel/general/index.tsx b/apps/web/src/components/affine/workspace-setting-detail/panel/general/index.tsxindex 423622f37c..b3f7a4bf85 100644--- a/apps/web/src/components/affine/workspace-setting-detail/panel/general/index.tsx+++ b/apps/web/src/components/affine/workspace-setting-detail/panel/general/index.tsx@@ -30,8 +30,7 @@ const useShowOpenDBFile = (workspaceId: string) => {window.apis.workspace.getMeta(workspaceId).then(meta => {setShow(!!meta.secondaryDBPath);});- // @ts-expect-error- return window.events.workspace.onMetaChange(newMeta => {+ return window.events.workspace.onMetaChange((newMeta: any) => {if (newMeta.workspaceId === workspaceId) {const meta = newMeta.meta;setShow(!!meta.secondaryDBPath);@@ -74,7 +73,7 @@ export const GeneralPanel: React.FC<PanelProps> = ({if (!result?.error && !result?.canceled) {toast(t['Move folder success']());} else if (result?.error) {- // @ts-expect-error+ // @ts-expect-error: result.error is dynamictoast(t[result.error]());}} catch (err) {diff --git a/apps/web/src/components/blocksuite/workspace-header/header-right-items/theme-mode-switch/style.ts b/apps/web/src/components/blocksuite/workspace-header/header-right-items/theme-mode-switch/style.tsindex 52a08bacd1..229dd2de8a 100644--- a/apps/web/src/components/blocksuite/workspace-header/header-right-items/theme-mode-switch/style.ts+++ b/apps/web/src/components/blocksuite/workspace-header/header-right-items/theme-mode-switch/style.ts@@ -1,5 +1,5 @@import { css, displayFlex, keyframes, styled } from '@affine/component';-// @ts-ignore+// @ts-expect-error: no types for css-springimport spring, { toString } from 'css-spring';const ANIMATE_DURATION = 400;diff --git a/packages/component/src/ui/popper/pure-popper.tsx b/packages/component/src/ui/popper/pure-popper.tsxindex 2679c2f106..c0e856c3c2 100644--- a/packages/component/src/ui/popper/pure-popper.tsx+++ b/packages/component/src/ui/popper/pure-popper.tsx@@ -28,7 +28,6 @@ export const PurePopper = (props: PurePopperProps) => {} = props;const [arrowRef, setArrowRef] = useState<HTMLElement | null>();- // @ts-ignorereturn (<BasicStyledPopperzIndex={zIndex}diff --git a/packages/workspace/src/providers/index.ts b/packages/workspace/src/providers/index.tsindex bddd5c58b8..82286eeb7e 100644--- a/packages/workspace/src/providers/index.ts+++ b/packages/workspace/src/providers/index.ts@@ -182,12 +182,19 @@ const createSQLiteProvider = (const connect = () => {logger.info('connecting sqlite provider', blockSuiteWorkspace.id);blockSuiteWorkspace.doc.on('update', handleUpdate);- // @ts-expect-error- unsubscribe = events.db.onExternalUpdate(({ update, workspaceId }) => {- if (workspaceId === blockSuiteWorkspace.id) {- Y.applyUpdate(blockSuiteWorkspace.doc, update, sqliteOrigin);+ unsubscribe = events.db.onExternalUpdate(+ ({+ update,+ workspaceId,+ }: {+ workspaceId: string;+ update: Uint8Array;+ }) => {+ if (workspaceId === blockSuiteWorkspace.id) {+ Y.applyUpdate(blockSuiteWorkspace.doc, update, sqliteOrigin);+ }}- });+ );connected = true;logger.info('connecting sqlite done', blockSuiteWorkspace.id);};diff --git a/packages/workspace/tsconfig.json b/packages/workspace/tsconfig.jsonindex 9e4af629e2..c96773e131 100644--- a/packages/workspace/tsconfig.json+++ b/packages/workspace/tsconfig.json@@ -10,7 +10,6 @@{ "path": "../y-indexeddb" },{ "path": "../env" },{ "path": "../debug" },- { "path": "../hooks" },- { "path": "../../apps/electron" }+ { "path": "../hooks" }]}diff --git a/tests/libs/utils.ts b/tests/libs/utils.tsindex 4e40549774..9b6b4d3b07 100644--- a/tests/libs/utils.ts+++ b/tests/libs/utils.ts@@ -116,7 +116,6 @@ export async function loginUser(}) {await page.evaluate(async token => {- // @ts-ignoreglobalThis.setLogin(token);}, token);}diff --git a/tests/parallels/debug-init-page.spec.ts b/tests/parallels/debug-init-page.spec.tsindex 43ab8dfef5..99ec2ed29f 100644--- a/tests/parallels/debug-init-page.spec.ts+++ b/tests/parallels/debug-init-page.spec.ts@@ -5,7 +5,6 @@ test('should have page0', async ({ page }) => {await page.goto('http://localhost:8080/_debug/init-page');await page.waitForSelector('v-line');const pageId = await page.evaluate(async () => {- // @ts-ignorereturn globalThis.page.id;});expect(pageId).toBe('page0');