chore: 🚨 lint megalodon

This commit is contained in:
ThatOneCalculator 2023-09-01 16:36:33 -07:00
parent 34e2f7ada6
commit a75a19cd17
No known key found for this signature in database
GPG Key ID: 8703CACD01000000
31 changed files with 301 additions and 284 deletions

View File

@ -16,7 +16,7 @@
"build": "pnpm swc src -d built -D",
"build:debug": "pnpm swc src -d built -s -D",
"watch": "pnpm swc src -d built -D -w",
"lint": "pnpm rome check --apply **/*.ts",
"lint": "pnpm rome check --apply **/*.ts ; pnpm run format",
"mocha": "cross-env NODE_ENV=test TS_NODE_FILES=true TS_NODE_TRANSPILE_ONLY=true TS_NODE_PROJECT=\"./test/tsconfig.json\" mocha",
"test": "pnpm run mocha",
"format": "pnpm rome format * --write"

View File

@ -1514,7 +1514,7 @@ export default class Misskey implements MegalodonInterface {
if (status.quote != null)
status.quote = await this.addMentionsToStatus(status.quote, cache);
const idx = status.account.acct.indexOf('@');
const idx = status.account.acct.indexOf("@");
const origin = idx < 0 ? null : status.account.acct.substring(idx + 1);
status.mentions = (
@ -1523,22 +1523,25 @@ export default class Misskey implements MegalodonInterface {
for (const m of status.mentions.filter(
(value, index, array) => array.indexOf(value) === index,
)) {
const regexFull = new RegExp(`(?<=^|\\s|>)@${m.acct}(?=[^a-zA-Z0-9]|$)`, 'gi');
const regexLocalUser = new RegExp(`(?<=^|\\s|>)@${m.acct}@${this.baseUrlToHost(this.baseUrl)}(?=[^a-zA-Z0-9]|$)`, 'gi');
const regexRemoteUser = new RegExp(`(?<=^|\\s|>)@${m.username}(?=[^a-zA-Z0-9@]|$)`, 'gi');
const regexFull = new RegExp(
`(?<=^|\\s|>)@${m.acct}(?=[^a-zA-Z0-9]|$)`,
"gi",
);
const regexLocalUser = new RegExp(
`(?<=^|\\s|>)@${m.acct}@${this.baseUrlToHost(
this.baseUrl,
)}(?=[^a-zA-Z0-9]|$)`,
"gi",
);
const regexRemoteUser = new RegExp(
`(?<=^|\\s|>)@${m.username}(?=[^a-zA-Z0-9@]|$)`,
"gi",
);
if (m.acct == m.username) {
status.content = status.content.replace(
regexLocalUser,
`@${m.acct}`,
);
}
else if (!status.content.match(regexFull)) {
status.content = status.content.replace(
regexRemoteUser,
`@${m.acct}`,
);
status.content = status.content.replace(regexLocalUser, `@${m.acct}`);
} else if (!status.content.match(regexFull)) {
status.content = status.content.replace(regexRemoteUser, `@${m.acct}`);
}
status.content = status.content.replace(
@ -2015,7 +2018,10 @@ export default class Misskey implements MegalodonInterface {
*/
private reactionName(name: string): string {
// See: https://github.com/tc39/proposal-regexp-unicode-property-escapes#matching-emoji
const isUnicodeEmoji = /\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F/gu.test(name);
const isUnicodeEmoji =
/\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F/gu.test(
name,
);
if (isUnicodeEmoji) {
return name;
}
@ -2025,7 +2031,10 @@ export default class Misskey implements MegalodonInterface {
/**
* POST /api/notes/reactions/create
*/
public async reactStatus(id: string, name: string): Promise<Response<Entity.Status>> {
public async reactStatus(
id: string,
name: string,
): Promise<Response<Entity.Status>> {
await this.client.post<{}>("/api/notes/reactions/create", {
noteId: id,
reaction: this.reactionName(name),
@ -2047,7 +2056,10 @@ export default class Misskey implements MegalodonInterface {
/**
* POST /api/notes/reactions/delete
*/
public async unreactStatus(id: string, name: string): Promise<Response<Entity.Status>> {
public async unreactStatus(
id: string,
name: string,
): Promise<Response<Entity.Status>> {
await this.client.post<{}>("/api/notes/reactions/delete", {
noteId: id,
reaction: this.reactionName(name),
@ -3037,7 +3049,9 @@ export default class Misskey implements MegalodonInterface {
}
try {
const match = q.match(/^@(?<user>[a-zA-Z0-9_]+)(?:@(?<host>[a-zA-Z0-9-.]+\.[a-zA-Z0-9-]+)|)$/);
const match = q.match(
/^@(?<user>[a-zA-Z0-9_]+)(?:@(?<host>[a-zA-Z0-9-.]+\.[a-zA-Z0-9-]+)|)$/,
);
if (match) {
const lookupQuery = {
username: match.groups?.user,

View File

@ -1,6 +1,6 @@
namespace MisskeyEntity {
export type GetAll = {
tutorial: number
defaultNoteVisibility: 'public' | 'home' | 'followers' | 'specified'
}
export type GetAll = {
tutorial: number;
defaultNoteVisibility: "public" | "home" | "followers" | "specified";
};
}

View File

@ -1,10 +1,10 @@
namespace MisskeyEntity {
export type Announcement = {
id: string
createdAt: string
updatedAt: string
text: string
title: string
isRead?: boolean
}
export type Announcement = {
id: string;
createdAt: string;
updatedAt: string;
text: string;
title: string;
isRead?: boolean;
};
}

View File

@ -1,9 +1,9 @@
namespace MisskeyEntity {
export type App = {
id: string
name: string
callbackUrl: string
permission: Array<string>
secret: string
}
export type App = {
id: string;
name: string;
callbackUrl: string;
permission: Array<string>;
secret: string;
};
}

View File

@ -1,10 +1,10 @@
/// <reference path="userDetail.ts" />
namespace MisskeyEntity {
export type Blocking = {
id: string
createdAt: string
blockeeId: string
blockee: UserDetail
}
export type Blocking = {
id: string;
createdAt: string;
blockeeId: string;
blockee: UserDetail;
};
}

View File

@ -1,7 +1,7 @@
/// <reference path="note.ts" />
namespace MisskeyEntity {
export type CreatedNote = {
createdNote: Note
}
export type CreatedNote = {
createdNote: Note;
};
}

View File

@ -1,9 +1,9 @@
namespace MisskeyEntity {
export type Emoji = {
name: string
host: string | null
url: string
aliases: Array<string>
category: string
}
export type Emoji = {
name: string;
host: string | null;
url: string;
aliases: Array<string>;
category: string;
};
}

View File

@ -1,10 +1,10 @@
/// <reference path="note.ts" />
namespace MisskeyEntity {
export type Favorite = {
id: string
createdAt: string
noteId: string
note: Note
}
export type Favorite = {
id: string;
createdAt: string;
noteId: string;
note: Note;
};
}

View File

@ -1,7 +1,7 @@
namespace MisskeyEntity {
export type Field = {
name: string
value: string
verified?: string
}
export type Field = {
name: string;
value: string;
verified?: string;
};
}

View File

@ -1,20 +1,20 @@
namespace MisskeyEntity {
export type File = {
id: string
createdAt: string
name: string
type: string
md5: string
size: number
isSensitive: boolean
properties: {
width: number
height: number
avgColor: string
}
url: string
thumbnailUrl: string
comment: string
blurhash: string
}
export type File = {
id: string;
createdAt: string;
name: string;
type: string;
md5: string;
size: number;
isSensitive: boolean;
properties: {
width: number;
height: number;
avgColor: string;
};
url: string;
thumbnailUrl: string;
comment: string;
blurhash: string;
};
}

View File

@ -1,9 +1,9 @@
/// <reference path="user.ts" />
namespace MisskeyEntity {
export type FollowRequest = {
id: string
follower: User
followee: User
}
export type FollowRequest = {
id: string;
follower: User;
followee: User;
};
}

View File

@ -1,11 +1,11 @@
/// <reference path="userDetail.ts" />
namespace MisskeyEntity {
export type Follower = {
id: string
createdAt: string
followeeId: string
followerId: string
follower: UserDetail
}
export type Follower = {
id: string;
createdAt: string;
followeeId: string;
followerId: string;
follower: UserDetail;
};
}

View File

@ -1,11 +1,11 @@
/// <reference path="userDetail.ts" />
namespace MisskeyEntity {
export type Following = {
id: string
createdAt: string
followeeId: string
followerId: string
followee: UserDetail
}
export type Following = {
id: string;
createdAt: string;
followeeId: string;
followerId: string;
followee: UserDetail;
};
}

View File

@ -1,7 +1,7 @@
namespace MisskeyEntity {
export type Hashtag = {
tag: string
chart: Array<number>
usersCount: number
}
export type Hashtag = {
tag: string;
chart: Array<number>;
usersCount: number;
};
}

View File

@ -1,8 +1,8 @@
namespace MisskeyEntity {
export type List = {
id: string
createdAt: string
name: string
userIds: Array<string>
}
export type List = {
id: string;
createdAt: string;
name: string;
userIds: Array<string>;
};
}

View File

@ -1,18 +1,18 @@
/// <reference path="emoji.ts" />
namespace MisskeyEntity {
export type Meta = {
maintainerName: string
maintainerEmail: string
name: string
version: string
uri: string
description: string
langs: Array<string>
disableRegistration: boolean
disableLocalTimeline: boolean
bannerUrl: string
maxNoteTextLength: 3000
emojis: Array<Emoji>
}
export type Meta = {
maintainerName: string;
maintainerEmail: string;
name: string;
version: string;
uri: string;
description: string;
langs: Array<string>;
disableRegistration: boolean;
disableLocalTimeline: boolean;
bannerUrl: string;
maxNoteTextLength: 3000;
emojis: Array<Emoji>;
};
}

View File

@ -1,10 +1,10 @@
/// <reference path="userDetail.ts" />
namespace MisskeyEntity {
export type Mute = {
id: string
createdAt: string
muteeId: string
mutee: UserDetail
}
export type Mute = {
id: string;
createdAt: string;
muteeId: string;
mutee: UserDetail;
};
}

View File

@ -4,29 +4,29 @@
/// <reference path="poll.ts" />
namespace MisskeyEntity {
export type Note = {
id: string
createdAt: string
userId: string
user: User
text: string | null
cw: string | null
visibility: 'public' | 'home' | 'followers' | 'specified'
renoteCount: number
repliesCount: number
reactions: { [key: string]: number }
emojis: Array<Emoji>
fileIds: Array<string>
files: Array<File>
replyId: string | null
renoteId: string | null
uri?: string
reply?: Note
renote?: Note
viaMobile?: boolean
tags?: Array<string>
poll?: Poll
mentions?: Array<string>
myReaction?: string
}
export type Note = {
id: string;
createdAt: string;
userId: string;
user: User;
text: string | null;
cw: string | null;
visibility: "public" | "home" | "followers" | "specified";
renoteCount: number;
repliesCount: number;
reactions: { [key: string]: number };
emojis: Array<Emoji>;
fileIds: Array<string>;
files: Array<File>;
replyId: string | null;
renoteId: string | null;
uri?: string;
reply?: Note;
renote?: Note;
viaMobile?: boolean;
tags?: Array<string>;
poll?: Poll;
mentions?: Array<string>;
myReaction?: string;
};
}

View File

@ -2,16 +2,16 @@
/// <reference path="note.ts" />
namespace MisskeyEntity {
export type Notification = {
id: string
createdAt: string
// https://github.com/syuilo/misskey/blob/056942391aee135eb6c77aaa63f6ed5741d701a6/src/models/entities/notification.ts#L50-L62
type: NotificationType
userId: string
user: User
note?: Note
reaction?: string
}
export type Notification = {
id: string;
createdAt: string;
// https://github.com/syuilo/misskey/blob/056942391aee135eb6c77aaa63f6ed5741d701a6/src/models/entities/notification.ts#L50-L62
type: NotificationType;
userId: string;
user: User;
note?: Note;
reaction?: string;
};
export type NotificationType = string
export type NotificationType = string;
}

View File

@ -1,13 +1,13 @@
namespace MisskeyEntity {
export type Choice = {
text: string
votes: number
isVoted: boolean
}
export type Choice = {
text: string;
votes: number;
isVoted: boolean;
};
export type Poll = {
multiple: boolean
expiresAt: string
choices: Array<Choice>
}
export type Poll = {
multiple: boolean;
expiresAt: string;
choices: Array<Choice>;
};
}

View File

@ -1,11 +1,11 @@
/// <reference path="user.ts" />
namespace MisskeyEntity {
export type Reaction = {
id: string
createdAt: string
user: User
url?: string
type: string
}
export type Reaction = {
id: string;
createdAt: string;
user: User;
url?: string;
type: string;
};
}

View File

@ -1,12 +1,12 @@
namespace MisskeyEntity {
export type Relation = {
id: string
isFollowing: boolean
hasPendingFollowRequestFromYou: boolean
hasPendingFollowRequestToYou: boolean
isFollowed: boolean
isBlocking: boolean
isBlocked: boolean
isMuted: boolean
}
export type Relation = {
id: string;
isFollowing: boolean;
hasPendingFollowRequestFromYou: boolean;
hasPendingFollowRequestToYou: boolean;
isFollowed: boolean;
isBlocking: boolean;
isBlocked: boolean;
isMuted: boolean;
};
}

View File

@ -1,6 +1,6 @@
namespace MisskeyEntity {
export type Session = {
token: string
url: string
}
export type Session = {
token: string;
url: string;
};
}

View File

@ -1,7 +1,7 @@
namespace MisskeyEntity {
export type State = {
isFavorited: boolean
isMutedThread: boolean
isWatching: boolean
}
export type State = {
isFavorited: boolean;
isMutedThread: boolean;
isWatching: boolean;
};
}

View File

@ -1,9 +1,9 @@
namespace MisskeyEntity {
export type Stats = {
notesCount: number
originalNotesCount: number
usersCount: number
originalUsersCount: number
instances: number
}
export type Stats = {
notesCount: number;
originalNotesCount: number;
usersCount: number;
originalUsersCount: number;
instances: number;
};
}

View File

@ -1,13 +1,13 @@
/// <reference path="emoji.ts" />
namespace MisskeyEntity {
export type User = {
id: string
name: string
username: string
host: string | null
avatarUrl: string
avatarColor: string
emojis: Array<Emoji>
}
export type User = {
id: string;
name: string;
username: string;
host: string | null;
avatarUrl: string;
avatarColor: string;
emojis: Array<Emoji>;
};
}

View File

@ -3,32 +3,32 @@
/// <reference path="note.ts" />
namespace MisskeyEntity {
export type UserDetail = {
id: string
name: string
username: string
host: string | null
avatarUrl: string
avatarColor: string
isAdmin: boolean
isModerator: boolean
isBot: boolean
isCat: boolean
emojis: Array<Emoji>
createdAt: string
bannerUrl: string
bannerColor: string
isLocked: boolean
isSilenced: boolean
isSuspended: boolean
description: string
followersCount: number
followingCount: number
notesCount: number
avatarId: string
bannerId: string
pinnedNoteIds?: Array<string>
pinnedNotes?: Array<Note>
fields: Array<Field>
}
export type UserDetail = {
id: string;
name: string;
username: string;
host: string | null;
avatarUrl: string;
avatarColor: string;
isAdmin: boolean;
isModerator: boolean;
isBot: boolean;
isCat: boolean;
emojis: Array<Emoji>;
createdAt: string;
bannerUrl: string;
bannerColor: string;
isLocked: boolean;
isSilenced: boolean;
isSuspended: boolean;
description: string;
followersCount: number;
followingCount: number;
notesCount: number;
avatarId: string;
bannerId: string;
pinnedNoteIds?: Array<string>;
pinnedNotes?: Array<Note>;
fields: Array<Field>;
};
}

View File

@ -3,34 +3,34 @@
/// <reference path="note.ts" />
namespace MisskeyEntity {
export type UserDetailMe = {
id: string
name: string
username: string
host: string | null
avatarUrl: string
avatarColor: string
isAdmin: boolean
isModerator: boolean
isBot: boolean
isCat: boolean
emojis: Array<Emoji>
createdAt: string
bannerUrl: string
bannerColor: string
isLocked: boolean
isSilenced: boolean
isSuspended: boolean
description: string
followersCount: number
followingCount: number
notesCount: number
avatarId: string
bannerId: string
pinnedNoteIds?: Array<string>
pinnedNotes?: Array<Note>
fields: Array<Field>
alwaysMarkNsfw: boolean
lang: string | null
}
export type UserDetailMe = {
id: string;
name: string;
username: string;
host: string | null;
avatarUrl: string;
avatarColor: string;
isAdmin: boolean;
isModerator: boolean;
isBot: boolean;
isCat: boolean;
emojis: Array<Emoji>;
createdAt: string;
bannerUrl: string;
bannerColor: string;
isLocked: boolean;
isSilenced: boolean;
isSuspended: boolean;
description: string;
followersCount: number;
followingCount: number;
notesCount: number;
avatarId: string;
bannerId: string;
pinnedNoteIds?: Array<string>;
pinnedNotes?: Array<Note>;
fields: Array<Field>;
alwaysMarkNsfw: boolean;
lang: string | null;
};
}

View File

@ -1,8 +1,8 @@
/// <reference path="user.ts" />
namespace MisskeyEntity {
export type UserKey = {
accessToken: string
user: User
}
export type UserKey = {
accessToken: string;
user: User;
};
}

View File

@ -20,6 +20,9 @@
"*/model.json",
"*.md",
"*.spec.ts",
"*.png",
"*.jpeg",
"*.jpg",
"**/tsconfig.json",
"*/.yml"
]