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": "pnpm swc src -d built -D",
"build:debug": "pnpm swc src -d built -s -D", "build:debug": "pnpm swc src -d built -s -D",
"watch": "pnpm swc src -d built -D -w", "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", "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", "test": "pnpm run mocha",
"format": "pnpm rome format * --write" "format": "pnpm rome format * --write"

View File

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

View File

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

View File

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

View File

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

View File

@ -2,9 +2,9 @@
namespace MisskeyEntity { namespace MisskeyEntity {
export type Blocking = { export type Blocking = {
id: string id: string;
createdAt: string createdAt: string;
blockeeId: string blockeeId: string;
blockee: UserDetail blockee: UserDetail;
} };
} }

View File

@ -2,6 +2,6 @@
namespace MisskeyEntity { namespace MisskeyEntity {
export type CreatedNote = { export type CreatedNote = {
createdNote: Note createdNote: Note;
} };
} }

View File

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

View File

@ -2,9 +2,9 @@
namespace MisskeyEntity { namespace MisskeyEntity {
export type Favorite = { export type Favorite = {
id: string id: string;
createdAt: string createdAt: string;
noteId: string noteId: string;
note: Note note: Note;
} };
} }

View File

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

View File

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

View File

@ -2,8 +2,8 @@
namespace MisskeyEntity { namespace MisskeyEntity {
export type FollowRequest = { export type FollowRequest = {
id: string id: string;
follower: User follower: User;
followee: User followee: User;
} };
} }

View File

@ -2,10 +2,10 @@
namespace MisskeyEntity { namespace MisskeyEntity {
export type Follower = { export type Follower = {
id: string id: string;
createdAt: string createdAt: string;
followeeId: string followeeId: string;
followerId: string followerId: string;
follower: UserDetail follower: UserDetail;
} };
} }

View File

@ -2,10 +2,10 @@
namespace MisskeyEntity { namespace MisskeyEntity {
export type Following = { export type Following = {
id: string id: string;
createdAt: string createdAt: string;
followeeId: string followeeId: string;
followerId: string followerId: string;
followee: UserDetail followee: UserDetail;
} };
} }

View File

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

View File

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

View File

@ -2,17 +2,17 @@
namespace MisskeyEntity { namespace MisskeyEntity {
export type Meta = { export type Meta = {
maintainerName: string maintainerName: string;
maintainerEmail: string maintainerEmail: string;
name: string name: string;
version: string version: string;
uri: string uri: string;
description: string description: string;
langs: Array<string> langs: Array<string>;
disableRegistration: boolean disableRegistration: boolean;
disableLocalTimeline: boolean disableLocalTimeline: boolean;
bannerUrl: string bannerUrl: string;
maxNoteTextLength: 3000 maxNoteTextLength: 3000;
emojis: Array<Emoji> emojis: Array<Emoji>;
} };
} }

View File

@ -2,9 +2,9 @@
namespace MisskeyEntity { namespace MisskeyEntity {
export type Mute = { export type Mute = {
id: string id: string;
createdAt: string createdAt: string;
muteeId: string muteeId: string;
mutee: UserDetail mutee: UserDetail;
} };
} }

View File

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

View File

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

View File

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

View File

@ -2,10 +2,10 @@
namespace MisskeyEntity { namespace MisskeyEntity {
export type Reaction = { export type Reaction = {
id: string id: string;
createdAt: string createdAt: string;
user: User user: User;
url?: string url?: string;
type: string type: string;
} };
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -2,12 +2,12 @@
namespace MisskeyEntity { namespace MisskeyEntity {
export type User = { export type User = {
id: string id: string;
name: string name: string;
username: string username: string;
host: string | null host: string | null;
avatarUrl: string avatarUrl: string;
avatarColor: string avatarColor: string;
emojis: Array<Emoji> emojis: Array<Emoji>;
} };
} }

View File

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

View File

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

View File

@ -2,7 +2,7 @@
namespace MisskeyEntity { namespace MisskeyEntity {
export type UserKey = { export type UserKey = {
accessToken: string accessToken: string;
user: User user: User;
} };
} }

View File

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