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

refactor(misskey-js): 警告をすべて解決 #14257

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 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
2 changes: 2 additions & 0 deletions packages/misskey-js/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import tsParser from '@typescript-eslint/parser';
import sharedConfig from '../shared/eslint.config.js';

// eslint-disable-next-line import/no-default-export
export default [
...sharedConfig,
{
Expand All @@ -26,3 +27,4 @@ export default [
},
},
];

1 change: 1 addition & 0 deletions packages/misskey-js/src/acct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type Acct = {
};

export function parse(acct: string): Acct {
// eslint-disable-next-line no-param-reassign
if (acct.startsWith('@')) acct = acct.substring(1);
Comment on lines +7 to 8
Copy link
Contributor

@tai-cha tai-cha Jul 18, 2024

Choose a reason for hiding this comment

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

これは素直にコメントで抑制するのではなく引数に上書きせずに再宣言した方がいいタイプな気がする

Copy link
Member

Choose a reason for hiding this comment

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

どうだろう...Strict modeだと arguments との影響もないしあるし正直私はno-param-reassign自体の有用性に疑問を持ってます...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

既存の振る舞いを壊さないようにASTを変えない範囲で解決したので、別のPRに分けたい気持ちがややある

const split = acct.split('@', 2);
return { username: split[0], host: split[1] || null };
Expand Down
3 changes: 3 additions & 0 deletions packages/misskey-js/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type APIError = {
code: string;
message: string;
kind: 'client' | 'server';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

潰すと多分広範囲に影響するので後のPRでやる

info: Record<string, any>;
};

Expand All @@ -29,6 +30,7 @@ export type FetchLike = (input: string, init?: {
headers: { [key in string]: string }
}) => Promise<{
status: number;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

同上

json(): Promise<any>;
}>;

Expand All @@ -49,6 +51,7 @@ export class APIClient {
this.fetch = opts.fetch ?? ((...args) => fetch(...args));
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

同上

private assertIsRecord<T>(obj: T): obj is T & Record<string, any> {
return obj !== null && typeof obj === 'object' && !Array.isArray(obj);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/misskey-js/src/api.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ type StrictExtract<Union, Cond> = Cond extends Union ? Union : never;

type IsCaseMatched<E extends keyof Endpoints, P extends Endpoints[E]['req'], C extends number> =
Endpoints[E]['res'] extends SwitchCase
// eslint-disable-next-line @typescript-eslint/no-explicit-any
? IsNeverType<StrictExtract<Endpoints[E]['res']['$switch']['$cases'][C], [P, any]>> extends false ? true : false
: false

type GetCaseResult<E extends keyof Endpoints, P extends Endpoints[E]['req'], C extends number> =
Endpoints[E]['res'] extends SwitchCase
// eslint-disable-next-line @typescript-eslint/no-explicit-any
? StrictExtract<Endpoints[E]['res']['$switch']['$cases'][C], [P, any]>[1]
: never

Expand Down
92 changes: 55 additions & 37 deletions packages/misskey-js/src/consts.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
import type { operations } from './autogen/types.js';
import type {
AbuseReportNotificationRecipient, Ad,
Announcement,
EmojiDetailed, InviteCode,
MetaDetailed,
Note,
Role, SystemWebhook, UserLite,
} from './autogen/models.js';

export const notificationTypes = ['note', 'follow', 'mention', 'reply', 'renote', 'quote', 'reaction', 'pollVote', 'pollEnded', 'receiveFollowRequest', 'followRequestAccepted', 'groupInvited', 'app', 'roleAssigned', 'achievementEarned'] as const;

export const noteVisibilities = ['public', 'home', 'followers', 'specified'] as const;
Expand Down Expand Up @@ -135,10 +145,18 @@ export const moderationLogTypes = [
'unsetUserBanner',
] as const;

type AvatarDecoration = UserLite['avatarDecorations'][number];

type ReceivedAbuseReport = {
reportId: AbuseReportNotificationRecipient['id'];
report: operations['admin___abuse-user-reports']['responses'][200]['content']['application/json'];
forwarded: boolean;
};

export type ModerationLogPayloads = {
updateServerSettings: {
before: any | null;
after: any | null;
before: MetaDetailed | null;
after: MetaDetailed | null;
};
suspend: {
userId: string;
Expand All @@ -159,16 +177,16 @@ export type ModerationLogPayloads = {
};
addCustomEmoji: {
emojiId: string;
emoji: any;
emoji: EmojiDetailed;
};
updateCustomEmoji: {
emojiId: string;
before: any;
after: any;
before: EmojiDetailed;
after: EmojiDetailed;
};
deleteCustomEmoji: {
emojiId: string;
emoji: any;
emoji: EmojiDetailed;
};
assignRole: {
userId: string;
Expand All @@ -187,16 +205,16 @@ export type ModerationLogPayloads = {
};
createRole: {
roleId: string;
role: any;
role: Role;
};
updateRole: {
roleId: string;
before: any;
after: any;
before: Role;
after: Role;
};
deleteRole: {
roleId: string;
role: any;
role: Role;
};
clearQueue: Record<string, never>;
promoteQueue: Record<string, never>;
Expand All @@ -211,39 +229,39 @@ export type ModerationLogPayloads = {
noteUserId: string;
noteUserUsername: string;
noteUserHost: string | null;
note: any;
note: Note;
};
createGlobalAnnouncement: {
announcementId: string;
announcement: any;
announcement: Announcement;
};
createUserAnnouncement: {
announcementId: string;
announcement: any;
announcement: Announcement;
userId: string;
userUsername: string;
userHost: string | null;
};
updateGlobalAnnouncement: {
announcementId: string;
before: any;
after: any;
before: Announcement;
after: Announcement;
};
updateUserAnnouncement: {
announcementId: string;
before: any;
after: any;
before: Announcement;
after: Announcement;
userId: string;
userUsername: string;
userHost: string | null;
};
deleteGlobalAnnouncement: {
announcementId: string;
announcement: any;
announcement: Announcement;
};
deleteUserAnnouncement: {
announcementId: string;
announcement: any;
announcement: Announcement;
userId: string;
userUsername: string;
userHost: string | null;
Expand Down Expand Up @@ -281,37 +299,37 @@ export type ModerationLogPayloads = {
};
resolveAbuseReport: {
reportId: string;
report: any;
report: ReceivedAbuseReport;
forwarded: boolean;
};
createInvitation: {
invitations: any[];
invitations: InviteCode[];
};
createAd: {
adId: string;
ad: any;
ad: Ad;
};
updateAd: {
adId: string;
before: any;
after: any;
before: Ad;
after: Ad;
};
deleteAd: {
adId: string;
ad: any;
ad: Ad;
};
createAvatarDecoration: {
avatarDecorationId: string;
avatarDecoration: any;
avatarDecoration: AvatarDecoration;
};
updateAvatarDecoration: {
avatarDecorationId: string;
before: any;
after: any;
before: AvatarDecoration;
after: AvatarDecoration;
};
deleteAvatarDecoration: {
avatarDecorationId: string;
avatarDecoration: any;
avatarDecoration: AvatarDecoration;
};
unsetUserAvatar: {
userId: string;
Expand All @@ -327,28 +345,28 @@ export type ModerationLogPayloads = {
};
createSystemWebhook: {
systemWebhookId: string;
webhook: any;
webhook: SystemWebhook;
};
updateSystemWebhook: {
systemWebhookId: string;
before: any;
after: any;
before: SystemWebhook;
after: SystemWebhook;
};
deleteSystemWebhook: {
systemWebhookId: string;
webhook: any;
webhook: SystemWebhook;
};
createAbuseReportNotificationRecipient: {
recipientId: string;
recipient: any;
recipient: AbuseReportNotificationRecipient;
};
updateAbuseReportNotificationRecipient: {
recipientId: string;
before: any;
after: any;
before: AbuseReportNotificationRecipient;
after: AbuseReportNotificationRecipient;
};
deleteAbuseReportNotificationRecipient: {
recipientId: string;
recipient: any;
recipient: AbuseReportNotificationRecipient;
};
};
Loading