mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-09-24 04:27:27 +08:00
style: add no-misused-promises rule (#3547)
Co-authored-by: Peng Xiao <pengxiao@outlook.com>
This commit is contained in:
@@ -214,6 +214,7 @@ const config = {
|
|||||||
ignoreIIFE: false,
|
ignoreIIFE: false,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
'@typescript-eslint/no-misused-promises': ['error'],
|
||||||
},
|
},
|
||||||
})),
|
})),
|
||||||
{
|
{
|
||||||
@@ -239,6 +240,7 @@ const config = {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
'@typescript-eslint/no-floating-promises': 0,
|
'@typescript-eslint/no-floating-promises': 0,
|
||||||
|
'@typescript-eslint/no-misused-promises': 0,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -115,7 +115,11 @@ function startPollingSecondaryDB(db: WorkspaceSQLiteDB) {
|
|||||||
const secondaryDB = new SecondaryWorkspaceSQLiteDB(path, db);
|
const secondaryDB = new SecondaryWorkspaceSQLiteDB(path, db);
|
||||||
return new Observable<SecondaryWorkspaceSQLiteDB>(subscriber => {
|
return new Observable<SecondaryWorkspaceSQLiteDB>(subscriber => {
|
||||||
subscriber.next(secondaryDB);
|
subscriber.next(secondaryDB);
|
||||||
return () => secondaryDB.destroy();
|
return () => {
|
||||||
|
secondaryDB.destroy().catch(err => {
|
||||||
|
subscriber.error(err);
|
||||||
|
});
|
||||||
|
};
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
switchMap(secondaryDB => {
|
switchMap(secondaryDB => {
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ app.on('second-instance', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.on('open-url', async (_, _url) => {
|
app.on('open-url', (_, _url) => {
|
||||||
// todo: handle `affine://...` urls
|
// todo: handle `affine://...` urls
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -54,7 +54,11 @@ app.on('window-all-closed', () => {
|
|||||||
/**
|
/**
|
||||||
* @see https://www.electronjs.org/docs/v14-x-y/api/app#event-activate-macos Event: 'activate'
|
* @see https://www.electronjs.org/docs/v14-x-y/api/app#event-activate-macos Event: 'activate'
|
||||||
*/
|
*/
|
||||||
app.on('activate', restoreOrCreateWindow);
|
app.on('activate', () => {
|
||||||
|
restoreOrCreateWindow().catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create app window when background process will be ready
|
* Create app window when background process will be ready
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ export function getGoogleOauthCode() {
|
|||||||
logger.error('Failed to open external url', e);
|
logger.error('Failed to open external url', e);
|
||||||
reject(e);
|
reject(e);
|
||||||
});
|
});
|
||||||
const handleOpenUrl = async (_: any, url: string) => {
|
const handleOpenUrl = (_: any, url: string) => {
|
||||||
const mainWindow = BrowserWindow.getAllWindows().find(
|
const mainWindow = BrowserWindow.getAllWindows().find(
|
||||||
w => !w.isDestroyed()
|
w => !w.isDestroyed()
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -99,7 +99,9 @@ export const registerUpdater = async () => {
|
|||||||
});
|
});
|
||||||
autoUpdater.forceDevUpdateConfig = isDev;
|
autoUpdater.forceDevUpdateConfig = isDev;
|
||||||
|
|
||||||
app.on('activate', async () => {
|
app.on('activate', () => {
|
||||||
await checkForUpdates(false);
|
checkForUpdates(false).catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,10 +19,15 @@ const mainThread = AsyncCall<{
|
|||||||
channel: new MessageEventChannel(parentPort),
|
channel: new MessageEventChannel(parentPort),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||||
globalThis.console.log = mainThread.log;
|
globalThis.console.log = mainThread.log;
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||||
globalThis.console.error = mainThread.log;
|
globalThis.console.error = mainThread.log;
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||||
globalThis.console.info = mainThread.log;
|
globalThis.console.info = mainThread.log;
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||||
globalThis.console.debug = mainThread.log;
|
globalThis.console.debug = mainThread.log;
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||||
globalThis.console.warn = mainThread.log;
|
globalThis.console.warn = mainThread.log;
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ export class WorkspaceResolver {
|
|||||||
return workspace.permission;
|
return workspace.permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
const permission = this.permissionProvider.get(workspace.id, user.id);
|
const permission = await this.permissionProvider.get(workspace.id, user.id);
|
||||||
|
|
||||||
if (!permission) {
|
if (!permission) {
|
||||||
throw new ForbiddenException();
|
throw new ForbiddenException();
|
||||||
|
|||||||
@@ -9,8 +9,10 @@ export class PrismaService extends PrismaClient implements OnModuleInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async enableShutdownHooks(app: INestApplication) {
|
async enableShutdownHooks(app: INestApplication) {
|
||||||
process.on('beforeExit', async () => {
|
process.on('beforeExit', () => {
|
||||||
await app.close();
|
app.close().catch(e => {
|
||||||
|
console.error(e);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,7 +181,9 @@ function NotificationCard(props: NotificationCardProps): ReactElement {
|
|||||||
|
|
||||||
const onClickUndo = useCallback(() => {
|
const onClickUndo = useCallback(() => {
|
||||||
if (notification.undo) {
|
if (notification.undo) {
|
||||||
return notification.undo();
|
notification.undo().catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return void 0;
|
return void 0;
|
||||||
}, [notification]);
|
}, [notification]);
|
||||||
|
|||||||
@@ -63,10 +63,14 @@ export const CollectionBar = (props: CollectionBarProps) => {
|
|||||||
: t['com.affine.collection-bar.action.tooltip.pin'](),
|
: t['com.affine.collection-bar.action.tooltip.pin'](),
|
||||||
className: styles.pin,
|
className: styles.pin,
|
||||||
click: () => {
|
click: () => {
|
||||||
return setting.updateCollection({
|
setting
|
||||||
...collection,
|
.updateCollection({
|
||||||
pinned: !collection.pinned,
|
...collection,
|
||||||
});
|
pinned: !collection.pinned,
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -102,6 +106,7 @@ export const CollectionBar = (props: CollectionBarProps) => {
|
|||||||
init={collection}
|
init={collection}
|
||||||
open={open}
|
open={open}
|
||||||
onClose={onClose}
|
onClose={onClose}
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||||
onConfirm={setting.updateCollection}
|
onConfirm={setting.updateCollection}
|
||||||
></EditCollectionModel>
|
></EditCollectionModel>
|
||||||
<ViewLayersIcon
|
<ViewLayersIcon
|
||||||
|
|||||||
@@ -43,10 +43,14 @@ const CollectionOption = ({
|
|||||||
icon: <PinIcon />,
|
icon: <PinIcon />,
|
||||||
name: 'pin',
|
name: 'pin',
|
||||||
click: () => {
|
click: () => {
|
||||||
return setting.updateCollection({
|
setting
|
||||||
...collection,
|
.updateCollection({
|
||||||
pinned: !collection.pinned,
|
...collection,
|
||||||
});
|
pinned: !collection.pinned,
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -144,10 +148,14 @@ export const CollectionList = ({
|
|||||||
const [collection, setCollection] = useState<Collection>();
|
const [collection, setCollection] = useState<Collection>();
|
||||||
const onChange = useCallback(
|
const onChange = useCallback(
|
||||||
(filterList: Filter[]) => {
|
(filterList: Filter[]) => {
|
||||||
return setting.updateCollection({
|
setting
|
||||||
...setting.currentCollection,
|
.updateCollection({
|
||||||
filterList,
|
...setting.currentCollection,
|
||||||
});
|
filterList,
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
[setting]
|
[setting]
|
||||||
);
|
);
|
||||||
@@ -156,10 +164,9 @@ export const CollectionList = ({
|
|||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
const onConfirm = useCallback(
|
const onConfirm = useCallback(
|
||||||
(view: Collection) => {
|
async (view: Collection) => {
|
||||||
return setting.updateCollection(view).then(() => {
|
await setting.updateCollection(view);
|
||||||
closeUpdateCollectionModal();
|
closeUpdateCollectionModal();
|
||||||
});
|
|
||||||
},
|
},
|
||||||
[closeUpdateCollectionModal, setting]
|
[closeUpdateCollectionModal, setting]
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ type CreateCollectionProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
type SaveCollectionButtonProps = {
|
type SaveCollectionButtonProps = {
|
||||||
onConfirm: (collection: Collection) => void;
|
onConfirm: (collection: Collection) => Promise<void>;
|
||||||
getPageInfo: GetPageInfoById;
|
getPageInfo: GetPageInfoById;
|
||||||
propertiesMeta: PropertiesMeta;
|
propertiesMeta: PropertiesMeta;
|
||||||
filterList: Filter[];
|
filterList: Filter[];
|
||||||
@@ -49,7 +49,7 @@ export const EditCollectionModel = ({
|
|||||||
title,
|
title,
|
||||||
}: {
|
}: {
|
||||||
init?: Collection;
|
init?: Collection;
|
||||||
onConfirm: (view: Collection) => void;
|
onConfirm: (view: Collection) => Promise<void>;
|
||||||
open: boolean;
|
open: boolean;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
title?: string;
|
title?: string;
|
||||||
@@ -57,6 +57,18 @@ export const EditCollectionModel = ({
|
|||||||
propertiesMeta: PropertiesMeta;
|
propertiesMeta: PropertiesMeta;
|
||||||
}) => {
|
}) => {
|
||||||
const t = useAFFiNEI18N();
|
const t = useAFFiNEI18N();
|
||||||
|
const onConfirmOnCollection = useCallback(
|
||||||
|
(view: Collection) => {
|
||||||
|
onConfirm(view)
|
||||||
|
.then(() => {
|
||||||
|
onClose();
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[onClose, onConfirm]
|
||||||
|
);
|
||||||
return (
|
return (
|
||||||
<Modal open={open} onClose={onClose}>
|
<Modal open={open} onClose={onClose}>
|
||||||
<ModalWrapper
|
<ModalWrapper
|
||||||
@@ -75,10 +87,7 @@ export const EditCollectionModel = ({
|
|||||||
init={init}
|
init={init}
|
||||||
getPageInfo={getPageInfo}
|
getPageInfo={getPageInfo}
|
||||||
onCancel={onClose}
|
onCancel={onClose}
|
||||||
onConfirm={view => {
|
onConfirm={onConfirmOnCollection}
|
||||||
onConfirm(view);
|
|
||||||
onClose();
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
) : null}
|
) : null}
|
||||||
</ModalWrapper>
|
</ModalWrapper>
|
||||||
|
|||||||
@@ -47,9 +47,15 @@ export const AffineSharePage: FC<ShareMenuProps> = props => {
|
|||||||
const onClickCreateLink = useCallback(() => {
|
const onClickCreateLink = useCallback(() => {
|
||||||
setIsPublic(true);
|
setIsPublic(true);
|
||||||
}, [setIsPublic]);
|
}, [setIsPublic]);
|
||||||
const onClickCopyLink = useCallback(async () => {
|
const onClickCopyLink = useCallback(() => {
|
||||||
await navigator.clipboard.writeText(sharingUrl);
|
navigator.clipboard
|
||||||
toast(t['Copied link to clipboard']());
|
.writeText(sharingUrl)
|
||||||
|
.then(() => {
|
||||||
|
toast(t['Copied link to clipboard']());
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
}, [sharingUrl, t]);
|
}, [sharingUrl, t]);
|
||||||
const onDisablePublic = useCallback(() => {
|
const onDisablePublic = useCallback(() => {
|
||||||
setIsPublic(false);
|
setIsPublic(false);
|
||||||
|
|||||||
@@ -115,21 +115,26 @@ export const toast = (
|
|||||||
|
|
||||||
element.animate(fadeIn, options);
|
element.animate(fadeIn, options);
|
||||||
|
|
||||||
setTimeout(async () => {
|
setTimeout(() => {
|
||||||
const animation = element.animate(
|
const animation = element.animate(
|
||||||
// fade out
|
// fade out
|
||||||
fadeIn.reverse(),
|
fadeIn.reverse(),
|
||||||
options
|
options
|
||||||
);
|
);
|
||||||
await animation.finished;
|
animation.finished
|
||||||
element.style.maxHeight = '0';
|
.then(() => {
|
||||||
element.style.margin = '0';
|
element.style.maxHeight = '0';
|
||||||
element.style.padding = '0';
|
element.style.margin = '0';
|
||||||
// wait for transition
|
element.style.padding = '0';
|
||||||
// ToastContainer = null;
|
// wait for transition
|
||||||
element.addEventListener('transitionend', () => {
|
// ToastContainer = null;
|
||||||
element.remove();
|
element.addEventListener('transitionend', () => {
|
||||||
});
|
element.remove();
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
}, duration);
|
}, duration);
|
||||||
return element;
|
return element;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -87,23 +87,22 @@ const main = async () => {
|
|||||||
language => language.completeRate > 0.4
|
language => language.completeRate > 0.4
|
||||||
);
|
);
|
||||||
|
|
||||||
availableLanguages
|
for (const language of availableLanguages
|
||||||
// skip base language
|
// skip base language
|
||||||
.filter(i => !i.base)
|
.filter(i => !i.base)) {
|
||||||
.forEach(async language => {
|
await fs.writeFile(
|
||||||
await fs.writeFile(
|
path.resolve(RES_DIR, `${language.tag}.json`),
|
||||||
path.resolve(RES_DIR, `${language.tag}.json`),
|
JSON.stringify(
|
||||||
JSON.stringify(
|
{
|
||||||
{
|
'// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.':
|
||||||
'// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.':
|
'',
|
||||||
'',
|
...flattenTranslation(language.translations),
|
||||||
...flattenTranslation(language.translations),
|
},
|
||||||
},
|
null,
|
||||||
null,
|
INDENT
|
||||||
INDENT
|
) + '\n'
|
||||||
) + '\n'
|
);
|
||||||
);
|
}
|
||||||
});
|
|
||||||
|
|
||||||
console.log('Generating meta data...');
|
console.log('Generating meta data...');
|
||||||
const code = `// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
const code = `// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||||
|
|||||||
@@ -127,11 +127,11 @@ const main = async () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
diff.add.forEach(async key => {
|
for (const key of diff.add) {
|
||||||
const val = flatLocalTranslations[key];
|
const val = flatLocalTranslations[key];
|
||||||
console.log(`Creating new key: ${key} -> ${val}`);
|
console.log(`Creating new key: ${key} -> ${val}`);
|
||||||
await createsNewKey(key, { [BASE_LANGUAGES]: val });
|
await createsNewKey(key, { [BASE_LANGUAGES]: val });
|
||||||
});
|
}
|
||||||
|
|
||||||
// TODO remove unused tags from used keys
|
// TODO remove unused tags from used keys
|
||||||
|
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ function getMainAPIs() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const helperPort$ = new Promise<MessagePort>(resolve =>
|
const helperPort$ = new Promise<MessagePort>(resolve =>
|
||||||
ipcRenderer.on('helper-connection', async e => {
|
ipcRenderer.on('helper-connection', e => {
|
||||||
console.info('[preload] helper-connection', e);
|
console.info('[preload] helper-connection', e);
|
||||||
resolve(e.ports[0]);
|
resolve(e.ports[0]);
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -106,14 +106,15 @@ export const createSQLiteDBDownloadProvider: DocProviderCreator = (
|
|||||||
cleanup: () => {
|
cleanup: () => {
|
||||||
// todo
|
// todo
|
||||||
},
|
},
|
||||||
sync: async () => {
|
sync: () => {
|
||||||
logger.info('connect sqlite download provider', id);
|
logger.info('connect sqlite download provider', id);
|
||||||
try {
|
syncUpdates(rootDoc)
|
||||||
await syncUpdates(rootDoc);
|
.then(() => {
|
||||||
_resolve();
|
_resolve();
|
||||||
} catch (error) {
|
})
|
||||||
_reject(error);
|
.catch(error => {
|
||||||
}
|
_reject(error);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -34,9 +34,12 @@ const Actions = () => {
|
|||||||
/>
|
/>
|
||||||
<IconButton
|
<IconButton
|
||||||
className={sendButtonStyle}
|
className={sendButtonStyle}
|
||||||
onClick={useCallback(async () => {
|
onClick={useCallback(() => {
|
||||||
await call(input);
|
call(input)
|
||||||
await generateFollowingUp();
|
.then(() => generateFollowingUp())
|
||||||
|
.catch(e => {
|
||||||
|
console.error(e);
|
||||||
|
});
|
||||||
}, [call, generateFollowingUp, input])}
|
}, [call, generateFollowingUp, input])}
|
||||||
>
|
>
|
||||||
<SendIcon />
|
<SendIcon />
|
||||||
|
|||||||
Reference in New Issue
Block a user