From 7875d03fdbe2dfa1c051c6dfa42cc1d9e7469afb Mon Sep 17 00:00:00 2001 From: Brian Ingles Date: Mon, 22 Jul 2024 08:42:58 -0500 Subject: [PATCH] fix: Enabled @typescript-eslint/return-await rule and fixed offending code (#2157) Enabled `@typescript-eslint/return-await` eslint rule and fixed offending code. fixes #2154 BREAKING CHANGE: Fix any try / catch blocks that return non-awaited Promises --- packages/eslint-config/index.js | 4 ++++ packages/iris-grid/src/IrisGridTableModelTemplate.ts | 4 +++- packages/utils/src/ClipboardUtils.test.ts | 4 ++-- packages/utils/src/ClipboardUtils.ts | 5 +++-- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/eslint-config/index.js b/packages/eslint-config/index.js index e29dcc2055..c0b9e98dce 100644 --- a/packages/eslint-config/index.js +++ b/packages/eslint-config/index.js @@ -96,6 +96,10 @@ module.exports = { '@typescript-eslint/default-param-last': ['error'], '@typescript-eslint/explicit-module-boundary-types': 'error', '@typescript-eslint/method-signature-style': 'error', + // `no-return-await` needs to be disabled when enabling `@typescript-eslint/return-await` + // to avoid incorrectly reporting errors + 'no-return-await': 'off', + '@typescript-eslint/return-await': 'error', }, }, { diff --git a/packages/iris-grid/src/IrisGridTableModelTemplate.ts b/packages/iris-grid/src/IrisGridTableModelTemplate.ts index 082e4bb34d..017b32e445 100644 --- a/packages/iris-grid/src/IrisGridTableModelTemplate.ts +++ b/packages/iris-grid/src/IrisGridTableModelTemplate.ts @@ -1528,7 +1528,9 @@ class IrisGridTableModelTemplate< table = await this.table.copy(); table.applyFilter([]); table.applySort([]); - return table.selectDistinct(Array.isArray(columns) ? columns : [columns]); + return await table.selectDistinct( + Array.isArray(columns) ? columns : [columns] + ); } finally { if (table != null) { table.close(); diff --git a/packages/utils/src/ClipboardUtils.test.ts b/packages/utils/src/ClipboardUtils.test.ts index e47c796170..20210cbea0 100644 --- a/packages/utils/src/ClipboardUtils.test.ts +++ b/packages/utils/src/ClipboardUtils.test.ts @@ -10,7 +10,7 @@ describe('Clipboard', () => { Object.assign(navigator, { clipboard: { // eslint-disable-next-line @typescript-eslint/no-empty-function - writeText: () => {}, + writeText: async () => {}, }, }); jest.spyOn(navigator.clipboard, 'writeText'); @@ -22,7 +22,7 @@ describe('Clipboard', () => { it('should call copyToClipboardExecCommand if writeText fails', async () => { Object.assign(navigator, { clipboard: { - writeText: () => { + writeText: async () => { throw new Error('Could not write text'); }, }, diff --git a/packages/utils/src/ClipboardUtils.ts b/packages/utils/src/ClipboardUtils.ts index e7f20a2758..096d9177ab 100644 --- a/packages/utils/src/ClipboardUtils.ts +++ b/packages/utils/src/ClipboardUtils.ts @@ -7,9 +7,10 @@ export async function copyToClipboard(text: string): Promise { const { clipboard } = navigator; if (clipboard !== undefined) { try { - return navigator.clipboard.writeText(text); + return await navigator.clipboard.writeText(text); } catch { - return copyToClipboardExecCommand(text); + // Ignore error. Fallback to `copyToClipboardExecCommand` below + // (same as when clipboard is not available). } } copyToClipboardExecCommand(text);