diff --git a/configs/.eslintrc.ts b/configs/.eslintrc.ts index bc652f2d..e05fc416 100644 --- a/configs/.eslintrc.ts +++ b/configs/.eslintrc.ts @@ -39,6 +39,7 @@ const config: ESLint.ConfigData = { count: 1, }, ], + 'require-await': 'error', '@typescript-eslint/no-unused-vars': [ 'error', { diff --git a/src/background/RemotePontoon.ts b/src/background/RemotePontoon.ts index 4c21f1a9..2379db52 100644 --- a/src/background/RemotePontoon.ts +++ b/src/background/RemotePontoon.ts @@ -68,7 +68,7 @@ export function listenToMessagesFromClients() { listenToMessagesExclusively( BackgroundClientMessageType.UPDATE_TEAMS_LIST, async () => { - return updateTeamsList(); + return await updateTeamsList(); }, ); listenToMessagesExclusively( @@ -82,7 +82,7 @@ export function listenToMessagesFromClients() { listenToMessagesExclusively( BackgroundClientMessageType.GET_TEAM_FROM_PONTOON, async () => { - return getUsersTeamFromPontoon(); + return await getUsersTeamFromPontoon(); }, ); } diff --git a/src/background/backgroundClient.ts b/src/background/backgroundClient.ts index de325f29..36bd9b4e 100644 --- a/src/background/backgroundClient.ts +++ b/src/background/backgroundClient.ts @@ -17,7 +17,7 @@ async function getTeam(): Promise<{ code: string }> { } async function getPontoonBaseUrl(): Promise { - return getOneOption('pontoon_base_url'); + return await getOneOption('pontoon_base_url'); } export async function getNotificationsUrl(): Promise { @@ -87,7 +87,7 @@ export async function reportTranslatedTextToBugzilla(text: string) { export async function notificationBellIconScriptLoaded(): Promise<{ type: BackgroundClientMessageType; }> { - return browser.runtime.sendMessage({ + return await browser.runtime.sendMessage({ type: BackgroundClientMessageType.NOTIFICATIONS_BELL_SCRIPT_LOADED, }); } diff --git a/src/background/httpClients.ts b/src/background/httpClients.ts index 8f8b5e83..fe067ba5 100644 --- a/src/background/httpClients.ts +++ b/src/background/httpClients.ts @@ -143,7 +143,7 @@ export const pontoonHttpClient = new PontoonHttpClient(); export const httpClient = { fetch: async (url: string): Promise => { - return fetch(url, { credentials: 'omit' }); + return await fetch(url, { credentials: 'omit' }); }, }; diff --git a/src/commons/webExtensionsApi/index.ts b/src/commons/webExtensionsApi/index.ts index ece7db0c..f26453f6 100644 --- a/src/commons/webExtensionsApi/index.ts +++ b/src/commons/webExtensionsApi/index.ts @@ -108,13 +108,13 @@ export function listenToStorageChange( } export async function saveToStorage(toSave: Partial) { - return browser.storage.local.set(toSave); + return await browser.storage.local.set(toSave); } export async function deleteFromStorage( ...storageKeys: K[] ) { - return browser.storage.local.remove(storageKeys); + return await browser.storage.local.remove(storageKeys); } export async function createNotification( @@ -132,7 +132,7 @@ export async function createNotification( } export async function closeNotification(notificationId: string) { - return browser.notifications.clear(notificationId); + return await browser.notifications.clear(notificationId); } export function createContextMenu( @@ -142,7 +142,7 @@ export function createContextMenu( } export async function removeContextMenu(menuItemId: number | string) { - return browser.contextMenus.remove(menuItemId); + return await browser.contextMenus.remove(menuItemId); } export function browserFamily(): BrowserFamily { @@ -154,26 +154,26 @@ export function browserFamily(): BrowserFamily { } export async function openNewTab(url: string) { - return browser.tabs.create({ url }); + return await browser.tabs.create({ url }); } export async function getAllTabs() { - return browser.tabs.query({}); + return await browser.tabs.query({}); } export async function getTabsMatching(...patterns: string[]) { - return browser.tabs.query({ url: patterns }); + return await browser.tabs.query({ url: patterns }); } export async function getTabsWithBaseUrl(baseUrl: string) { - return getTabsMatching(`${baseUrl}/*`); + return await getTabsMatching(`${baseUrl}/*`); } export async function getActiveTab(): Promise { return (await browser.tabs.query({ currentWindow: true, active: true }))[0]; } -export async function listenToTabsCompletedLoading( +export function listenToTabsCompletedLoading( listener: (tab: Tabs.Tab & { id: number }) => void, ) { browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { @@ -188,23 +188,25 @@ export function getResourceUrl(path: string) { } export async function openOptions() { - return browser.runtime.openOptionsPage(); + return await browser.runtime.openOptionsPage(); } export async function openIntro() { - return openNewTab(browser.runtime.getURL('frontend/intro.html')); + return await openNewTab(browser.runtime.getURL('frontend/intro.html')); } export async function openPrivacyPolicy() { - return openNewTab(browser.runtime.getURL('frontend/privacy-policy.html')); + return await openNewTab( + browser.runtime.getURL('frontend/privacy-policy.html'), + ); } export async function openSnakeGame() { - return openNewTab(browser.runtime.getURL('frontend/snake-game.html')); + return await openNewTab(browser.runtime.getURL('frontend/snake-game.html')); } export async function openToolbarButtonPopup() { - return browser.browserAction.openPopup(); + return await browser.browserAction.openPopup(); } export function supportsAddressBar(): boolean { @@ -241,18 +243,20 @@ export function supportsContainers(): boolean { export async function getAllContainers() { if (supportsContainers()) { - return browser.contextualIdentities.query({}); + return await browser.contextualIdentities.query({}); } else { return []; } } export async function requestPermissionForPontoon(pontoonBaseUrl: string) { - return browser.permissions.request({ origins: [`${pontoonBaseUrl}/*`] }); + return await browser.permissions.request({ + origins: [`${pontoonBaseUrl}/*`], + }); } export async function registerScriptForBaseUrl(baseUrl: string, file: string) { - return browser.contentScripts.register({ + return await browser.contentScripts.register({ js: [{ file }], matches: [`${baseUrl}/*`], runAt: 'document_end', // Corresponds to interactive. The DOM has finished loading, but resources such as scripts and images may still be loading. @@ -260,7 +264,7 @@ export async function registerScriptForBaseUrl(baseUrl: string, file: string) { } export async function executeScript(tabId: number, file: string) { - return browser.tabs.executeScript(tabId, { file }); + return await browser.tabs.executeScript(tabId, { file }); } export function callWithInterval( diff --git a/src/commons/webExtensionsApi/spec.ts b/src/commons/webExtensionsApi/spec.ts index b5cb47c2..cf02ea38 100644 --- a/src/commons/webExtensionsApi/spec.ts +++ b/src/commons/webExtensionsApi/spec.ts @@ -284,7 +284,7 @@ describe('webExtensionsApi', () => { .expect(42, { file: 'foo/bar.js' }) .andResolve([]); - executeScript(42, 'foo/bar.js'); + await executeScript(42, 'foo/bar.js'); }); it('callWithInterval', () => { diff --git a/src/content-scripts/pontoon-addon-promotion/content-script.ts b/src/content-scripts/pontoon-addon-promotion/content-script.ts index 152419e3..47dd64ec 100644 --- a/src/content-scripts/pontoon-addon-promotion/content-script.ts +++ b/src/content-scripts/pontoon-addon-promotion/content-script.ts @@ -8,7 +8,7 @@ function injectScript(src: string) { document.head.prepend(script); } -async function postMessage(): Promise { +function postMessage() { window.postMessage( { _type: 'PontoonAddonInfo', diff --git a/src/frontend/index.spec.ts b/src/frontend/index.spec.ts index 20e86ae5..f7ff1fc7 100644 --- a/src/frontend/index.spec.ts +++ b/src/frontend/index.spec.ts @@ -50,7 +50,7 @@ describe('address bar', () => { const root = prepareRoot('address-bar-root'); await act(async () => { - await index(); + index(); await flushPromises(); }); @@ -63,7 +63,7 @@ describe('intro', () => { const root = prepareRoot('intro-root'); await act(async () => { - await index(); + index(); await flushPromises(); }); @@ -76,7 +76,7 @@ describe('options', () => { const root = prepareRoot('options-root'); await act(async () => { - await index(); + index(); await flushPromises(); }); @@ -89,7 +89,7 @@ describe('privacy policy', () => { const root = prepareRoot('privacy-policy-root'); await act(async () => { - await index(); + index(); await flushPromises(); }); @@ -102,7 +102,7 @@ describe('snake game', () => { const root = prepareRoot('snake-game-root'); await act(async () => { - await index(); + index(); await flushPromises(); }); @@ -130,7 +130,7 @@ describe('toolbar button', () => { const root = prepareRoot('toolbar-button-root'); await act(async () => { - await index(); + index(); await flushPromises(); }); diff --git a/src/frontend/index.tsx b/src/frontend/index.tsx index abf8bd2d..4465a72d 100644 --- a/src/frontend/index.tsx +++ b/src/frontend/index.tsx @@ -21,7 +21,7 @@ function renderToolbarButtonApp(rootElement: HTMLElement) { renderRoot(rootElement, ); } -export async function render(): Promise { +export function render() { const addressBarRoot = document.getElementById('address-bar-root'); const introRoot = document.getElementById('intro-root'); const optionsRoot = document.getElementById('options-root'); diff --git a/src/frontend/toolbar-button/NotificationsListItem/index.tsx b/src/frontend/toolbar-button/NotificationsListItem/index.tsx index 6030e995..031cc1fa 100644 --- a/src/frontend/toolbar-button/NotificationsListItem/index.tsx +++ b/src/frontend/toolbar-button/NotificationsListItem/index.tsx @@ -138,7 +138,7 @@ function wrapLinks(pontoonBaseUrl: string): HTMLReactParserOptions['replace'] { async function openTeamProject(projectUrl: string): Promise { const teamProjectUrl = await getTeamProjectUrl(projectUrl); - openNewPontoonTab(teamProjectUrl); + await openNewPontoonTab(teamProjectUrl); window.close(); }