Skip to content

Commit

Permalink
fix: Enabled @typescript-eslint/return-await rule and fixed offending…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
bmingles authored Jul 22, 2024
1 parent 8b20692 commit 7875d03
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
4 changes: 4 additions & 0 deletions packages/eslint-config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
{
Expand Down
4 changes: 3 additions & 1 deletion packages/iris-grid/src/IrisGridTableModelTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/src/ClipboardUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
},
},
Expand Down
5 changes: 3 additions & 2 deletions packages/utils/src/ClipboardUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ export async function copyToClipboard(text: string): Promise<void> {
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);
Expand Down

0 comments on commit 7875d03

Please sign in to comment.