Skip to content

Commit 63f13ee

Browse files
author
ntwigg
committed
biome:fix
1 parent 180b258 commit 63f13ee

File tree

5 files changed

+173
-187
lines changed

5 files changed

+173
-187
lines changed
Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,48 @@
1-
import { CommentContext, TextareaHandler, TextareaInfo } from './textarea-handler';
2-
import { GitHubHandler } from '../handlers/github-handler';
3-
import { RedditHandler } from '../handlers/reddit-handler';
1+
import { GitHubHandler } from '../handlers/github-handler'
2+
import { RedditHandler } from '../handlers/reddit-handler'
3+
import type { CommentContext, TextareaHandler, TextareaInfo } from './textarea-handler'
44

55
export class HandlerRegistry {
6-
private handlers = new Set<TextareaHandler<any>>();
6+
private handlers = new Set<TextareaHandler<any>>()
77

88
constructor() {
99
// Register all available handlers
10-
this.register(new GitHubHandler());
11-
this.register(new RedditHandler());
10+
this.register(new GitHubHandler())
11+
this.register(new RedditHandler())
1212
}
1313

1414
private register<T extends CommentContext>(handler: TextareaHandler<T>): void {
15-
this.handlers.add(handler);
15+
this.handlers.add(handler)
1616
}
1717

1818
getHandlerForType(type: string): TextareaHandler<any> | null {
1919
for (const handler of this.handlers) {
2020
if (handler.forCommentTypes().includes(type)) {
21-
return handler;
21+
return handler
2222
}
2323
}
24-
return null;
24+
return null
2525
}
2626

2727
identifyTextarea(textarea: HTMLTextAreaElement): TextareaInfo<any> | null {
2828
for (const handler of this.handlers) {
2929
try {
30-
const context = handler.identifyContextOf(textarea);
30+
const context = handler.identifyContextOf(textarea)
3131
if (context) {
32-
return { element: textarea, context, handler };
32+
return { context, element: textarea, handler }
3333
}
3434
} catch (error) {
35-
console.warn('Handler failed to identify textarea:', error);
35+
console.warn('Handler failed to identify textarea:', error)
3636
}
3737
}
38-
return null;
38+
return null
3939
}
4040

41-
4241
getAllHandlers(): TextareaHandler<any>[] {
43-
return Array.from(this.handlers);
42+
return Array.from(this.handlers)
4443
}
4544

4645
getCommentTypesForHandler(handler: TextareaHandler<any>): string[] {
47-
return handler.forCommentTypes();
46+
return handler.forCommentTypes()
4847
}
49-
}
48+
}
Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
21
export interface CommentContext {
3-
unique_key: string;
4-
type: string;
2+
unique_key: string
3+
type: string
54
}
65

76
export interface TextareaInfo<T extends CommentContext = CommentContext> {
8-
element: HTMLTextAreaElement;
9-
context: T;
10-
handler: TextareaHandler<T>;
7+
element: HTMLTextAreaElement
8+
context: T
9+
handler: TextareaHandler<T>
1110
}
1211

1312
export interface TextareaHandler<T extends CommentContext = CommentContext> {
1413
// Handler metadata
15-
forCommentTypes(): string[];
14+
forCommentTypes(): string[]
1615
// whenever a new `textarea` is added to any webpage, this method is called to try to find a handler for it
17-
identifyContextOf(textarea: HTMLTextAreaElement): T | null;
18-
16+
identifyContextOf(textarea: HTMLTextAreaElement): T | null
17+
1918
// Popup functionality helpers
20-
generateDisplayTitle(context: T): string;
21-
generateIcon(context: T): string;
22-
buildUrl(context: T, withDraft?: boolean): string;
19+
generateDisplayTitle(context: T): string
20+
generateIcon(context: T): string
21+
buildUrl(context: T, withDraft?: boolean): string
2322
}
24-
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import { TextareaInfo, CommentContext } from './textarea-handler';
1+
import type { CommentContext, TextareaInfo } from './textarea-handler'
22

33
export class TextareaRegistry {
4-
private textareas = new Map<HTMLTextAreaElement, TextareaInfo<any>>();
4+
private textareas = new Map<HTMLTextAreaElement, TextareaInfo<any>>()
55

66
register<T extends CommentContext>(textareaInfo: TextareaInfo<T>): void {
7-
this.textareas.set(textareaInfo.element, textareaInfo);
7+
this.textareas.set(textareaInfo.element, textareaInfo)
88
// TODO: register as a draft in progress with the global list
99
}
1010

1111
unregisterDueToModification(textarea: HTMLTextAreaElement): void {
1212
if (this.textareas.has(textarea)) {
1313
// TODO: register as abandoned or maybe submitted with the global list
14-
this.textareas.delete(textarea);
14+
this.textareas.delete(textarea)
1515
}
1616
}
1717

1818
get(textarea: HTMLTextAreaElement): TextareaInfo<any> | undefined {
19-
return this.textareas.get(textarea);
19+
return this.textareas.get(textarea)
2020
}
21-
}
21+
}
Lines changed: 74 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
import { CommentContext, TextareaHandler } from '../datamodel/textarea-handler';
1+
import type { CommentContext, TextareaHandler } from '../datamodel/textarea-handler'
22

3-
export type GitHubCommentType =
3+
export type GitHubCommentType =
44
| 'GH_ISSUE_NEW'
55
| 'GH_PR_NEW'
66
| 'GH_ISSUE_ADD_COMMENT'
77
| 'GH_ISSUE_EDIT_COMMENT'
88
| 'GH_PR_ADD_COMMENT'
99
| 'GH_PR_EDIT_COMMENT'
10-
| 'GH_PR_CODE_COMMENT';
10+
| 'GH_PR_CODE_COMMENT'
1111

1212
export interface GitHubContext extends CommentContext {
13-
type: GitHubCommentType; // Override to narrow from string to specific union
14-
domain: string;
15-
slug: string; // owner/repo
16-
number?: number | undefined; // issue/PR number
17-
commentId?: string | undefined; // for editing existing comments
13+
type: GitHubCommentType // Override to narrow from string to specific union
14+
domain: string
15+
slug: string // owner/repo
16+
number?: number | undefined // issue/PR number
17+
commentId?: string | undefined // for editing existing comments
1818
}
1919

2020
export class GitHubHandler implements TextareaHandler<GitHubContext> {
21-
2221
forCommentTypes(): string[] {
2322
return [
2423
'GH_ISSUE_NEW',
@@ -27,144 +26,144 @@ export class GitHubHandler implements TextareaHandler<GitHubContext> {
2726
'GH_ISSUE_EDIT_COMMENT',
2827
'GH_PR_ADD_COMMENT',
2928
'GH_PR_EDIT_COMMENT',
30-
'GH_PR_CODE_COMMENT'
31-
];
29+
'GH_PR_CODE_COMMENT',
30+
]
3231
}
3332

3433
identifyContextOf(textarea: HTMLTextAreaElement): GitHubContext | null {
3534
// Only handle GitHub domains
3635
if (!window.location.hostname.includes('github')) {
37-
return null;
36+
return null
3837
}
3938

40-
const pathname = window.location.pathname;
41-
39+
const pathname = window.location.pathname
40+
4241
// Parse GitHub URL structure: /owner/repo/issues/123 or /owner/repo/pull/456
43-
const match = pathname.match(/^\/([^\/]+)\/([^\/]+)(?:\/(issues|pull)\/(\d+))?/);
44-
if (!match) return null;
42+
const match = pathname.match(/^\/([^/]+)\/([^/]+)(?:\/(issues|pull)\/(\d+))?/)
43+
if (!match) return null
44+
45+
const [, owner, repo, urlType, numberStr] = match
46+
const slug = `${owner}/${repo}`
47+
const number = numberStr ? parseInt(numberStr, 10) : undefined
4548

46-
const [, owner, repo, urlType, numberStr] = match;
47-
const slug = `${owner}/${repo}`;
48-
const number = numberStr ? parseInt(numberStr, 10) : undefined;
49-
5049
// Check if editing existing comment
51-
const commentId = this.getCommentId(textarea);
52-
50+
const commentId = this.getCommentId(textarea)
51+
5352
// Determine comment type
54-
let type: GitHubCommentType;
55-
53+
let type: GitHubCommentType
54+
5655
// New issue
5756
if (pathname.includes('/issues/new')) {
58-
type = 'GH_ISSUE_NEW';
57+
type = 'GH_ISSUE_NEW'
5958
}
6059
// New PR
6160
else if (pathname.includes('/compare/') || pathname.endsWith('/compare')) {
62-
type = 'GH_PR_NEW';
61+
type = 'GH_PR_NEW'
6362
}
6463
// Existing issue or PR page
6564
else if (urlType && number) {
66-
const isEditingComment = commentId !== null;
67-
65+
const isEditingComment = commentId !== null
66+
6867
if (urlType === 'issues') {
69-
type = isEditingComment ? 'GH_ISSUE_EDIT_COMMENT' : 'GH_ISSUE_ADD_COMMENT';
68+
type = isEditingComment ? 'GH_ISSUE_EDIT_COMMENT' : 'GH_ISSUE_ADD_COMMENT'
7069
} else {
7170
// Check if it's a code comment (in Files Changed tab)
72-
const isCodeComment = textarea.closest('.js-inline-comment-form') !== null ||
73-
textarea.closest('[data-path]') !== null;
74-
71+
const isCodeComment =
72+
textarea.closest('.js-inline-comment-form') !== null ||
73+
textarea.closest('[data-path]') !== null
74+
7575
if (isCodeComment) {
76-
type = 'GH_PR_CODE_COMMENT';
76+
type = 'GH_PR_CODE_COMMENT'
7777
} else {
78-
type = isEditingComment ? 'GH_PR_EDIT_COMMENT' : 'GH_PR_ADD_COMMENT';
78+
type = isEditingComment ? 'GH_PR_EDIT_COMMENT' : 'GH_PR_ADD_COMMENT'
7979
}
8080
}
8181
} else {
82-
return null;
82+
return null
8383
}
84-
84+
8585
// Generate unique key based on context
86-
let unique_key = `github:${slug}`;
86+
let unique_key = `github:${slug}`
8787
if (number) {
88-
unique_key += `:${urlType}:${number}`;
88+
unique_key += `:${urlType}:${number}`
8989
} else {
90-
unique_key += ':new';
90+
unique_key += ':new'
9191
}
92-
92+
9393
if (commentId) {
94-
unique_key += `:edit:${commentId}`;
94+
unique_key += `:edit:${commentId}`
9595
}
9696

9797
const context: GitHubContext = {
98-
unique_key,
99-
type,
98+
commentId: commentId || undefined,
10099
domain: window.location.hostname,
101-
slug,
102100
number,
103-
commentId: commentId || undefined
104-
};
101+
slug,
102+
type,
103+
unique_key,
104+
}
105105

106-
return context;
106+
return context
107107
}
108108

109109
generateDisplayTitle(context: GitHubContext): string {
110-
const { slug, number, commentId } = context;
111-
110+
const { slug, number, commentId } = context
111+
112112
if (commentId) {
113-
return `Edit comment in ${slug}${number ? ` #${number}` : ''}`;
113+
return `Edit comment in ${slug}${number ? ` #${number}` : ''}`
114114
}
115-
115+
116116
if (number) {
117-
return `Comment on ${slug} #${number}`;
117+
return `Comment on ${slug} #${number}`
118118
}
119-
120-
return `New ${window.location.pathname.includes('/issues/') ? 'issue' : 'PR'} in ${slug}`;
119+
120+
return `New ${window.location.pathname.includes('/issues/') ? 'issue' : 'PR'} in ${slug}`
121121
}
122122

123123
generateIcon(context: GitHubContext): string {
124124
switch (context.type) {
125125
case 'GH_ISSUE_NEW':
126126
case 'GH_ISSUE_ADD_COMMENT':
127127
case 'GH_ISSUE_EDIT_COMMENT':
128-
return '🐛'; // Issue icon
128+
return '🐛' // Issue icon
129129
case 'GH_PR_NEW':
130130
case 'GH_PR_ADD_COMMENT':
131131
case 'GH_PR_EDIT_COMMENT':
132-
return '🔄'; // PR icon
132+
return '🔄' // PR icon
133133
case 'GH_PR_CODE_COMMENT':
134-
return '💬'; // Code comment icon
134+
return '💬' // Code comment icon
135135
default:
136-
return '📝'; // Generic comment icon
136+
return '📝' // Generic comment icon
137137
}
138138
}
139139

140140
buildUrl(context: GitHubContext): string {
141-
const baseUrl = `https://${context.domain}/${context.slug}`;
142-
141+
const baseUrl = `https://${context.domain}/${context.slug}`
142+
143143
if (context.number) {
144-
const type = window.location.pathname.includes('/issues/') ? 'issues' : 'pull';
145-
return `${baseUrl}/${type}/${context.number}${context.commentId ? `#issuecomment-${context.commentId}` : ''}`;
144+
const type = window.location.pathname.includes('/issues/') ? 'issues' : 'pull'
145+
return `${baseUrl}/${type}/${context.number}${context.commentId ? `#issuecomment-${context.commentId}` : ''}`
146146
}
147-
148-
return baseUrl;
147+
148+
return baseUrl
149149
}
150150

151151
private getCommentId(textarea: HTMLTextAreaElement): string | null {
152152
// Look for edit comment form indicators
153-
const commentForm = textarea.closest('[data-comment-id]');
153+
const commentForm = textarea.closest('[data-comment-id]')
154154
if (commentForm) {
155-
return commentForm.getAttribute('data-comment-id');
155+
return commentForm.getAttribute('data-comment-id')
156156
}
157-
158-
const editForm = textarea.closest('.js-comment-edit-form');
157+
158+
const editForm = textarea.closest('.js-comment-edit-form')
159159
if (editForm) {
160-
const commentContainer = editForm.closest('.js-comment-container');
160+
const commentContainer = editForm.closest('.js-comment-container')
161161
if (commentContainer) {
162-
const id = commentContainer.getAttribute('data-gid') ||
163-
commentContainer.getAttribute('id');
164-
return id ? id.replace('issuecomment-', '') : null;
162+
const id = commentContainer.getAttribute('data-gid') || commentContainer.getAttribute('id')
163+
return id ? id.replace('issuecomment-', '') : null
165164
}
166165
}
167-
168-
return null;
166+
167+
return null
169168
}
170-
}
169+
}

0 commit comments

Comments
 (0)