diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/background.ts | 2 | ||||
-rw-r--r-- | source/features/follow-file-renames.tsx | 4 | ||||
-rw-r--r-- | source/features/forked-to.tsx | 2 | ||||
-rw-r--r-- | source/features/hide-useless-comments.tsx | 2 | ||||
-rw-r--r-- | source/features/link-to-file-in-file-history.tsx | 3 | ||||
-rw-r--r-- | source/features/linkify-urls-in-code.tsx | 2 | ||||
-rw-r--r-- | source/features/minimize-upload-bar.tsx | 2 | ||||
-rw-r--r-- | source/features/pr-branch-auto-delete.tsx | 2 | ||||
-rw-r--r-- | source/features/revert-file.tsx | 11 | ||||
-rw-r--r-- | source/features/show-names.tsx | 2 | ||||
-rw-r--r-- | source/features/sticky-discussion-sidebar.tsx | 2 | ||||
-rw-r--r-- | source/features/submit-review-as-single-comment.tsx | 2 | ||||
-rw-r--r-- | source/features/tags-dropdown.tsx | 2 | ||||
-rw-r--r-- | source/features/view-markdown-source.tsx | 4 | ||||
-rw-r--r-- | source/globals.d.ts | 19 | ||||
-rw-r--r-- | source/libs/features.tsx | 4 | ||||
-rw-r--r-- | source/libs/get-default-branch.ts | 6 | ||||
-rw-r--r-- | source/libs/get-text-nodes.ts | 2 | ||||
-rw-r--r-- | source/libs/on-new-comments.ts | 1 | ||||
-rw-r--r-- | source/libs/post-form.ts | 2 | ||||
-rw-r--r-- | source/options-storage.ts | 4 | ||||
-rw-r--r-- | source/options.tsx | 2 |
22 files changed, 37 insertions, 45 deletions
diff --git a/source/background.ts b/source/background.ts index 59876081..cb3f1a5e 100644 --- a/source/background.ts +++ b/source/background.ts @@ -2,7 +2,7 @@ import 'webext-dynamic-content-scripts'; import addDomainPermissionToggle from 'webext-domain-permission-toggle'; import './options-storage'; -browser.runtime.onMessage.addListener(async (message, {tab}) => { +browser.runtime.onMessage.addListener((message, {tab}) => { if (message && Array.isArray(message.openUrls)) { for (const [i, url] of (message.openUrls as string[]).entries()) { browser.tabs.create({ diff --git a/source/features/follow-file-renames.tsx b/source/features/follow-file-renames.tsx index 0657f386..0f50ccf3 100644 --- a/source/features/follow-file-renames.tsx +++ b/source/features/follow-file-renames.tsx @@ -17,10 +17,10 @@ async function findRename( ): Promise<File[]> { // API v4 doesn't support it: https://github.community/t5/GitHub-API-Development-and/What-is-the-corresponding-object-in-GraphQL-API-v4-for-patch/m-p/14502?collapse_discussion=true&filter=location&location=board:api&q=files%20changed%20commit&search_type=thread const {files} = await api.v3(`repos/${user}/${repo}/commits/${lastCommitOnPage}`); - return files as Promise<File[]>; + return files as File[]; } -async function init(): Promise<false | void> { +function init(): false | void { const disabledPagination = select.all('.paginate-container [disabled], .paginate-container .disabled'); if (disabledPagination.length === 0) { diff --git a/source/features/forked-to.tsx b/source/features/forked-to.tsx index 867a9467..33e44e29 100644 --- a/source/features/forked-to.tsx +++ b/source/features/forked-to.tsx @@ -17,7 +17,7 @@ async function save(forks: string[]): Promise<void> { return cache.set(getCacheKey(), forks, 10); } -async function saveAllForks(): Promise<void> { +function saveAllForks(): void { const forks = select .all('details-dialog[src*="/fork"] .octicon-repo-forked') .map(({nextSibling}) => nextSibling!.textContent!.trim()); diff --git a/source/features/hide-useless-comments.tsx b/source/features/hide-useless-comments.tsx index 98accf05..df40a45f 100644 --- a/source/features/hide-useless-comments.tsx +++ b/source/features/hide-useless-comments.tsx @@ -17,7 +17,7 @@ function init(): void { } // Ensure that they're not by VIPs (owner, collaborators, etc) - const comment = commentText.closest('.js-timeline-item') as HTMLElement; + const comment = commentText.closest<HTMLElement>('.js-timeline-item')!; if (select.exists('.timeline-comment-label', comment)) { continue; } diff --git a/source/features/link-to-file-in-file-history.tsx b/source/features/link-to-file-in-file-history.tsx index 69591b1d..e754a40d 100644 --- a/source/features/link-to-file-in-file-history.tsx +++ b/source/features/link-to-file-in-file-history.tsx @@ -25,8 +25,7 @@ function init(): void | false { </a> ); - // TODO: drop `as` after https://github.com/Microsoft/TSJS-lib-generator/pull/697 - (rootLink.closest('.commit-links-cell') as HTMLElement).style.width = 'auto'; + rootLink.closest<HTMLElement>('.commit-links-cell')!.style.width = 'auto'; groupSiblings(rootLink); } diff --git a/source/features/linkify-urls-in-code.tsx b/source/features/linkify-urls-in-code.tsx index 066bfef3..9e9ca6a1 100644 --- a/source/features/linkify-urls-in-code.tsx +++ b/source/features/linkify-urls-in-code.tsx @@ -12,7 +12,7 @@ export function linkifyIssuesInDom(element: Element): void { } // Enable native issue title fetch - for (const link of (linkified.children as HTMLCollectionOf<HTMLAnchorElement>)) { + for (const link of linkified.children as HTMLCollectionOf<HTMLAnchorElement>) { const issue = link.href.split('/').pop(); link.setAttribute('class', 'issue-link js-issue-link tooltipped tooltipped-ne'); link.setAttribute('data-error-text', 'Failed to load issue title'); diff --git a/source/features/minimize-upload-bar.tsx b/source/features/minimize-upload-bar.tsx index a325388d..db0d3ceb 100644 --- a/source/features/minimize-upload-bar.tsx +++ b/source/features/minimize-upload-bar.tsx @@ -5,7 +5,7 @@ import delegate, {DelegateEvent} from 'delegate-it'; import features from '../libs/features'; import * as icons from '../libs/icons'; -async function addButton(): Promise<void> { +function addButton(): void { for (const toolbarButton of select.all('md-ref')) { toolbarButton.after( <button type="button" className="toolbar-item tooltipped tooltipped-n rgh-upload-btn" aria-label="Attach files"> diff --git a/source/features/pr-branch-auto-delete.tsx b/source/features/pr-branch-auto-delete.tsx index 9282b6ba..acfd28fa 100644 --- a/source/features/pr-branch-auto-delete.tsx +++ b/source/features/pr-branch-auto-delete.tsx @@ -4,7 +4,7 @@ import features from '../libs/features'; import observeEl from '../libs/simplified-element-observer'; function init(): void { - const [subscription] = delegate('#discussion_bucket', '.js-merge-commit-button', 'click', async () => { + const [subscription] = delegate('#discussion_bucket', '.js-merge-commit-button', 'click', () => { subscription.destroy(); observeEl('.discussion-timeline-actions', (_, observer) => { diff --git a/source/features/revert-file.tsx b/source/features/revert-file.tsx index 0c17ca88..347fad5c 100644 --- a/source/features/revert-file.tsx +++ b/source/features/revert-file.tsx @@ -30,7 +30,7 @@ const getBaseRef = onetime(async (): Promise<string> => { }); async function getFile(menuItem: Element): Promise<{isTruncated: boolean; text: string}> { - const filePath = (menuItem.closest('[data-path]') as HTMLElement).dataset.path!; + const filePath = menuItem.closest<HTMLElement>('[data-path]')!.dataset.path!; const {repository} = await api.v4(` repository(${getRepoGQL()}) { file: object(expression: "${await getBaseRef()}:${filePath}") { @@ -45,8 +45,6 @@ async function getFile(menuItem: Element): Promise<{isTruncated: boolean; text: } async function deleteFile(menuItem: Element): Promise<void> { - // The `a` selector skips the broken Delete link on some pages. GitHub's bug. - // TODO: where? What happens when it's not found? menuItem.textContent = 'Deleting…'; const deleteFileLink = select<HTMLAnchorElement>('a[aria-label^="Delete this"]', menuItem.parentElement!)!; @@ -77,7 +75,8 @@ async function commitFileContent(menuItem: Element, content: string): Promise<vo async function handleRevertFileClick(event: React.MouseEvent<HTMLButtonElement>): Promise<void> { const menuItem = event.currentTarget; // Allow only one click - menuItem.removeEventListener('click', handleRevertFileClick as any); // TODO: change JSX event types to be plain browser events + // TODO: change JSX event types to be plain browser events + menuItem.removeEventListener('click', handleRevertFileClick as any); menuItem.textContent = 'Reverting…'; event.preventDefault(); event.stopPropagation(); @@ -88,7 +87,7 @@ async function handleRevertFileClick(event: React.MouseEvent<HTMLButtonElement>) if (!file) { // The file was created by this PR. Revert === Delete. // If there was a way to tell if a file was created by the PR, we could skip `getFile` - // TODO: find this info on the page + // TODO: find this info on the page ("was this file created by this PR?") await deleteFile(menuItem); return; } @@ -108,7 +107,7 @@ async function handleRevertFileClick(event: React.MouseEvent<HTMLButtonElement>) } } -async function handleMenuOpening(event: DelegateEvent): Promise<void> { +function handleMenuOpening(event: DelegateEvent): void { const dropdown = event.delegateTarget.nextElementSibling!; const editFile = select<HTMLAnchorElement>('[aria-label^="Change this"]', dropdown); diff --git a/source/features/show-names.tsx b/source/features/show-names.tsx index 43fcfe5f..9363e991 100644 --- a/source/features/show-names.tsx +++ b/source/features/show-names.tsx @@ -72,7 +72,7 @@ features.add({ features.isDashboard ], load: features.onDomReady, - init: async () => onNewsfeedLoad(init) + init: () => onNewsfeedLoad(init) }); features.add({ diff --git a/source/features/sticky-discussion-sidebar.tsx b/source/features/sticky-discussion-sidebar.tsx index edbc729b..82e2938a 100644 --- a/source/features/sticky-discussion-sidebar.tsx +++ b/source/features/sticky-discussion-sidebar.tsx @@ -4,7 +4,7 @@ import debounce from 'debounce-fn'; import features from '../libs/features'; function updateStickiness(): void { - const sidebar = select<HTMLElement>('#partial-discussion-sidebar')!; + const sidebar = select('#partial-discussion-sidebar')!; const sidebarHeight = sidebar.offsetHeight + 60; // 60 matches sticky header's height sidebar.classList.toggle('rgh-sticky-sidebar', sidebarHeight < window.innerHeight); } diff --git a/source/features/submit-review-as-single-comment.tsx b/source/features/submit-review-as-single-comment.tsx index 74b0cd45..32238e28 100644 --- a/source/features/submit-review-as-single-comment.tsx +++ b/source/features/submit-review-as-single-comment.tsx @@ -64,7 +64,7 @@ async function handleSubmitSingle(event: DelegateEvent): Promise<void> { // Use nearby comment box const comment = await getNewCommentField(commentContainer, lineBeingCommentedOn); const submitButton = select<HTMLButtonElement>('[name="single_comment"]', comment.form!)!; - const commentForm = comment.closest('.inline-comment-form-container') as HTMLElement; + const commentForm = comment.closest<HTMLElement>('.inline-comment-form-container')!; // Copy comment to new comment box insertText(comment.form!.elements['comment[body]'] as HTMLTextAreaElement, commentText); diff --git a/source/features/tags-dropdown.tsx b/source/features/tags-dropdown.tsx index 6e61e306..e151c968 100644 --- a/source/features/tags-dropdown.tsx +++ b/source/features/tags-dropdown.tsx @@ -5,7 +5,7 @@ import features from '../libs/features'; import {getRepoURL} from '../libs/utils'; import {octoface} from '../libs/icons'; -async function init(): Promise<false | void> { +function init(): false | void { if (select.exists('.blankslate')) { return false; } diff --git a/source/features/view-markdown-source.tsx b/source/features/view-markdown-source.tsx index 79501013..39a0d407 100644 --- a/source/features/view-markdown-source.tsx +++ b/source/features/view-markdown-source.tsx @@ -39,7 +39,7 @@ async function showSource(): Promise<void> { sourceButton.disabled = true; const source = btnBodyMap.get(sourceButton) || fetchSource(); - const rendered = btnBodyMap.get(renderedButton) as Element || select('.blob.instapaper_body')!; + const rendered = await btnBodyMap.get(renderedButton) || select('.blob.instapaper_body')!; btnBodyMap.set(sourceButton, source); btnBodyMap.set(renderedButton, rendered); @@ -61,7 +61,7 @@ async function showRendered(): Promise<void> { renderedButton.disabled = true; - (await btnBodyMap.get(sourceButton))!.replaceWith(btnBodyMap.get(renderedButton) as Element); + (await btnBodyMap.get(sourceButton))!.replaceWith(await btnBodyMap.get(renderedButton)!); renderedButton.disabled = false; diff --git a/source/globals.d.ts b/source/globals.d.ts index 6d891eb6..bd6a5446 100644 --- a/source/globals.d.ts +++ b/source/globals.d.ts @@ -1,3 +1,5 @@ +// TODO: Drop some definitions when their related bugs are resolved + type AnyObject = Record<string, any>; type AsyncVoidFunction = () => Promise<void>; @@ -17,7 +19,7 @@ interface Window { content: GlobalFetch; } -// TODO: Drop after https://github.com/sindresorhus/p-memoize/issues/9 +// Drop after https://github.com/sindresorhus/p-memoize/issues/9 declare module 'mem' { function mem<T = VoidFunction>(fn: T, options?: AnyObject): T; export = mem; @@ -25,8 +27,7 @@ declare module 'mem' { declare module 'size-plugin'; -// TODO: Drop linkify-* types when Firefox adds RegEx lookbehind support -// https://github.com/sindresorhus/refined-github/pull/1936#discussion_r276515991 +// Drop when Firefox adds RegEx lookbehind support https://github.com/sindresorhus/refined-github/pull/1936#discussion_r276515991 declare module 'linkify-urls' { type Options = { user: string; @@ -44,6 +45,7 @@ declare module 'linkify-urls' { export = linkifyUrls; } +// Drop when Firefox adds RegEx lookbehind support https://github.com/sindresorhus/refined-github/pull/1936#discussion_r276515991 declare module 'linkify-issues' { type Options = { user: string; @@ -64,7 +66,6 @@ declare module 'linkify-issues' { // Custom UI events specific to RGH interface GlobalEventHandlersEventMap { 'details:toggled': CustomEvent; - 'focusin': UIEvent; // Drop when it reaches W3C Recommendation https://github.com/Microsoft/TSJS-lib-generator/pull/369 'rgh:view-markdown-source': CustomEvent; 'rgh:view-markdown-rendered': CustomEvent; 'filterable:change': CustomEvent; @@ -84,18 +85,12 @@ declare namespace JSX { } } -// TODO: Drop when this bug is fixed -// https://github.com/Microsoft/TypeScript/issues/30928 +// Drop after https://github.com/Microsoft/TypeScript/issues/30928 interface NamedNodeMap { [key: string]: Attr; } -// https://github.com/Microsoft/TypeScript/issues/30928 +// Drop after https://github.com/Microsoft/TypeScript/issues/30928 interface HTMLFormControlsCollection { [key: string]: HTMLInputElement | HTMLTextAreaElement | HTMLButtonElement; } - -// TODO: Drop when this appears on npm https://github.com/microsoft/TypeScript/blob/340f81035ff1d753e6a1f0fedc2323d169c86cc6/src/lib/dom.generated.d.ts#L9686 -interface KeyboardEvent { - readonly isComposing: boolean; -} diff --git a/source/libs/features.tsx b/source/libs/features.tsx index b3205bd4..a84c5b17 100644 --- a/source/libs/features.tsx +++ b/source/libs/features.tsx @@ -170,12 +170,12 @@ const add = async (definition: FeatureDetails): Promise<void> => { return result; }; - onAjaxedPages(async () => run(details)); + onAjaxedPages(() => run(details)); } else if (load instanceof Promise) { await load; run(details); } else { - load(async () => run(details)); + load(() => run(details)); } }; diff --git a/source/libs/get-default-branch.ts b/source/libs/get-default-branch.ts index c55eb66e..bae7c86c 100644 --- a/source/libs/get-default-branch.ts +++ b/source/libs/get-default-branch.ts @@ -26,11 +26,9 @@ function parseBranchFromDom(): string | undefined { return matches ? matches[1] : undefined; } -async function fetchFromApi(): Promise<any> { +async function fetchFromApi(): Promise<string> { const response = await api.v3(`repos/${getRepoURL()}`); - if (response.default_branch) { - return response.default_branch; - } + return response.default_branch as string; } export default async function (): Promise<string> { diff --git a/source/libs/get-text-nodes.ts b/source/libs/get-text-nodes.ts index 30bf9722..e8cee915 100644 --- a/source/libs/get-text-nodes.ts +++ b/source/libs/get-text-nodes.ts @@ -1,4 +1,4 @@ -export default (el: Node) => { +export default (el: Node): Text[] => { const walker = document.createTreeWalker(el, NodeFilter.SHOW_TEXT); const nodes: Text[] = []; let node: Text; diff --git a/source/libs/on-new-comments.ts b/source/libs/on-new-comments.ts index 43fd224a..2ddc5aae 100644 --- a/source/libs/on-new-comments.ts +++ b/source/libs/on-new-comments.ts @@ -7,6 +7,7 @@ const observed = new WeakSet(); const run = debounce(() => { // Safely run all callbacks + // eslint-disable-next-line @typescript-eslint/require-await handlers.forEach(async cb => cb()); }, {wait: 200}); diff --git a/source/libs/post-form.ts b/source/libs/post-form.ts index ad8f5851..ccee33f4 100644 --- a/source/libs/post-form.ts +++ b/source/libs/post-form.ts @@ -6,7 +6,7 @@ export default async function postForm(form: HTMLFormElement): Promise<Response> const contentFetch = typeof window.content === 'object' ? window.content.fetch : window.fetch; const response = await contentFetch(form.action, { - // `as` required until https://github.com/microsoft/TSJS-lib-generator/issues/741 + // TODO: drop `as` after https://github.com/microsoft/TSJS-lib-generator/issues/741 body: new URLSearchParams(new FormData(form) as URLSearchParams), method: 'POST', headers: { diff --git a/source/options-storage.ts b/source/options-storage.ts index 6330ac8d..83bbdb6f 100644 --- a/source/options-storage.ts +++ b/source/options-storage.ts @@ -1,4 +1,4 @@ -import OptionsSync from 'webext-options-sync'; +import OptionsSync, {Migration} from 'webext-options-sync'; import {isBackgroundPage} from 'webext-detect-page'; import {getAdditionalPermissions} from 'webext-additional-permissions'; @@ -10,7 +10,7 @@ export interface RGHOptions { [featureName: string]: string | boolean; } -function featureWasRenamed(from: string, to: string): any { // TODO: any should probably be `Migration` after `webext-options-sync`'s types are fixed +function featureWasRenamed(from: string, to: string): Migration<RGHOptions> { return (options: RGHOptions) => { if (typeof options[`feature:${from}`] === 'boolean') { options[`feature:${to}`] = options[`feature:${from}`]; diff --git a/source/options.tsx b/source/options.tsx index 1bc890a2..bc5171b9 100644 --- a/source/options.tsx +++ b/source/options.tsx @@ -66,7 +66,7 @@ async function init(): Promise<void> { <select> {[...optionsByDomain.keys()].map(domain => <option value={domain}>{domain}</option>)} </select> - ) as any as HTMLSelectElement; + ) as unknown as HTMLSelectElement; form.before(<p>Domain selector: {dropdown}</p>, <hr/>); dropdown.addEventListener('change', () => { for (const [domain, options] of optionsByDomain) { |