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

Update eslint, stylelint packages (major) #509

Merged
merged 5 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@
"no-multi-spaces": ["off"],
"no-return-assign": ["off"],
"@typescript-eslint/indent": ["error", 4],
"@typescript-eslint/semi": ["error", "always"],
"@typescript-eslint/object-curly-spacing": ["error", "never"],
"@typescript-eslint/space-before-function-paren": ["error", "never"],
"@typescript-eslint/promise-function-async": ["off"],
"@typescript-eslint/no-confusing-void-expression": ["error", {"ignoreArrowShorthand": true}],
"@typescript-eslint/no-extraneous-class": ["off"],
"@typescript-eslint/no-invalid-void-type": ["off", {"allowAsThisParameter": true}],
"@typescript-eslint/no-unnecessary-boolean-literal-compare": ["off"],
"@typescript-eslint/object-curly-spacing": ["error", "never"],
"@typescript-eslint/promise-function-async": ["off"],
"@typescript-eslint/restrict-template-expressions": ["off"],
"@typescript-eslint/semi": ["error", "always"],
"@typescript-eslint/space-before-function-paren": ["error", "never"],
"@typescript-eslint/unbound-method": ["off"],
"@typescript-eslint/member-delimiter-style": [
"error",
{
Expand Down
3 changes: 2 additions & 1 deletion assets/ts/controllers/browser_notification_controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Controller} from '@hotwired/stimulus';
import type MercureEvent from '../entity/MercureEvent';
import BrowserNotification from '../lib/BrowserNotification';

export default class extends Controller {
Expand All @@ -12,7 +13,7 @@ export default class extends Controller {
}

private handleNotification(event: Event): void {
const data = (event as CustomEvent).detail;
const data = (event as CustomEvent<MercureEvent>).detail;
this.notification.publish(data.title, data.message, 'tag-' + String(data.eventId), data.url);
}
}
2 changes: 1 addition & 1 deletion assets/ts/controllers/comment_thread_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class extends Controller<HTMLElement> {
private readonly declare idValue: number;
private readonly declare urlValue: string;

public commentUpdated(event: CustomEvent): void {
public commentUpdated(event: CustomEvent<string>): void {
Events.stop(event);
if (parseInt(event.detail) !== this.idValue) {
return;
Expand Down
9 changes: 6 additions & 3 deletions assets/ts/controllers/review_notification_list_controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Controller} from '@hotwired/stimulus';
import type MercureEvent from '../entity/MercureEvent';

export default class extends Controller {
public static targets = ['template'];
Expand All @@ -23,7 +24,7 @@ export default class extends Controller {
}

private handleNotification(event: Event): void {
const data = (event as CustomEvent).detail;
const data = (event as CustomEvent<MercureEvent>).detail;

// skip notifications from me
if (data.userId === this.userIdValue) {
Expand All @@ -40,8 +41,10 @@ export default class extends Controller {

private createItem(message: string): HTMLElement {
const clone = this.templateTarget.content.cloneNode(true) as HTMLElement;

(clone.querySelector('[data-role=item]') as HTMLElement).innerHTML = message;
const item = clone.querySelector<HTMLElement>('[data-role=item]');
if (item !== null) {
item.innerHTML = message;
}
return clone;
}
}
5 changes: 3 additions & 2 deletions assets/ts/controllers/server_event_controller.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {Controller} from '@hotwired/stimulus';
import type MercureEvent from '../entity/MercureEvent';
import DataSet from '../lib/DataSet';

export default class extends Controller<HTMLElement> {
public connect(): void {
const publishUrl = DataSet.string(this.element, 'url');
const eventSource = new EventSource(publishUrl, {withCredentials: true});
eventSource.onmessage = (event) => {
const data = JSON.parse(event.data);
eventSource.onmessage = (event: MessageEvent<string>) => {
const data = JSON.parse(event.data) as MercureEvent;
document.dispatchEvent(new CustomEvent(data.topic, {detail: data}));
};

Expand Down
6 changes: 5 additions & 1 deletion assets/ts/controllers/textarea_paste_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export default class extends Controller<HTMLTextAreaElement> {
return;
}

const item = event.clipboardData.items[0] as DataTransferItem;
const item = event.clipboardData.items[0];
if (item === undefined) {
return;
}

const allowedMimes = ['image/png', 'image/gif', 'image/jpg', 'image/jpeg'];
if (item.kind !== 'file' || allowedMimes.includes(item.type) === false) {
return;
Expand Down
9 changes: 9 additions & 0 deletions assets/ts/entity/MercureEvent.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default interface MercureEvent {
eventId: 1;
eventName: string;
topic: string;
userId: number;
title: string;
message: string;
url: string;
}
2 changes: 1 addition & 1 deletion assets/ts/lib/Errors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export default class Errors {
public static catch(error: any): void {
public static catch(this: void, error: any): void {
// handle Axios error response
if (error.response?.data?.error !== undefined) {
alert(error.response.data.error);
Expand Down
1 change: 1 addition & 0 deletions assets/ts/lib/Mentions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export default class Mentions {
const params = new URLSearchParams({search: searchQuery ?? '', preferredUserIds: this.preferredUserIds.join(',')});
axios
.get('/app/user/mentions?' + params.toString())
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
.then(response => callback(response.data))
.catch(Function.empty);
}
Expand Down
4 changes: 2 additions & 2 deletions assets/ts/service/CommentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class CommentService {
public getAddCommentForm(url: string, oldPath: string, newPath: string, line: number, offset: number, lineAfter: number, headSha: string, state: string): Promise<HTMLElement> {
return this.client
.get(url, {params: {oldPath, newPath, line, offset, lineAfter, state, headSha}})
.then(response => response.data)
.then(response => (response.data as string))
.then(html => Elements.create(html));
}

Expand All @@ -34,7 +34,7 @@ export default class CommentService {

return this.client
.get(url, params)
.then(response => response.data)
.then(response => (response.data as string))
.then(html => Elements.create(html));
}

Expand Down
2 changes: 1 addition & 1 deletion assets/ts/service/ReviewFileTreeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default class ReviewFileTreeService {
public getReviewFileTree(url: string, filePath: string | null): Promise<HTMLElement> {
return this.client
.get(url, {params: {filePath}})
.then(response => response.data)
.then(response => (response.data as string))
.then(html => Elements.create(html));
}
}
Loading