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 1 commit
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
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 @@ -61,7 +61,7 @@

// Remove PR number from commit title
const prTitle = getCommitTitleField()!.value
.replace(regexJoin(/\s*\(/, '#' + getConversationNumber()!, /\)$/), '');

Check failure on line 64 in source/features/sync-pr-commit-title.tsx

View workflow job for this annotation

GitHub Actions / Lint

Operands of '+' operation must either be both strings or both numbers. Consider using a template literal.

// Fill and submit title-change form
select(prTitleFieldSelector)!.value = prTitle;
Expand Down Expand Up @@ -89,12 +89,12 @@
}

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,
});
12 changes: 6 additions & 6 deletions source/github-helpers/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '.';

test('getConversationNumber', () => {
const pairs = new Map<string, string | undefined>([
const pairs = new Map<string, number | undefined>([
[
'https://github.com',
undefined,
Expand Down Expand Up @@ -48,23 +48,23 @@ test('getConversationNumber', () => {
],
[
'https://github.com/refined-github/refined-github/pull/148/commits/0019603b83bd97c2f7ef240969f49e6126c5ec85',
'148',
148,
],
[
'https://github.com/refined-github/refined-github/pull/148/commits/00196',
'148',
148,
],
[
'https://github.com/refined-github/refined-github/pull/148/commits',
'148',
148,
],
[
'https://github.com/refined-github/refined-github/pull/148',
'148',
148,
],
[
'https://github.com/refined-github/refined-github/issues/146',
'146',
146,
],
[
'https://github.com/refined-github/refined-github/issues',
Expand Down
4 changes: 2 additions & 2 deletions source/github-helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import * as pageDetect from 'github-url-detection';
export const getUsername = onetime(pageDetect.utils.getUsername);
export const {getRepositoryInfo: getRepo, getCleanPathname} = pageDetect.utils;

export const getConversationNumber = (): string | undefined => {
export const getConversationNumber = (): number | undefined => {
if (pageDetect.isPR() || pageDetect.isIssue()) {
return location.pathname.split('/')[4];
return Number(location.pathname.split('/')[4]);
}

return undefined;
Expand Down
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;
}
12 changes: 7 additions & 5 deletions source/helpers/selector-observer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import {ParseSelector} from 'typed-query-selector/parser';
import getCallerID from './caller-id';
import isDevelopmentVersion from './is-development-version';

type ObserverListener<Selector extends string> = (element: ParseSelector<Selector, HTMLElement>, 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 = <ExpectedElement extends HTMLElement>(seenMark: string, selector: string, callback: ObserverListener<string>, 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 +19,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 @@ -28,8 +30,8 @@ export default function observe<
Selector extends string,
>(
selectors: Selector | readonly Selector[],
listener: (element: ParseSelector<Selector, HTMLElement>) => void,
{signal}: {signal?: AbortSignal} = {},
listener: ObserverListener<Selector>,
{signal}: SignalAsOptions = {},
): void {
if (signal?.aborted) {
return;
Expand All @@ -55,5 +57,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});
}