Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint #6555

Merged
merged 9 commits into from
Apr 25, 2023
Merged

Lint #6555

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions source/feature-manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import onAbort from './helpers/abort-controller';
import ArrayMap from './helpers/map-of-arrays';
import bisectFeatures from './helpers/bisect';
import {shouldFeatureRun} from './github-helpers';
import polyfillTurboEvents from './github-helpers/turbo-events-polyfill';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PJAX is old news

import optionsStorage, {RGHOptions} from './options-storage';
import {
applyStyleHotfixes,
Expand Down Expand Up @@ -151,8 +150,6 @@ const globalReady = new Promise<RGHOptions>(async resolve => {
features.log.error = () => {/* No logging */};
}

polyfillTurboEvents();

resolve(options);
});

Expand Down
2 changes: 1 addition & 1 deletion source/features/bypass-checks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function bypass(detailsLink: HTMLAnchorElement): Promise<void> {
return;
}

// TODO: Use v4: https://docs.github.com/en/graphql/reference/objects#checkrun
// Impossible with v4 https://github.com/refined-github/refined-github/pull/6550#discussion_r1176346110
const {details_url: detailsUrl} = await api.v3(`check-runs/${runId}`);
if (!detailsUrl) {
return;
Expand Down
8 changes: 4 additions & 4 deletions source/features/clear-pr-merge-commit-message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,21 @@ async function init(): Promise<void | false> {
}

void features.add(import.meta.url, {
asLongAs: [
userCanLikelyMergePR,
],
include: [
pageDetect.isPRConversation,
],
exclude: [
// Don't clear 1-commit PRs #3140
() => select.all('.TimelineItem.js-commit').length === 1,
],
asLongAs: [
userCanLikelyMergePR,
],
additionalListeners: [
onPrMergePanelOpen,
],
onlyAdditionalListeners: true,
awaitDomReady: true, // Appears near the page anyway
awaitDomReady: true, // Appears near the end of the page anyway
init,
});

Expand Down
1 change: 0 additions & 1 deletion source/features/conversation-activity-filter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ async function addWidget(header: string, state: State): Promise<void> {
}

const minorFixesIssuePages = [
'https://github.com/refined-github/refined-github/issues/5222',
'https://github.com/refined-github/refined-github/issues/3686',
'https://github.com/refined-github/refined-github/issues/6000',
];
Expand Down
9 changes: 9 additions & 0 deletions source/features/enable-file-links-in-compare-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,12 @@ void features.add(import.meta.url, {
awaitDomReady: true, // DOM-based filters
init,
});

/*
Test URLs
- Open PR: https://github.com/refined-github/sandbox/pull/4/files
- Compare view: https://github.com/refined-github/sandbox/compare/default-a...very-very-long-long-long-long-branch-name
*/
6 changes: 3 additions & 3 deletions source/features/link-to-github-io.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ function initRepoList(signal: AbortSignal): void {
}

void features.add(import.meta.url, {
include: [
pageDetect.hasRepoHeader,
],
asLongAs: [
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asLongAs must be first

() => /\.github\.(io|com)$/.test(getRepo()?.name ?? 'shush eslint'),
],
include: [
pageDetect.hasRepoHeader,
],
init: initRepo,
}, {
include: [
Expand Down
6 changes: 3 additions & 3 deletions source/features/linkify-user-labels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ function init(signal: AbortSignal): void {
}

void features.add(import.meta.url, {
include: [
pageDetect.hasComments,
],
asLongAs: [
pageDetect.isRepo,
],
include: [
pageDetect.hasComments,
],
init,
});

Expand Down
6 changes: 3 additions & 3 deletions source/features/sync-pr-commit-title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ function init(signal: AbortSignal): void {
}

void features.add(import.meta.url, {
include: [
pageDetect.isPRConversation,
],
asLongAs: [
userCanLikelyMergePR,
],
include: [
pageDetect.isPRConversation,
],
awaitDomReady: true, // DOM-based filters, feature appears at the end of the page
init,
});
20 changes: 0 additions & 20 deletions source/github-helpers/turbo-events-polyfill.ts

This file was deleted.

4 changes: 4 additions & 0 deletions source/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,7 @@ declare module 'react' {
interface Node extends EventTarget {
cloneNode(deep?: boolean): this;
}

interface SignalAsOptions {
signal?: AbortSignal;
}
21 changes: 16 additions & 5 deletions source/helpers/selector-observer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@ import {ParseSelector} from 'typed-query-selector/parser';
import getCallerID from './caller-id';
import isDevelopmentVersion from './is-development-version';

type ObserverListener<ExpectedElement extends Element> = (element: ExpectedElement, options: SignalAsOptions) => void;

const animation = 'rgh-selector-observer';
const getListener = <ExpectedElement extends HTMLElement>(seenMark: string, selector: string, callback: (element: ExpectedElement) => void) => function (event: AnimationEvent) {
const getListener = <
Selector extends string,
ExpectedElement extends ParseSelector<Selector, HTMLElement>,
>(
seenMark: string,
selector: Selector,
callback: ObserverListener<ExpectedElement>,
signal?: AbortSignal,
) => function (event: AnimationEvent) {
const target = event.target as ExpectedElement;
// The target can match a selector even if the animation actually happened on a ::before pseudo-element, so it needs an explicit exclusion here
if (target.classList.contains(seenMark) || !target.matches(selector)) {
Expand All @@ -17,7 +27,7 @@ const getListener = <ExpectedElement extends HTMLElement>(seenMark: string, sele
// Removes this specific selector’s animation once it was seen
target.classList.add(seenMark);

callback(target);
callback(target, {signal});
};

const registerAnimation = onetime((): void => {
Expand All @@ -26,10 +36,11 @@ const registerAnimation = onetime((): void => {

export default function observe<
Selector extends string,
ExpectedElement extends ParseSelector<Selector, HTMLElement>,
>(
selectors: Selector | readonly Selector[],
listener: (element: ParseSelector<Selector, HTMLElement>) => void,
{signal}: {signal?: AbortSignal} = {},
listener: ObserverListener<ExpectedElement>,
{signal}: SignalAsOptions = {},
): void {
if (signal?.aborted) {
return;
Expand All @@ -55,5 +66,5 @@ export default function observe<
signal?.addEventListener('abort', () => {
rule.remove();
});
window.addEventListener('animationstart', getListener(seenMark, selector, listener), {signal});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lets us listen to the feature unload inside the observer’s callback:

function add(element, {signal}) {
	wrap(element, <strong/>)
	signal.addEventListener('abort', () => {
		element.remove();
	});
}

function init(signal) {
	observe('a', add, {signal})
}

Mentioned in:

window.addEventListener('animationstart', getListener(seenMark, selector, listener, signal), {signal});
}