From 9b64c1fbdb34821b72e04c6a32f24515355cc25e Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Wed, 25 Nov 2020 14:40:25 +0000 Subject: [PATCH] Added no-floating-promises eslint rule --- .eslintrc.js | 5 +++++ packages/app-desktop/InteropServiceHelper.ts | 4 ++-- packages/app-desktop/app.ts | 8 +++---- .../commands/openProfileDirectory.ts | 2 +- .../commands/startExternalEditing.ts | 2 +- .../commands/stopExternalEditing.ts | 2 +- .../commands/toggleExternalEditing.ts | 4 ++-- .../gui/ConfigScreen/ConfigScreen.tsx | 2 +- .../gui/KeymapConfig/utils/useKeymap.ts | 2 +- .../app-desktop/gui/MainScreen/MainScreen.tsx | 2 +- .../gui/MainScreen/commands/selectTemplate.ts | 4 ++-- .../MainScreen/commands/showNoteProperties.ts | 2 +- packages/app-desktop/gui/MenuBar.tsx | 18 +++++++-------- .../NoteBody/CodeMirror/CodeMirror.tsx | 4 ++-- .../NoteBody/CodeMirror/utils/useKeymap.ts | 2 +- .../NoteEditor/NoteBody/TinyMCE/TinyMCE.tsx | 14 ++++++------ .../app-desktop/gui/NoteEditor/NoteEditor.tsx | 8 +++---- .../gui/NoteEditor/NoteTitle/NoteTitleBar.tsx | 4 ++-- .../gui/NoteEditor/utils/useFolder.ts | 2 +- .../gui/NoteEditor/utils/useFormNote.ts | 8 +++---- .../app-desktop/gui/NoteList/NoteList.tsx | 4 ++-- .../gui/NoteListControls/NoteListControls.tsx | 4 ++-- packages/app-desktop/gui/ResourceScreen.tsx | 6 ++--- .../app-desktop/gui/SearchBar/SearchBar.tsx | 6 ++--- packages/app-desktop/gui/ShareNoteDialog.tsx | 2 +- packages/app-desktop/gui/SideBar/SideBar.tsx | 8 +++---- .../gui/StatusScreen/StatusScreen.tsx | 4 ++-- packages/app-desktop/plugins/GotoAnything.tsx | 6 ++--- .../services/plugins/hooks/useThemeCss.ts | 2 +- .../NoteBodyViewer/hooks/useSource.ts | 2 +- .../app-mobile/components/screens/Note.tsx | 22 +++++++++---------- packages/lib/AsyncActionQueue.ts | 2 +- packages/lib/Synchronizer.ts | 2 +- .../lib/services/AlarmServiceDriverNode.ts | 4 ++-- packages/lib/services/CommandService.ts | 2 +- packages/lib/services/ExternalEditWatcher.ts | 4 ++-- .../lib/services/ResourceEditWatcher/index.ts | 8 +++---- packages/lib/services/ResourceService.ts | 4 ++-- .../services/commands/ToolbarButtonUtils.ts | 4 ++-- .../interop/InteropService_Importer_Md.ts | 6 ++--- .../lib/services/plugins/WebviewController.ts | 2 +- .../lib/services/plugins/api/JoplinPlugins.ts | 2 +- .../spellChecker/SpellCheckerService.ts | 6 ++--- .../synchronizer/gui/useSyncTargetUpgrade.ts | 2 +- tsconfig.eslint.json | 7 ++++++ 45 files changed, 116 insertions(+), 104 deletions(-) create mode 100644 tsconfig.eslint.json diff --git a/.eslintrc.js b/.eslintrc.js index 66dc5121a7..a2c2317c23 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -126,6 +126,10 @@ module.exports = { { // enable the rule specifically for TypeScript files 'files': ['*.ts', '*.tsx'], + 'parserOptions': { + // Required for @typescript-eslint/no-floating-promises + 'project': './tsconfig.eslint.json', + }, 'rules': { // Warn only because it would make it difficult to convert JS classes to TypeScript, unless we // make everything public which is not great. New code however should specify member accessibility. @@ -152,6 +156,7 @@ module.exports = { 'requireLast': false, }, }], + '@typescript-eslint/no-floating-promises': ['error'], }, }, ], diff --git a/packages/app-desktop/InteropServiceHelper.ts b/packages/app-desktop/InteropServiceHelper.ts index 33770a38ff..6a51f99d32 100644 --- a/packages/app-desktop/InteropServiceHelper.ts +++ b/packages/app-desktop/InteropServiceHelper.ts @@ -156,7 +156,7 @@ export default class InteropServiceHelper { if (Array.isArray(path)) path = path[0]; - CommandService.instance().execute('showModalMessage', _('Exporting to "%s" as "%s" format. Please wait...', path, module.format)); + void CommandService.instance().execute('showModalMessage', _('Exporting to "%s" as "%s" format. Please wait...', path, module.format)); const exportOptions: ExportOptions = {}; exportOptions.path = path; @@ -177,7 +177,7 @@ export default class InteropServiceHelper { bridge().showErrorMessageBox(_('Could not export notes: %s', error.message)); } - CommandService.instance().execute('hideModalMessage'); + void CommandService.instance().execute('hideModalMessage'); } } diff --git a/packages/app-desktop/app.ts b/packages/app-desktop/app.ts index 67249fe0b4..d6fd631f06 100644 --- a/packages/app-desktop/app.ts +++ b/packages/app-desktop/app.ts @@ -424,7 +424,7 @@ class Application extends BaseApplication { const contextMenu = Menu.buildFromTemplate([ { label: _('Open %s', app.electronApp().name), click: () => { app.window().show(); } }, { type: 'separator' }, - { label: _('Quit'), click: () => { app.quit(); } }, + { label: _('Quit'), click: () => { void app.quit(); } }, ]); app.createTray(contextMenu); } @@ -664,7 +664,7 @@ class Application extends BaseApplication { this.updateTray(); shim.setTimeout(() => { - AlarmService.garbageCollect(); + void AlarmService.garbageCollect(); }, 1000 * 60 * 60); if (Setting.value('startMinimized') && Setting.value('showTrayIcon')) { @@ -676,12 +676,12 @@ class Application extends BaseApplication { ResourceService.runInBackground(); if (Setting.value('env') === 'dev') { - AlarmService.updateAllNotifications(); + void AlarmService.updateAllNotifications(); } else { reg.scheduleSync(1000).then(() => { // Wait for the first sync before updating the notifications, since synchronisation // might change the notifications. - AlarmService.updateAllNotifications(); + void AlarmService.updateAllNotifications(); DecryptionWorker.instance().scheduleStart(); }); diff --git a/packages/app-desktop/commands/openProfileDirectory.ts b/packages/app-desktop/commands/openProfileDirectory.ts index c6ac723256..634f5edbe2 100644 --- a/packages/app-desktop/commands/openProfileDirectory.ts +++ b/packages/app-desktop/commands/openProfileDirectory.ts @@ -11,7 +11,7 @@ export const declaration: CommandDeclaration = { export const runtime = (): CommandRuntime => { return { execute: async () => { - bridge().openItem(Setting.value('profileDir')); + void bridge().openItem(Setting.value('profileDir')); }, }; }; diff --git a/packages/app-desktop/commands/startExternalEditing.ts b/packages/app-desktop/commands/startExternalEditing.ts index 19f63c9459..7d7ce11c10 100644 --- a/packages/app-desktop/commands/startExternalEditing.ts +++ b/packages/app-desktop/commands/startExternalEditing.ts @@ -18,7 +18,7 @@ export const runtime = (): CommandRuntime => { try { const note = await Note.load(noteId); - ExternalEditWatcher.instance().openAndWatch(note); + void ExternalEditWatcher.instance().openAndWatch(note); } catch (error) { bridge().showErrorMessageBox(_('Error opening note in editor: %s', error.message)); } diff --git a/packages/app-desktop/commands/stopExternalEditing.ts b/packages/app-desktop/commands/stopExternalEditing.ts index 093df60c93..7999ac7ffd 100644 --- a/packages/app-desktop/commands/stopExternalEditing.ts +++ b/packages/app-desktop/commands/stopExternalEditing.ts @@ -13,7 +13,7 @@ export const runtime = (): CommandRuntime => { return { execute: async (context: CommandContext, noteId: string = null) => { noteId = noteId || stateUtils.selectedNoteId(context.state); - ExternalEditWatcher.instance().stopWatching(noteId); + void ExternalEditWatcher.instance().stopWatching(noteId); }, enabledCondition: 'oneNoteSelected', }; diff --git a/packages/app-desktop/commands/toggleExternalEditing.ts b/packages/app-desktop/commands/toggleExternalEditing.ts index f5d3eaf860..5a40993e9b 100644 --- a/packages/app-desktop/commands/toggleExternalEditing.ts +++ b/packages/app-desktop/commands/toggleExternalEditing.ts @@ -17,9 +17,9 @@ export const runtime = (): CommandRuntime => { if (!noteId) return; if (context.state.watchedNoteFiles.includes(noteId)) { - CommandService.instance().execute('stopExternalEditing', noteId); + void CommandService.instance().execute('stopExternalEditing', noteId); } else { - CommandService.instance().execute('startExternalEditing', noteId); + void CommandService.instance().execute('startExternalEditing', noteId); } }, enabledCondition: 'oneNoteSelected', diff --git a/packages/app-desktop/gui/ConfigScreen/ConfigScreen.tsx b/packages/app-desktop/gui/ConfigScreen/ConfigScreen.tsx index 8c89079d6a..5a577a5923 100644 --- a/packages/app-desktop/gui/ConfigScreen/ConfigScreen.tsx +++ b/packages/app-desktop/gui/ConfigScreen/ConfigScreen.tsx @@ -696,7 +696,7 @@ class ConfigScreenComponent extends React.Component { const needRestartComp: any = this.state.needRestart ? (
{this.restartMessage()} - { this.restartApp(); }}>{_('Restart now')} + { void this.restartApp(); }}>{_('Restart now')}
) : null; diff --git a/packages/app-desktop/gui/KeymapConfig/utils/useKeymap.ts b/packages/app-desktop/gui/KeymapConfig/utils/useKeymap.ts index d381c702f8..6584484743 100644 --- a/packages/app-desktop/gui/KeymapConfig/utils/useKeymap.ts +++ b/packages/app-desktop/gui/KeymapConfig/utils/useKeymap.ts @@ -86,7 +86,7 @@ const useKeymap = (): [ } } - saveKeymap(); + void saveKeymap(); }, [keymapItems, mustSave]); return [keymapItems, keymapError, overrideKeymapItems, setAccelerator, resetAccelerator]; diff --git a/packages/app-desktop/gui/MainScreen/MainScreen.tsx b/packages/app-desktop/gui/MainScreen/MainScreen.tsx index 37e185c67e..a5402b1478 100644 --- a/packages/app-desktop/gui/MainScreen/MainScreen.tsx +++ b/packages/app-desktop/gui/MainScreen/MainScreen.tsx @@ -330,7 +330,7 @@ class MainScreenComponent extends React.Component { layoutModeListenerKeyDown(event: any) { if (event.key !== 'Escape') return; if (!this.props.layoutMoveMode) return; - CommandService.instance().execute('toggleLayoutMoveMode'); + void CommandService.instance().execute('toggleLayoutMoveMode'); } componentDidMount() { diff --git a/packages/app-desktop/gui/MainScreen/commands/selectTemplate.ts b/packages/app-desktop/gui/MainScreen/commands/selectTemplate.ts index a9e0a4817d..cac70cab8b 100644 --- a/packages/app-desktop/gui/MainScreen/commands/selectTemplate.ts +++ b/packages/app-desktop/gui/MainScreen/commands/selectTemplate.ts @@ -18,9 +18,9 @@ export const runtime = (comp: any): CommandRuntime => { onClose: async (answer: any) => { if (answer) { if (noteType === 'note' || noteType === 'todo') { - CommandService.instance().execute('newNote', answer.value, noteType === 'todo'); + void CommandService.instance().execute('newNote', answer.value, noteType === 'todo'); } else { - CommandService.instance().execute('insertText', TemplateUtils.render(answer.value)); + void CommandService.instance().execute('insertText', TemplateUtils.render(answer.value)); } } diff --git a/packages/app-desktop/gui/MainScreen/commands/showNoteProperties.ts b/packages/app-desktop/gui/MainScreen/commands/showNoteProperties.ts index bb1e86d7a3..e54d7bc42b 100644 --- a/packages/app-desktop/gui/MainScreen/commands/showNoteProperties.ts +++ b/packages/app-desktop/gui/MainScreen/commands/showNoteProperties.ts @@ -18,7 +18,7 @@ export const runtime = (comp: any): CommandRuntime => { noteId: noteId, visible: true, onRevisionLinkClick: () => { - CommandService.instance().execute('showRevisions'); + void CommandService.instance().execute('showRevisions'); }, }, }); diff --git a/packages/app-desktop/gui/MenuBar.tsx b/packages/app-desktop/gui/MenuBar.tsx index dcd62f7b91..43d46e0f0a 100644 --- a/packages/app-desktop/gui/MenuBar.tsx +++ b/packages/app-desktop/gui/MenuBar.tsx @@ -112,7 +112,7 @@ function useMenu(props: Props) { const [modulesLastChangeTime, setModulesLastChangeTime] = useState(Date.now()); const onMenuItemClick = useCallback((commandName: string) => { - CommandService.instance().execute(commandName); + void CommandService.instance().execute(commandName); }, []); const onImportModuleClick = useCallback(async (module: Module, moduleSource: string) => { @@ -134,7 +134,7 @@ function useMenu(props: Props) { const modalMessage = _('Importing from "%s" as "%s" format. Please wait...', path, module.format); - CommandService.instance().execute('showModalMessage', modalMessage); + void CommandService.instance().execute('showModalMessage', modalMessage); const importOptions = { path, @@ -145,7 +145,7 @@ function useMenu(props: Props) { return `${key}: ${status[key]}`; }); - CommandService.instance().execute('showModalMessage', `${modalMessage}\n\n${statusStrings.join('\n')}`); + void CommandService.instance().execute('showModalMessage', `${modalMessage}\n\n${statusStrings.join('\n')}`); }, onError: console.warn, destinationFolderId: !module.isNoteArchive && moduleSource === 'file' ? props.selectedFolderId : null, @@ -159,7 +159,7 @@ function useMenu(props: Props) { bridge().showErrorMessageBox(error.message); } - CommandService.instance().execute('hideModalMessage'); + void CommandService.instance().execute('hideModalMessage'); }, [props.selectedFolderId]); const onMenuItemClickRef = useRef(null); @@ -177,7 +177,7 @@ function useMenu(props: Props) { const quitMenuItem = { label: _('Quit'), accelerator: keymapService.getAccelerator('quit'), - click: () => { bridge().electronApp().quit(); }, + click: () => { void bridge().electronApp().quit(); }, }; const sortNoteFolderItems = (type: string) => { @@ -284,23 +284,23 @@ function useMenu(props: Props) { templateItems.push({ label: _('Create note from template'), click: () => { - CommandService.instance().execute('selectTemplate', 'note'); + void CommandService.instance().execute('selectTemplate', 'note'); }, }, { label: _('Create to-do from template'), click: () => { - CommandService.instance().execute('selectTemplate', 'todo'); + void CommandService.instance().execute('selectTemplate', 'todo'); }, }, { label: _('Insert template'), accelerator: keymapService.getAccelerator('insertTemplate'), click: () => { - CommandService.instance().execute('selectTemplate'); + void CommandService.instance().execute('selectTemplate'); }, }, { label: _('Open template directory'), click: () => { - bridge().openItem(Setting.value('templateDir')); + void bridge().openItem(Setting.value('templateDir')); }, }, { label: _('Refresh templates'), diff --git a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/CodeMirror.tsx b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/CodeMirror.tsx index dee3aac3cb..b5fa892d82 100644 --- a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/CodeMirror.tsx +++ b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/CodeMirror.tsx @@ -323,7 +323,7 @@ function CodeMirror(props: NoteBodyEditorProps, ref: any) { } } - loadScripts(); + void loadScripts(); return () => { cancelled = true; @@ -630,7 +630,7 @@ function CodeMirror(props: NoteBodyEditorProps, ref: any) { editorPasteText(); } else { // To handle pasting images - onEditorPaste(); + void onEditorPaste(); } }, }) diff --git a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useKeymap.ts b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useKeymap.ts index 989db4569f..37d2e2d319 100644 --- a/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useKeymap.ts +++ b/packages/app-desktop/gui/NoteEditor/NoteBody/CodeMirror/utils/useKeymap.ts @@ -5,7 +5,7 @@ import shim from '@joplin/lib/shim'; export default function useKeymap(CodeMirror: any) { function save() { - CommandService.instance().execute('synchronize'); + void CommandService.instance().execute('synchronize'); } function setupEmacs() { diff --git a/packages/app-desktop/gui/NoteEditor/NoteBody/TinyMCE/TinyMCE.tsx b/packages/app-desktop/gui/NoteEditor/NoteBody/TinyMCE/TinyMCE.tsx index af6c1ac6fc..8d0c64ed7f 100644 --- a/packages/app-desktop/gui/NoteEditor/NoteBody/TinyMCE/TinyMCE.tsx +++ b/packages/app-desktop/gui/NoteEditor/NoteBody/TinyMCE/TinyMCE.tsx @@ -371,7 +371,7 @@ const TinyMCE = (props: NoteBodyEditorProps, ref: any) => { setScriptLoaded(true); } - loadScripts(); + void loadScripts(); return () => { cancelled = true; @@ -661,7 +661,7 @@ const TinyMCE = (props: NoteBodyEditorProps, ref: any) => { tooltip: _('Insert Date Time'), icon: 'insert-time', onAction: function() { - CommandService.instance().execute('insertDateTime'); + void CommandService.instance().execute('insertDateTime'); }, }); @@ -670,7 +670,7 @@ const TinyMCE = (props: NoteBodyEditorProps, ref: any) => { tooltip: CommandService.instance().label(pluginCommandName), icon: CommandService.instance().iconName(pluginCommandName, 'tinymce'), onAction: function() { - CommandService.instance().execute(pluginCommandName); + void CommandService.instance().execute(pluginCommandName); }, }); } @@ -708,7 +708,7 @@ const TinyMCE = (props: NoteBodyEditorProps, ref: any) => { setEditor(editors[0]); }; - loadEditor(); + void loadEditor(); }, [scriptLoaded]); // ----------------------------------------------------------------------------------------- @@ -832,7 +832,7 @@ const TinyMCE = (props: NoteBodyEditorProps, ref: any) => { dispatchDidUpdate(editor); }; - loadContent(); + void loadContent(); return () => { cancelled = true; @@ -914,7 +914,7 @@ const TinyMCE = (props: NoteBodyEditorProps, ref: any) => { // the note. useEffect(() => { return () => { - execOnChangeEvent(); + void execOnChangeEvent(); }; }, []); @@ -942,7 +942,7 @@ const TinyMCE = (props: NoteBodyEditorProps, ref: any) => { onChangeHandlerTimeoutRef.current = shim.setTimeout(async () => { onChangeHandlerTimeoutRef.current = null; - execOnChangeEvent(); + void execOnChangeEvent(); }, 1000); } diff --git a/packages/app-desktop/gui/NoteEditor/NoteEditor.tsx b/packages/app-desktop/gui/NoteEditor/NoteEditor.tsx index f384b6c153..0996d6b73c 100644 --- a/packages/app-desktop/gui/NoteEditor/NoteEditor.tsx +++ b/packages/app-desktop/gui/NoteEditor/NoteEditor.tsx @@ -113,7 +113,7 @@ function NoteEditor(props: NoteEditorProps) { return { ...prev, user_updated_time: savedNote.user_updated_time }; }); - ExternalEditWatcher.instance().updateNoteFile(savedNote); + void ExternalEditWatcher.instance().updateNoteFile(savedNote); props.dispatch({ type: 'EDITOR_NOTE_STATUS_REMOVE', @@ -141,7 +141,7 @@ function NoteEditor(props: NoteEditorProps) { } async function saveNoteAndWait(formNote: FormNote) { - saveNoteIfWillChange(formNote); + await saveNoteIfWillChange(formNote); return formNote.saveActionQueue.waitForAllDone(); } @@ -184,7 +184,7 @@ function NoteEditor(props: NoteEditorProps) { value: props.selectedNoteHash ? props.selectedNoteHash : props.lastEditorScrollPercents[props.noteId] || 0, }); - ResourceEditWatcher.instance().stopWatchingAll(); + void ResourceEditWatcher.instance().stopWatchingAll(); }, [formNote.id, previousNoteId]); const onFieldChange = useCallback((field: string, value: any, changeId = 0) => { @@ -365,7 +365,7 @@ function NoteEditor(props: NoteEditorProps) { function renderTagBar() { const theme = themeStyle(props.themeId); const noteIds = [formNote.id]; - const instructions = { CommandService.instance().execute('setTags', noteIds); }} style={{ ...theme.clickableTextStyle, whiteSpace: 'nowrap' }}>Click to add tags...; + const instructions = { void CommandService.instance().execute('setTags', noteIds); }} style={{ ...theme.clickableTextStyle, whiteSpace: 'nowrap' }}>Click to add tags...; const tagList = props.selectedNoteTags.length ? : null; return ( diff --git a/packages/app-desktop/gui/NoteEditor/NoteTitle/NoteTitleBar.tsx b/packages/app-desktop/gui/NoteEditor/NoteTitle/NoteTitleBar.tsx index 7549e1dc88..eb50fefd3b 100644 --- a/packages/app-desktop/gui/NoteEditor/NoteTitle/NoteTitleBar.tsx +++ b/packages/app-desktop/gui/NoteEditor/NoteTitle/NoteTitleBar.tsx @@ -82,9 +82,9 @@ export default function NoteTitleBar(props: Props) { event.preventDefault(); if (event.shiftKey) { - CommandService.instance().execute('focusElement', 'noteList'); + void CommandService.instance().execute('focusElement', 'noteList'); } else { - CommandService.instance().execute('focusElement', 'noteBody'); + void CommandService.instance().execute('focusElement', 'noteBody'); } } }, []); diff --git a/packages/app-desktop/gui/NoteEditor/utils/useFolder.ts b/packages/app-desktop/gui/NoteEditor/utils/useFolder.ts index 45154304b0..db448460c7 100644 --- a/packages/app-desktop/gui/NoteEditor/utils/useFolder.ts +++ b/packages/app-desktop/gui/NoteEditor/utils/useFolder.ts @@ -18,7 +18,7 @@ export default function(dependencies: HookDependencies) { setFolder(f); } - loadFolder(); + void loadFolder(); return function() { cancelled = true; diff --git a/packages/app-desktop/gui/NoteEditor/utils/useFormNote.ts b/packages/app-desktop/gui/NoteEditor/utils/useFormNote.ts index 5db9d1e9b3..9ffc74a959 100644 --- a/packages/app-desktop/gui/NoteEditor/utils/useFormNote.ts +++ b/packages/app-desktop/gui/NoteEditor/utils/useFormNote.ts @@ -133,7 +133,7 @@ export default function useFormNote(dependencies: HookDependencies) { await initNoteState(n); }; - loadNote(); + void loadNote(); return () => { cancelled = true; @@ -183,7 +183,7 @@ export default function useFormNote(dependencies: HookDependencies) { handleAutoFocus(!!n.is_todo); } - loadNote(); + void loadNote(); return () => { cancelled = true; @@ -207,7 +207,7 @@ export default function useFormNote(dependencies: HookDependencies) { useEffect(() => { if (previousNoteId !== formNote.id) { - onResourceChange(); + void onResourceChange(); } }, [previousNoteId, formNote.id, onResourceChange]); @@ -222,7 +222,7 @@ export default function useFormNote(dependencies: HookDependencies) { }); } - runEffect(); + void runEffect(); return () => { cancelled = true; diff --git a/packages/app-desktop/gui/NoteList/NoteList.tsx b/packages/app-desktop/gui/NoteList/NoteList.tsx index 624d49d009..d1e40ba047 100644 --- a/packages/app-desktop/gui/NoteList/NoteList.tsx +++ b/packages/app-desktop/gui/NoteList/NoteList.tsx @@ -389,9 +389,9 @@ class NoteListComponent extends React.Component { event.preventDefault(); if (event.shiftKey) { - CommandService.instance().execute('focusElement', 'sideBar'); + void CommandService.instance().execute('focusElement', 'sideBar'); } else { - CommandService.instance().execute('focusElement', 'noteTitle'); + void CommandService.instance().execute('focusElement', 'noteTitle'); } } diff --git a/packages/app-desktop/gui/NoteListControls/NoteListControls.tsx b/packages/app-desktop/gui/NoteListControls/NoteListControls.tsx index f72fbeffcf..eb928c71c4 100644 --- a/packages/app-desktop/gui/NoteListControls/NoteListControls.tsx +++ b/packages/app-desktop/gui/NoteListControls/NoteListControls.tsx @@ -41,11 +41,11 @@ export default function NoteListControls(props: Props) { }, []); function onNewTodoButtonClick() { - CommandService.instance().execute('newTodo'); + void CommandService.instance().execute('newTodo'); } function onNewNoteButtonClick() { - CommandService.instance().execute('newNote'); + void CommandService.instance().execute('newNote'); } function renderNewNoteButtons() { diff --git a/packages/app-desktop/gui/ResourceScreen.tsx b/packages/app-desktop/gui/ResourceScreen.tsx index e807a722ab..8234c04f08 100644 --- a/packages/app-desktop/gui/ResourceScreen.tsx +++ b/packages/app-desktop/gui/ResourceScreen.tsx @@ -161,7 +161,7 @@ class ResourceScreenComponent extends React.Component { } componentDidMount() { - this.reloadResources(this.state.sorting); + void this.reloadResources(this.state.sorting); } onResourceDelete(resource: InnerResource) { @@ -177,7 +177,7 @@ class ResourceScreenComponent extends React.Component { bridge().showErrorMessageBox(error.message); }) .finally(() => { - this.reloadResources(this.state.sorting); + void this.reloadResources(this.state.sorting); }); } @@ -200,7 +200,7 @@ class ResourceScreenComponent extends React.Component { }; } this.setState({ sorting: newSorting }); - this.reloadResources(newSorting); + void this.reloadResources(newSorting); } render() { diff --git a/packages/app-desktop/gui/SearchBar/SearchBar.tsx b/packages/app-desktop/gui/SearchBar/SearchBar.tsx index db2a0d782d..ceebde10eb 100644 --- a/packages/app-desktop/gui/SearchBar/SearchBar.tsx +++ b/packages/app-desktop/gui/SearchBar/SearchBar.tsx @@ -103,17 +103,17 @@ function SearchBar(props: Props) { const onKeyDown = useCallback((event: any) => { if (event.key === 'Escape') { if (document.activeElement) (document.activeElement as any).blur(); - onExitSearch(); + void onExitSearch(); } }, [onExitSearch]); const onSearchButtonClick = useCallback(() => { - onExitSearch(); + void onExitSearch(); }, [onExitSearch]); useEffect(() => { if (props.notesParentType !== 'Search') { - onExitSearch(false); + void onExitSearch(false); } }, [props.notesParentType, onExitSearch]); diff --git a/packages/app-desktop/gui/ShareNoteDialog.tsx b/packages/app-desktop/gui/ShareNoteDialog.tsx index 352430f731..13fa92952e 100644 --- a/packages/app-desktop/gui/ShareNoteDialog.tsx +++ b/packages/app-desktop/gui/ShareNoteDialog.tsx @@ -79,7 +79,7 @@ export default function ShareNoteDialog(props: ShareNoteDialogProps) { setNotes(result); } - fetchNotes(); + void fetchNotes(); }, [props.noteIds]); const appApi = async () => { diff --git a/packages/app-desktop/gui/SideBar/SideBar.tsx b/packages/app-desktop/gui/SideBar/SideBar.tsx index 4d5f580507..1df4459bd2 100644 --- a/packages/app-desktop/gui/SideBar/SideBar.tsx +++ b/packages/app-desktop/gui/SideBar/SideBar.tsx @@ -510,9 +510,9 @@ class SideBarComponent extends React.Component { event.preventDefault(); if (event.shiftKey) { - CommandService.instance().execute('focusElement', 'noteBody'); + void CommandService.instance().execute('focusElement', 'noteBody'); } else { - CommandService.instance().execute('focusElement', 'noteList'); + void CommandService.instance().execute('focusElement', 'noteList'); } } @@ -559,14 +559,14 @@ class SideBarComponent extends React.Component { iconAnimation={iconAnimation} title={label} onClick={() => { - CommandService.instance().execute('synchronize', type !== 'sync'); + void CommandService.instance().execute('synchronize', type !== 'sync'); }} /> ); } onAddFolderButtonClick() { - CommandService.instance().execute('newFolder'); + void CommandService.instance().execute('newFolder'); } // componentDidUpdate(prevProps:any, prevState:any) { diff --git a/packages/app-desktop/gui/StatusScreen/StatusScreen.tsx b/packages/app-desktop/gui/StatusScreen/StatusScreen.tsx index f0e75d4dca..ef2cb00193 100644 --- a/packages/app-desktop/gui/StatusScreen/StatusScreen.tsx +++ b/packages/app-desktop/gui/StatusScreen/StatusScreen.tsx @@ -41,7 +41,7 @@ function StatusScreen(props: Props) { } useEffect(() => { - resfreshScreen(); + void resfreshScreen(); }, []); const theme = themeStyle(props.themeId); @@ -91,7 +91,7 @@ function StatusScreen(props: Props) { if (item.canRetry) { const onClick = async () => { await item.retryHandler(); - resfreshScreen(); + void resfreshScreen(); }; retryLink = ( diff --git a/packages/app-desktop/plugins/GotoAnything.tsx b/packages/app-desktop/plugins/GotoAnything.tsx index 82dd87385f..589b43bcc4 100644 --- a/packages/app-desktop/plugins/GotoAnything.tsx +++ b/packages/app-desktop/plugins/GotoAnything.tsx @@ -381,7 +381,7 @@ class Dialog extends React.PureComponent { }); if (item.type === BaseModel.TYPE_COMMAND) { - CommandService.instance().execute(item.id); + void CommandService.instance().execute(item.id); return; } @@ -423,7 +423,7 @@ class Dialog extends React.PureComponent { const parentId = event.currentTarget.getAttribute('data-parent-id'); const itemType = Number(event.currentTarget.getAttribute('data-type')); - this.gotoItem({ + void this.gotoItem({ id: itemId, parent_id: parentId, type: itemType, @@ -496,7 +496,7 @@ class Dialog extends React.PureComponent { const item = this.selectedItem(); if (!item) return; - this.gotoItem(item); + void this.gotoItem(item); } } diff --git a/packages/app-desktop/services/plugins/hooks/useThemeCss.ts b/packages/app-desktop/services/plugins/hooks/useThemeCss.ts index 7d78f01992..4e2c11af59 100644 --- a/packages/app-desktop/services/plugins/hooks/useThemeCss.ts +++ b/packages/app-desktop/services/plugins/hooks/useThemeCss.ts @@ -49,7 +49,7 @@ export default function useThemeCss(dep: HookDependencies) { setCssFilePath(filePath); } - createThemeStyleSheet(); + void createThemeStyleSheet(); return () => { cancelled = true; diff --git a/packages/app-mobile/components/NoteBodyViewer/hooks/useSource.ts b/packages/app-mobile/components/NoteBodyViewer/hooks/useSource.ts index a44c42909f..13a978cc83 100644 --- a/packages/app-mobile/components/NoteBodyViewer/hooks/useSource.ts +++ b/packages/app-mobile/components/NoteBodyViewer/hooks/useSource.ts @@ -186,7 +186,7 @@ export default function useSource(noteBody: string, noteMarkupLanguage: number, setSource(undefined); setInjectedJs([]); } else { - renderNote(); + void renderNote(); } return () => { diff --git a/packages/app-mobile/components/screens/Note.tsx b/packages/app-mobile/components/screens/Note.tsx index 8141db04d1..652dc4fc8b 100644 --- a/packages/app-mobile/components/screens/Note.tsx +++ b/packages/app-mobile/components/screens/Note.tsx @@ -259,11 +259,11 @@ class NoteScreenComponent extends BaseScreenComponent { } screenHeader_undoButtonPress() { - this.undoRedo('undo'); + void this.undoRedo('undo'); } screenHeader_redoButtonPress() { - this.undoRedo('redo'); + void this.undoRedo('redo'); } styles() { @@ -404,7 +404,7 @@ class NoteScreenComponent extends BaseScreenComponent { // Although it is async, we don't wait for the answer so that if permission // has already been granted, it doesn't slow down opening the note. If it hasn't // been granted, the popup will open anyway. - this.requestGeoLocationPermissions(); + void this.requestGeoLocationPermissions(); } onMarkForDownload(event: any) { @@ -703,7 +703,7 @@ class NoteScreenComponent extends BaseScreenComponent { } cameraView_onPhoto(data: any) { - this.attachFile( + void this.attachFile( { uri: data.uri, didCancel: false, @@ -810,14 +810,14 @@ class NoteScreenComponent extends BaseScreenComponent { output.push({ title: _('View on map'), onPress: () => { - this.showOnMap_onPress(); + void this.showOnMap_onPress(); }, }); if (note.source_url) { output.push({ title: _('Go to source URL'), onPress: () => { - this.showSource_onPress(); + void this.showSource_onPress(); }, }); } @@ -866,8 +866,8 @@ class NoteScreenComponent extends BaseScreenComponent { const buttonId = await dialogs.pop(this, _('Choose an option'), buttons); if (buttonId === 'takePhoto') this.takePhoto_onPress(); - if (buttonId === 'attachFile') this.attachFile_onPress(); - if (buttonId === 'attachPhoto') this.attachPhoto_onPress(); + if (buttonId === 'attachFile') void this.attachFile_onPress(); + if (buttonId === 'attachPhoto') void this.attachPhoto_onPress(); }, }); } @@ -884,7 +884,7 @@ class NoteScreenComponent extends BaseScreenComponent { output.push({ title: _('Share'), onPress: () => { - this.share_onPress(); + void this.share_onPress(); }, }); if (isSaved) { @@ -918,7 +918,7 @@ class NoteScreenComponent extends BaseScreenComponent { output.push({ title: _('Delete'), onPress: () => { - this.deleteNote_onPress(); + void this.deleteNote_onPress(); }, }); @@ -1010,7 +1010,7 @@ class NoteScreenComponent extends BaseScreenComponent { } onBodyViewerCheckboxChange(newBody: string) { - this.saveOneProperty('body', newBody); + void this.saveOneProperty('body', newBody); } render() { diff --git a/packages/lib/AsyncActionQueue.ts b/packages/lib/AsyncActionQueue.ts index 5c62f2627e..f36acbb54a 100644 --- a/packages/lib/AsyncActionQueue.ts +++ b/packages/lib/AsyncActionQueue.ts @@ -54,7 +54,7 @@ export default class AsyncActionQueue { this.scheduleProcessingIID_ = shim.setTimeout(() => { this.scheduleProcessingIID_ = null; - this.processQueue(); + void this.processQueue(); }, interval); } diff --git a/packages/lib/Synchronizer.ts b/packages/lib/Synchronizer.ts index da39288796..af64950ea0 100644 --- a/packages/lib/Synchronizer.ts +++ b/packages/lib/Synchronizer.ts @@ -354,7 +354,7 @@ export default class Synchronizer { this.lockHandler().startAutoLockRefresh(syncLock, (error: any) => { this.logger().warn('Could not refresh lock - cancelling sync. Error was:', error); this.syncTargetIsLocked_ = true; - this.cancel(); + void this.cancel(); }); // ======================================================================== diff --git a/packages/lib/services/AlarmServiceDriverNode.ts b/packages/lib/services/AlarmServiceDriverNode.ts index 597c15c192..906daf97b8 100644 --- a/packages/lib/services/AlarmServiceDriverNode.ts +++ b/packages/lib/services/AlarmServiceDriverNode.ts @@ -37,13 +37,13 @@ export default class AlarmServiceDriverNode { return id in this.notifications_; } - async clearNotification(id: number) { + clearNotification(id: number) { if (!this.notificationIsSet(id)) return; shim.clearTimeout(this.notifications_[id].timeoutId); delete this.notifications_[id]; } - async scheduleNotification(notification: Notification) { + scheduleNotification(notification: Notification) { const now = Date.now(); const interval = notification.date.getTime() - now; if (interval < 0) return; diff --git a/packages/lib/services/CommandService.ts b/packages/lib/services/CommandService.ts index 664a26ebcb..a96354db6c 100644 --- a/packages/lib/services/CommandService.ts +++ b/packages/lib/services/CommandService.ts @@ -232,7 +232,7 @@ export default class CommandService extends BaseService { public scheduleExecute(commandName: string, args: any) { shim.setTimeout(() => { - this.execute(commandName, args); + void this.execute(commandName, args); }, 10); } diff --git a/packages/lib/services/ExternalEditWatcher.ts b/packages/lib/services/ExternalEditWatcher.ts index 21e0285ae6..d5292742af 100644 --- a/packages/lib/services/ExternalEditWatcher.ts +++ b/packages/lib/services/ExternalEditWatcher.ts @@ -100,7 +100,7 @@ export default class ExternalEditWatcher { if (!note) { this.logger().warn(`ExternalEditWatcher: Watched note has been deleted: ${id}`); - this.stopWatching(id); + void this.stopWatching(id); return; } @@ -339,7 +339,7 @@ export default class ExternalEditWatcher { // avoid update loops. We only want to listen to file changes made by the user. this.skipNextChangeEvent_[note.id] = true; - this.writeNoteToFile_(note); + await this.writeNoteToFile_(note); } async writeNoteToFile_(note: NoteEntity) { diff --git a/packages/lib/services/ResourceEditWatcher/index.ts b/packages/lib/services/ResourceEditWatcher/index.ts index a97fda2fd3..3993072e64 100644 --- a/packages/lib/services/ResourceEditWatcher/index.ts +++ b/packages/lib/services/ResourceEditWatcher/index.ts @@ -157,7 +157,7 @@ export default class ResourceEditWatcher { if (!this.watcher_) { this.watcher_ = this.chokidar_.watch(fileToWatch); - this.watcher_.on('all', async (event: any, path: string) => { + this.watcher_.on('all', (event: any, path: string) => { path = toSystemSlashes(path, 'linux'); this.logger().info(`ResourceEditWatcher: Event: ${event}: ${path}`); @@ -170,7 +170,7 @@ export default class ResourceEditWatcher { // See: https://github.com/laurent22/joplin/issues/710#issuecomment-420997167 // this.watcher_.unwatch(path); } else if (event === 'change') { - handleChangeEvent(path); + void handleChangeEvent(path); } else if (event === 'error') { this.logger().error('ResourceEditWatcher: error'); } @@ -185,14 +185,14 @@ export default class ResourceEditWatcher { // https://github.com/laurent22/joplin/issues/3407 // // @ts-ignore Leave unused path variable - this.watcher_.on('raw', async (event: string, path: string, options: any) => { + this.watcher_.on('raw', (event: string, path: string, options: any) => { const watchedPath = toSystemSlashes(options.watchedPath, 'linux'); this.logger().debug(`ResourceEditWatcher: Raw event: ${event}: ${watchedPath}`); if (event === 'rename') { this.watcher_.unwatch(watchedPath); this.watcher_.add(watchedPath); - handleChangeEvent(watchedPath); + void handleChangeEvent(watchedPath); } }); } else { diff --git a/packages/lib/services/ResourceService.ts b/packages/lib/services/ResourceService.ts index c6c182533e..5782e6f066 100644 --- a/packages/lib/services/ResourceService.ts +++ b/packages/lib/services/ResourceService.ts @@ -154,11 +154,11 @@ export default class ResourceService extends BaseService { const service = this.instance(); service.maintenanceTimer1_ = shim.setTimeout(() => { - service.maintenance(); + void service.maintenance(); }, 1000 * 30); service.maintenanceTimer2_ = shim.setInterval(() => { - service.maintenance(); + void service.maintenance(); }, 1000 * 60 * 60 * 4); } diff --git a/packages/lib/services/commands/ToolbarButtonUtils.ts b/packages/lib/services/commands/ToolbarButtonUtils.ts index b0db6810f7..016ffc9eda 100644 --- a/packages/lib/services/commands/ToolbarButtonUtils.ts +++ b/packages/lib/services/commands/ToolbarButtonUtils.ts @@ -52,8 +52,8 @@ export default class ToolbarButtonUtils { tooltip: this.service.label(commandName), iconName: command.declaration.iconName, enabled: newEnabled, - onClick: async () => { - this.service.execute(commandName); + onClick: () => { + void this.service.execute(commandName); }, title: newTitle, }; diff --git a/packages/lib/services/interop/InteropService_Importer_Md.ts b/packages/lib/services/interop/InteropService_Importer_Md.ts index b960acfbce..ef007974e3 100644 --- a/packages/lib/services/interop/InteropService_Importer_Md.ts +++ b/packages/lib/services/interop/InteropService_Importer_Md.ts @@ -27,7 +27,7 @@ export default class InteropService_Importer_Md extends InteropService_Importer_ parentFolderId = this.options_.destinationFolder.id; } - this.importDirectory(sourcePath, parentFolderId); + await this.importDirectory(sourcePath, parentFolderId); } else { if (!this.options_.destinationFolder) throw new Error(_('Please specify the notebook where the notes should be imported to.')); parentFolderId = this.options_.destinationFolder.id; @@ -52,9 +52,9 @@ export default class InteropService_Importer_Md extends InteropService_Importer_ if (stat.isDirectory()) { const folderTitle = await Folder.findUniqueItemTitle(basename(stat.path)); const folder = await Folder.save({ title: folderTitle, parent_id: parentFolderId }); - this.importDirectory(`${dirPath}/${basename(stat.path)}`, folder.id); + await this.importDirectory(`${dirPath}/${basename(stat.path)}`, folder.id); } else if (supportedFileExtension.indexOf(fileExtension(stat.path).toLowerCase()) >= 0) { - this.importFile(`${dirPath}/${stat.path}`, parentFolderId); + await this.importFile(`${dirPath}/${stat.path}`, parentFolderId); } } } diff --git a/packages/lib/services/plugins/WebviewController.ts b/packages/lib/services/plugins/WebviewController.ts index 326802c42c..19d866afbd 100644 --- a/packages/lib/services/plugins/WebviewController.ts +++ b/packages/lib/services/plugins/WebviewController.ts @@ -103,7 +103,7 @@ export default class WebviewController extends ViewController { }); } - public async close() { + public close() { this.setStoreProp('opened', false); } diff --git a/packages/lib/services/plugins/api/JoplinPlugins.ts b/packages/lib/services/plugins/api/JoplinPlugins.ts index be533e5dea..bca52124e0 100644 --- a/packages/lib/services/plugins/api/JoplinPlugins.ts +++ b/packages/lib/services/plugins/api/JoplinPlugins.ts @@ -36,7 +36,7 @@ export default class JoplinPlugins { // We don't use `await` when calling onStart because the plugin might be awaiting // in that call too (for example, when opening a dialog on startup) so we don't // want to get stuck here. - script.onStart({}).catch((error: any) => { + void script.onStart({}).catch((error: any) => { // For some reason, error thrown from the executed script do not have the type "Error" // but are instead plain object. So recreate the Error object here so that it can // be handled correctly by loggers, etc. diff --git a/packages/lib/services/spellChecker/SpellCheckerService.ts b/packages/lib/services/spellChecker/SpellCheckerService.ts index bd0a415839..8d12a8add0 100644 --- a/packages/lib/services/spellChecker/SpellCheckerService.ts +++ b/packages/lib/services/spellChecker/SpellCheckerService.ts @@ -66,7 +66,7 @@ export default class SpellCheckerService { public setLanguage(language: string) { Setting.setValue('spellChecker.language', language); this.applyStateToDriver(); - this.addLatestSelectedLanguage(language); + void this.addLatestSelectedLanguage(language); } public get language(): string { @@ -98,7 +98,7 @@ export default class SpellCheckerService { output.push({ label: suggestion, click: () => { - CommandService.instance().execute('replaceSelection', suggestion); + void CommandService.instance().execute('replaceSelection', suggestion); }, }); } @@ -115,7 +115,7 @@ export default class SpellCheckerService { output.push({ label: _('Add to dictionary'), click: () => { - this.addToDictionary(this.language, misspelledWord); + void this.addToDictionary(this.language, misspelledWord); }, }); diff --git a/packages/lib/services/synchronizer/gui/useSyncTargetUpgrade.ts b/packages/lib/services/synchronizer/gui/useSyncTargetUpgrade.ts index 5404a69f7e..9d840235f4 100644 --- a/packages/lib/services/synchronizer/gui/useSyncTargetUpgrade.ts +++ b/packages/lib/services/synchronizer/gui/useSyncTargetUpgrade.ts @@ -51,7 +51,7 @@ export default function useSyncTargetUpgrade(): SyncTargetUpgradeResult { } useEffect(function() { - upgradeSyncTarget(); + void upgradeSyncTarget(); }, []); return upgradeResult; diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json new file mode 100644 index 0000000000..def7b8eff0 --- /dev/null +++ b/tsconfig.eslint.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "include": [ + "**/*.ts", + "**/*.tsx", + ], +} \ No newline at end of file