-
Notifications
You must be signed in to change notification settings - Fork 58
Enable more lints #897
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
Enable more lints #897
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -223,6 +223,7 @@ import { CreatePostWarning } from "./types/CreatePostWarning"; | |
| import { CreateCommentWarning } from "./types/CreateCommentWarning"; | ||
| import { GetMultiCommunity } from "./types/GetMultiCommunity"; | ||
| import { ListMultiCommunities } from "./types/ListMultiCommunities"; | ||
| import { UserSettingsBackup } from "./types/UserSettingsBackup"; | ||
|
|
||
| enum HttpType { | ||
| Get = "GET", | ||
|
|
@@ -240,7 +241,7 @@ type RequestOptions = Pick<RequestInit, "signal">; | |
| export class LemmyHttp extends Controller { | ||
| #apiUrl: string; | ||
| #headers: { [key: string]: string } = {}; | ||
| #fetchFunction: typeof fetch = fetch.bind(globalThis); | ||
| #fetchFunction = fetch.bind(globalThis) as typeof fetch; | ||
|
|
||
| /** | ||
| * Generates a new instance of LemmyHttp. | ||
|
|
@@ -386,7 +387,10 @@ export class LemmyHttp extends Controller { | |
| @Security("bearerAuth") | ||
| @Post("/account/settings/import") | ||
| @Tags("Account") | ||
| async importSettings(@Body() form: any, @Inject() options?: RequestOptions) { | ||
| async importSettings( | ||
| @Body() form: UserSettingsBackup, | ||
| @Inject() options?: RequestOptions, | ||
| ) { | ||
| return this.#wrapper<object, SuccessResponse>( | ||
| HttpType.Post, | ||
| "/account/settings/import", | ||
|
|
@@ -671,7 +675,7 @@ export class LemmyHttp extends Controller { | |
| @Get("/account/unread_counts") | ||
| @Tags("Account") | ||
| async getUnreadCounts(@Inject() options?: RequestOptions) { | ||
| return this.#wrapper<{}, UnreadCountsResponse>( | ||
| return this.#wrapper<object, UnreadCountsResponse>( | ||
| HttpType.Get, | ||
| "/account/unread_counts", | ||
| {}, | ||
|
|
@@ -2876,7 +2880,7 @@ export class LemmyHttp extends Controller { | |
| body: formData as unknown as BodyInit, | ||
| headers: this.#headers, | ||
| }); | ||
| return response.json(); | ||
| return response.json() as ResponseType; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Surprised this needs an
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one actually throws an error: |
||
| } | ||
|
|
||
| async #uploadWithQuery<QueryType extends object, ResponseType>( | ||
|
|
@@ -2918,8 +2922,7 @@ export class LemmyHttp extends Controller { | |
| }); | ||
| } | ||
|
|
||
| let json: any | undefined; | ||
|
|
||
| let json: unknown; | ||
| try { | ||
| json = await response.json(); | ||
| } catch { | ||
|
|
@@ -2930,14 +2933,15 @@ export class LemmyHttp extends Controller { | |
| console.error( | ||
| `Request error while calling ${type_} ${endpoint} with ${JSON.stringify(form)}`, | ||
| ); | ||
| let err = new LemmyError( | ||
| json.error ?? response.statusText, | ||
| const json2 = json as LemmyErrorDummy; | ||
| const err = new LemmyError( | ||
| json2.error ?? response.statusText, | ||
| response.status, | ||
| json.message, | ||
| json2.message ?? "", | ||
| ); | ||
| throw err; | ||
| } else { | ||
| return json; | ||
| return json as ResponseType; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -2949,6 +2953,11 @@ export class LemmyHttp extends Controller { | |
| } | ||
| } | ||
|
|
||
| interface LemmyErrorDummy { | ||
| error: string; | ||
| message?: string; | ||
| } | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had to add this because
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't that accurate? shouldn't it be then json2.message ?? ""
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems your right. Strange that there is no lint error.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But then you should be able to use LemmyErrorType ? its basically the same definition, every option has error but some have message?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No it throws this error:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just make
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not working: |
||
|
|
||
| function encodeGetParams<BodyType extends object>(p: BodyType): string { | ||
| return Object.entries(p) | ||
| .filter(kv => kv[1] !== undefined && kv[1] !== null) | ||
|
|
@@ -2957,7 +2966,7 @@ function encodeGetParams<BodyType extends object>(p: BodyType): string { | |
| } | ||
|
|
||
| function createFormData(image: File | Buffer): FormData { | ||
| let formData = new FormData(); | ||
| const formData = new FormData(); | ||
|
|
||
| if (image instanceof File) { | ||
| formData.append("images[]", image); | ||
|
|
@@ -2983,9 +2992,14 @@ export class LemmyError extends Error { | |
| name: string; | ||
| status: number; | ||
| message: string; | ||
| cause: any; | ||
| cause: unknown; | ||
|
|
||
| constructor(name: string, status: number, message: string = "", cause?: any) { | ||
| constructor( | ||
| name: string, | ||
| status: number, | ||
| message: string = "", | ||
| cause?: unknown, | ||
| ) { | ||
| super(); | ||
| this.name = name; | ||
| this.message = message; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| /* eslint-disable @typescript-eslint/no-empty-object-type */ | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Errors about the empty interface definitions below. It suggests using
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TSOA fails with type aliases and @queries decorator. So it wouldnt work. But I have PR to fix that and then you can get rid of these below |
||
| import { AdminListUsers } from "./types/AdminListUsers"; | ||
| import { CommunityIdQuery } from "./types/CommunityIdQuery"; | ||
| import { DeleteImageParams } from "./types/DeleteImageParams"; | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably needs prettier, and the woodpecker prettier lint should also check this file.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, wasnt running prettier in CI at all. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe its not finding any because rules here is empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing this line makes no difference.