summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar yakov116 <16872793+yakov116@users.noreply.github.com> 2020-06-26 04:30:43 -0400
committerGravatar GitHub <noreply@github.com> 2020-06-26 10:30:43 +0200
commitc6c727ca571c91d1ff426e218ccadb075cdb2af6 (patch)
treee1855bb6c6d37f0b28b97be73192316fec2067e5
parent15da229b3a29483f076782361ac429854f18e18b (diff)
downloadrefined-github-c6c727ca571c91d1ff426e218ccadb075cdb2af6.tar.gz
refined-github-c6c727ca571c91d1ff426e218ccadb075cdb2af6.tar.zst
refined-github-c6c727ca571c91d1ff426e218ccadb075cdb2af6.zip
Lint and avoid errors (#3256)
-rw-r--r--source/features/bypass-checks.tsx5
-rw-r--r--source/features/comment-fields-keyboard-shortcuts.tsx13
-rw-r--r--source/features/deep-reblame.tsx4
-rw-r--r--source/features/default-branch-button.tsx3
-rw-r--r--source/features/download-folder-button.tsx2
-rw-r--r--source/features/fit-textareas.tsx3
-rw-r--r--source/features/fork-source-link-same-view.tsx2
-rw-r--r--source/features/improve-shortcut-help.tsx23
-rw-r--r--source/features/mark-merge-commits-in-list.tsx2
-rw-r--r--source/features/minimize-upload-bar.tsx2
-rw-r--r--source/features/one-key-formatting.tsx4
-rw-r--r--source/features/pr-branches.tsx2
-rw-r--r--source/features/preview-hidden-comments.tsx13
-rw-r--r--source/features/release-download-count.tsx2
-rw-r--r--source/features/selection-in-new-tab.tsx24
-rw-r--r--source/features/show-associated-branch-prs-on-fork.tsx7
-rw-r--r--source/features/tab-to-indent.tsx4
-rw-r--r--source/github-helpers/index.ts7
18 files changed, 71 insertions, 51 deletions
diff --git a/source/features/bypass-checks.tsx b/source/features/bypass-checks.tsx
index 03303573..b5357835 100644
--- a/source/features/bypass-checks.tsx
+++ b/source/features/bypass-checks.tsx
@@ -9,7 +9,10 @@ async function bypass(detailsLink: HTMLAnchorElement): Promise<void> {
detailsLink.href,
'[data-hydro-click*="check_suite.external_click"]'
);
- detailsLink.href = directLink!.href;
+
+ if (directLink) {
+ detailsLink.href = directLink.href;
+ }
}
async function init(): Promise<void> {
diff --git a/source/features/comment-fields-keyboard-shortcuts.tsx b/source/features/comment-fields-keyboard-shortcuts.tsx
index f26b8c31..3a65f282 100644
--- a/source/features/comment-fields-keyboard-shortcuts.tsx
+++ b/source/features/comment-fields-keyboard-shortcuts.tsx
@@ -1,5 +1,6 @@
import select from 'select-dom';
import delegate from 'delegate-it';
+import * as pageDetect from 'github-url-detection';
import features from '.';
import onCommentFieldKeydown from '../github-events/on-comment-field-keydown';
@@ -39,13 +40,10 @@ function eventHandler(event: delegate.Event<KeyboardEvent, HTMLTextAreaElement>)
if (lastOwnComment) {
select<HTMLButtonElement>('.js-comment-edit-button', lastOwnComment)!.click();
- const closeCurrentField = field
+ field
.closest('form')!
- .querySelector<HTMLButtonElement>('.js-hide-inline-comment-form');
-
- if (closeCurrentField) {
- closeCurrentField.click();
- }
+ .querySelector<HTMLButtonElement>('.js-hide-inline-comment-form')
+ ?.click();
// Move caret to end of field
requestAnimationFrame(() => {
@@ -68,6 +66,9 @@ void features.add({
esc: 'Unfocuses comment field'
}
}, {
+ include: [
+ pageDetect.hasRichTextEditor
+ ],
waitForDomReady: false,
repeatOnAjax: false,
init
diff --git a/source/features/deep-reblame.tsx b/source/features/deep-reblame.tsx
index 935a1ce6..9a484635 100644
--- a/source/features/deep-reblame.tsx
+++ b/source/features/deep-reblame.tsx
@@ -16,9 +16,7 @@ const getPullRequestBlameCommit = mem(async (commit: string, prNumber: number, c
const {repository} = await api.v4(`
repository(${getRepoGQL()}) {
file: object(expression: "${commit}:${currentFilename}") {
- ... on Blob {
- id
- }
+ id
}
object(expression: "${commit}") {
... on Commit {
diff --git a/source/features/default-branch-button.tsx b/source/features/default-branch-button.tsx
index 1c89fe04..f4610cd6 100644
--- a/source/features/default-branch-button.tsx
+++ b/source/features/default-branch-button.tsx
@@ -63,6 +63,9 @@ void features.add({
pageDetect.isSingleFile,
pageDetect.isRepoCommitList
],
+ exclude: [
+ pageDetect.isRepoHome
+ ],
waitForDomReady: false,
init
});
diff --git a/source/features/download-folder-button.tsx b/source/features/download-folder-button.tsx
index ff80b7a9..a1f15218 100644
--- a/source/features/download-folder-button.tsx
+++ b/source/features/download-folder-button.tsx
@@ -1,7 +1,7 @@
import React from 'dom-chef';
import select from 'select-dom';
-import * as pageDetect from 'github-url-detection';
import DownloadIcon from 'octicon/download.svg';
+import * as pageDetect from 'github-url-detection';
import features from '.';
diff --git a/source/features/fit-textareas.tsx b/source/features/fit-textareas.tsx
index 2b0642e4..659fae66 100644
--- a/source/features/fit-textareas.tsx
+++ b/source/features/fit-textareas.tsx
@@ -40,6 +40,9 @@ void features.add({
description: 'Auto-resizes comment fields to fit their content and no longer show scroll bars, rather than have a height limit like GitHub’s native "fit to content" behavior.',
screenshot: 'https://user-images.githubusercontent.com/1402241/54336211-66fd5e00-4666-11e9-9c5e-111fccab004d.gif'
}, {
+ include: [
+ pageDetect.hasRichTextEditor
+ ],
init
}, {
include: [
diff --git a/source/features/fork-source-link-same-view.tsx b/source/features/fork-source-link-same-view.tsx
index d65d3f48..59bd55f1 100644
--- a/source/features/fork-source-link-same-view.tsx
+++ b/source/features/fork-source-link-same-view.tsx
@@ -31,7 +31,7 @@ void features.add({
],
exclude: [
() => !pageDetect.isForkedRepo(),
- () => pageDetect.isRepoRoot()
+ pageDetect.isRepoRoot
],
init
});
diff --git a/source/features/improve-shortcut-help.tsx b/source/features/improve-shortcut-help.tsx
index 852870ec..51fa9a24 100644
--- a/source/features/improve-shortcut-help.tsx
+++ b/source/features/improve-shortcut-help.tsx
@@ -3,6 +3,7 @@ import React from 'dom-chef';
import select from 'select-dom';
import features from '.';
+import {isEditable} from '../helpers/dom-utils';
function splitKeys(keys: string): DocumentFragment[] {
return keys.split(' ').map(key => <> <kbd>{key}</kbd></>);
@@ -45,17 +46,19 @@ const observer = new MutationObserver(([{target}]) => {
}
});
-function init(): void {
- document.addEventListener('keypress', ({key, target}) => {
- if (key !== '?' || target instanceof HTMLTextAreaElement || target instanceof HTMLInputElement) {
- return;
- }
+function observeShortcutModal({key, target}: KeyboardEvent): void {
+ if (key !== '?' || isEditable(target)) {
+ return;
+ }
- const modal = select('body > details > details-dialog');
- if (modal) {
- observer.observe(modal, {childList: true});
- }
- });
+ const modal = select('body > details > details-dialog');
+ if (modal) {
+ observer.observe(modal, {childList: true});
+ }
+}
+
+function init(): void {
+ document.addEventListener('keypress', observeShortcutModal);
}
void features.add({
diff --git a/source/features/mark-merge-commits-in-list.tsx b/source/features/mark-merge-commits-in-list.tsx
index d2179d36..23b6f42d 100644
--- a/source/features/mark-merge-commits-in-list.tsx
+++ b/source/features/mark-merge-commits-in-list.tsx
@@ -25,7 +25,7 @@ const filterMergeCommits = async (commits: string[]): Promise<string[]> => {
const mergeCommits = [];
for (const [key, commit] of Object.entries<AnyObject>(repository)) {
- if (commit.parents.totalCount === 2) {
+ if (commit.parents.totalCount >= 2) {
mergeCommits.push(key.slice(1));
}
}
diff --git a/source/features/minimize-upload-bar.tsx b/source/features/minimize-upload-bar.tsx
index 090db4d1..b39f4d59 100644
--- a/source/features/minimize-upload-bar.tsx
+++ b/source/features/minimize-upload-bar.tsx
@@ -2,8 +2,8 @@ import './minimize-upload-bar.css';
import React from 'dom-chef';
import select from 'select-dom';
import delegate from 'delegate-it';
-import * as pageDetect from 'github-url-detection';
import UploadIcon from 'octicon/upload.svg';
+import * as pageDetect from 'github-url-detection';
import features from '.';
diff --git a/source/features/one-key-formatting.tsx b/source/features/one-key-formatting.tsx
index 719c8bbd..fa492912 100644
--- a/source/features/one-key-formatting.tsx
+++ b/source/features/one-key-formatting.tsx
@@ -1,4 +1,5 @@
import delegate from 'delegate-it';
+import * as pageDetect from 'github-url-detection';
import * as textFieldEdit from 'text-field-edit';
import features from '.';
@@ -37,6 +38,9 @@ void features.add({
description: 'Wraps selected text when pressing one of Markdown symbols instead of replacing it: (`[` `’` `"` `(` etc).',
screenshot: 'https://user-images.githubusercontent.com/1402241/65020298-1f2dfb00-d957-11e9-9a2a-1c0ceab8d9e0.gif'
}, {
+ include: [
+ pageDetect.hasCode
+ ],
waitForDomReady: false,
repeatOnAjax: false,
init
diff --git a/source/features/pr-branches.tsx b/source/features/pr-branches.tsx
index de792cb2..e23990dc 100644
--- a/source/features/pr-branches.tsx
+++ b/source/features/pr-branches.tsx
@@ -5,9 +5,9 @@ import PullRequestIcon from 'octicon/git-pull-request.svg';
import features from '.';
import * as api from '../github-helpers/api';
+import {botSelectors} from './dim-bots';
import getDefaultBranch from '../github-helpers/get-default-branch';
import {getRepositoryInfo, getRepoGQL} from '../github-helpers';
-import {botSelectors} from './dim-bots';
type RepositoryReference = {
owner: string;
diff --git a/source/features/preview-hidden-comments.tsx b/source/features/preview-hidden-comments.tsx
index f07b6bda..14a794b3 100644
--- a/source/features/preview-hidden-comments.tsx
+++ b/source/features/preview-hidden-comments.tsx
@@ -4,11 +4,10 @@ import select from 'select-dom';
import * as pageDetect from 'github-url-detection';
import features from '.';
+import {upperCaseFirst} from '../github-helpers';
const allowedReasons = new Set(['resolved', 'outdated', 'off-topic']);
-const capitalize = (text: string): string => text.charAt(0).toUpperCase() + text.slice(1);
-
const init = (): void => {
for (const details of select.all('.minimized-comment:not(.d-none) > details:not(.rgh-preview-hidden-comments)')) {
details.classList.add('rgh-preview-hidden-comments');
@@ -18,10 +17,10 @@ const init = (): void => {
continue;
}
- const header = select(`
- summary .timeline-comment-header-text,
- summary .discussion-item-copy
- `, details)!;
+ const header = select([
+ 'summary .timeline-comment-header-text', // Issue and commit comments
+ '.discussion-item-icon + div' // Review Comments
+ ], details)!;
const reason = /was marked as ([^.]+)/.exec(header.textContent!)?.[1] ?? '';
if (!allowedReasons.has(reason)) {
@@ -30,7 +29,7 @@ const init = (): void => {
header.append(
<span className="Details-content--open">{header.firstChild}</span>,
- <span className="Details-content--closed">{`${capitalize(reason)} — ${commentText}`}</span>
+ <span className="Details-content--closed">{`${upperCaseFirst(reason)} — ${commentText}`}</span>
);
}
};
diff --git a/source/features/release-download-count.tsx b/source/features/release-download-count.tsx
index 03af9db8..f8354f77 100644
--- a/source/features/release-download-count.tsx
+++ b/source/features/release-download-count.tsx
@@ -1,8 +1,8 @@
import './release-download-count.css';
import React from 'dom-chef';
import select from 'select-dom';
-import * as pageDetect from 'github-url-detection';
import DownloadIcon from 'octicon/download.svg';
+import * as pageDetect from 'github-url-detection';
import features from '.';
import * as api from '../github-helpers/api';
diff --git a/source/features/selection-in-new-tab.tsx b/source/features/selection-in-new-tab.tsx
index 6ef6c2c1..59da6402 100644
--- a/source/features/selection-in-new-tab.tsx
+++ b/source/features/selection-in-new-tab.tsx
@@ -3,18 +3,20 @@ import select from 'select-dom';
import features from '.';
import {isEditable} from '../helpers/dom-utils';
-function init(): void {
- document.addEventListener('keypress', (event: KeyboardEvent) => {
- const selected = select<HTMLAnchorElement>('.navigation-focus .js-navigation-open[href]');
- if (selected && event.key === 'O' && !isEditable(event.target)) {
- void browser.runtime.sendMessage({
- openUrls: [selected.href]
- });
+function openInNewTab({key, target}: KeyboardEvent): void {
+ const selected = select<HTMLAnchorElement>('.navigation-focus .js-navigation-open[href]');
+ if (selected && key === 'O' && !isEditable(target)) {
+ void browser.runtime.sendMessage({
+ openUrls: [selected.href]
+ });
- // Get the list element that contains the unread class and mark it as read.
- selected.closest('.unread')?.classList.replace('unread', 'read');
- }
- });
+ // Get the list element that contains the unread class and mark it as read.
+ selected.closest('.unread')?.classList.replace('unread', 'read');
+ }
+}
+
+function init(): void {
+ document.addEventListener('keypress', openInNewTab);
}
void features.add({
diff --git a/source/features/show-associated-branch-prs-on-fork.tsx b/source/features/show-associated-branch-prs-on-fork.tsx
index e9c24624..636bf3f1 100644
--- a/source/features/show-associated-branch-prs-on-fork.tsx
+++ b/source/features/show-associated-branch-prs-on-fork.tsx
@@ -8,7 +8,7 @@ import PullRequestIcon from 'octicon/git-pull-request.svg';
import features from '.';
import * as api from '../github-helpers/api';
import observeElement from '../helpers/simplified-element-observer';
-import {getRepoGQL, getRepoURL} from '../github-helpers';
+import {getRepoGQL, getRepoURL, upperCaseFirst} from '../github-helpers';
interface PullRequest {
number: number;
@@ -59,11 +59,6 @@ const getPullRequestsAssociatedWithBranch = cache.function(async (): Promise<Rec
cacheKey: () => 'associatedBranchPullRequests:' + getRepoURL()
});
-// https://github.com/idimetrix/text-case/blob/master/packages/upper-case-first/src/index.ts
-function upperCaseFirst(input: string): string {
- return input.charAt(0).toUpperCase() + input.slice(1).toLowerCase();
-}
-
const stateClass: Record<string, string> = {
Open: '--green',
Closed: '--red',
diff --git a/source/features/tab-to-indent.tsx b/source/features/tab-to-indent.tsx
index 170bc10e..a6731d87 100644
--- a/source/features/tab-to-indent.tsx
+++ b/source/features/tab-to-indent.tsx
@@ -1,4 +1,5 @@
import {eventHandler} from 'indent-textarea';
+import * as pageDetect from 'github-url-detection';
import features from '.';
import onCommentFieldKeydown from '../github-events/on-comment-field-keydown';
@@ -12,6 +13,9 @@ void features.add({
description: 'Enables <kbd>tab</kbd> and <kbd>shift+tab</kbd> for indentation in comment fields.',
screenshot: 'https://user-images.githubusercontent.com/1402241/33802977-beb8497c-ddbf-11e7-899c-698d89298de4.gif'
}, {
+ include: [
+ pageDetect.hasCode
+ ],
waitForDomReady: false,
repeatOnAjax: false,
init
diff --git a/source/github-helpers/index.ts b/source/github-helpers/index.ts
index 7f79612d..0eea0b02 100644
--- a/source/github-helpers/index.ts
+++ b/source/github-helpers/index.ts
@@ -65,7 +65,7 @@ export function compareNames(username: string, realname: string): boolean {
* @param {string} selector A css selector.
*/
export function getScopedSelector(selector: string): string {
- return selector.split(',').map(sub => `:scope > ${sub.trim()}`).join(',');
+ return selector.split(',').map(sub => `:scope > ${sub.trim()}`).join();
}
export function looseParseInt(text: string): number {
@@ -109,3 +109,8 @@ export function preventPrCommitLinkLoss(url: string, pr: string, commit: string,
return `[\`${commit}\` (#${pr})](${url})`;
}
+
+// https://github.com/idimetrix/text-case/blob/master/packages/upper-case-first/src/index.ts
+export function upperCaseFirst(input: string): string {
+ return input.charAt(0).toUpperCase() + input.slice(1).toLowerCase();
+}