Skip to content

Commit 5f194bf

Browse files
committed
chore: fix lint errors; tweak lint rules
1 parent 9b3d6f5 commit 5f194bf

File tree

115 files changed

+173
-261
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+173
-261
lines changed

.eslintrc.js

+12
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,17 @@ module.exports = {
1212
"@typescript-eslint/no-explicit-any": 0,
1313
"@typescript-eslint/ban-ts-comment": 0,
1414
"@typescript-eslint/no-non-null-assertion": 0,
15+
"no-async-promise-executor": 0,
16+
"@typescript-eslint/no-empty-interface": 0,
17+
"no-constant-condition": ["error", {
18+
checkLoops: false,
19+
}],
20+
"prefer-const": ["error", {
21+
destructuring: "all",
22+
ignoreReadBeforeAssign: true,
23+
}],
24+
"@typescript-eslint/no-namespace": ["error", {
25+
allowDeclarations: true,
26+
}],
1527
},
1628
};

backend/src/SimpleError.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class SimpleError extends Error {
77
super(message);
88
}
99

10-
[util.inspect.custom](depth, options) {
10+
[util.inspect.custom]() {
1111
return `Error: ${this.message}`;
1212
}
1313
}

backend/src/api/auth.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ interface IPassportApiUser {
1818

1919
declare global {
2020
namespace Express {
21-
// tslint:disable-next-line:no-empty-interface
2221
interface User extends IPassportApiUser {}
2322
}
2423
}
@@ -151,6 +150,7 @@ export function initAuth(app: express.Express) {
151150
export function apiTokenAuthHandlers() {
152151
return [
153152
passport.authenticate("api-token", { failWithError: true }),
153+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
154154
(err, req: Request, res: Response, next) => {
155155
return res.status(401).json({ error: err.message });
156156
},

backend/src/api/guilds/importExport.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export function initGuildsImportExportAPI(guildRouter: express.Router) {
5050
importExportRouter.get(
5151
"/:guildId/pre-import",
5252
requireGuildPermission(ApiPermissions.ManageAccess),
53-
async (req: Request, res: Response) => {
53+
async (req: Request) => {
5454
const guildCases = GuildCases.getGuildInstance(req.params.guildId);
5555
const minNum = await guildCases.getMinCaseNumber();
5656
const maxNum = await guildCases.getMaxCaseNumber();

backend/src/api/responses.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export function unauthorized(res: Response) {
44
res.status(403).json({ error: "Unauthorized" });
55
}
66

7-
export function error(res: Response, message: string, statusCode: number = 500) {
7+
export function error(res: Response, message: string, statusCode = 500) {
88
res.status(statusCode).json({ error: message });
99
}
1010

backend/src/api/start.ts

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ app.get("/", (req, res) => {
3535
});
3636

3737
// Error response
38+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
3839
app.use((err, req, res, next) => {
3940
if (err instanceof TokenError) {
4041
clientError(res, "Invalid code");
@@ -45,6 +46,7 @@ app.use((err, req, res, next) => {
4546
});
4647

4748
// 404 response
49+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
4850
app.use((req, res, next) => {
4951
return notFound(res);
5052
});

backend/src/commandTypes.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export const commandTypes = {
9696
throw new TypeConversionError(`Could not parse ID: \`${escapeInlineCode(value)}\``);
9797
},
9898

99-
regex(value: string, context: CommandContext<any>): RegExp {
99+
regex(value: string): RegExp {
100100
try {
101101
return inputPatternToRegExp(value);
102102
} catch (e) {

backend/src/data/BaseGuildRepository.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BaseRepository } from "./BaseRepository";
22

3-
export class BaseGuildRepository<TEntity extends unknown = unknown> extends BaseRepository<TEntity> {
3+
export class BaseGuildRepository<TEntity = unknown> extends BaseRepository<TEntity> {
44
private static guildInstances: Map<string, any>;
55

66
protected guildId: string;

backend/src/data/BaseRepository.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { asyncMap } from "../utils/async";
22

3-
export class BaseRepository<TEntity extends unknown = unknown> {
3+
export class BaseRepository<TEntity = unknown> {
44
private nextRelations: string[];
55

66
constructor() {

backend/src/data/Configs.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@ import { cleanupConfigs } from "./cleanup/configs";
66
import { connection } from "./db";
77
import { Config } from "./entities/Config";
88

9-
if (isAPI()) {
10-
const CLEANUP_INTERVAL = 1 * HOURS;
9+
const CLEANUP_INTERVAL = 1 * HOURS;
1110

12-
async function cleanup() {
13-
await cleanupConfigs();
14-
setTimeout(cleanup, CLEANUP_INTERVAL);
15-
}
11+
async function cleanup() {
12+
await cleanupConfigs();
13+
setTimeout(cleanup, CLEANUP_INTERVAL);
14+
}
1615

16+
if (isAPI()) {
1717
// Start first cleanup 30 seconds after startup
18+
// TODO: Move to bot startup code
1819
setTimeout(cleanup, 30 * SECONDS);
1920
}
2021

backend/src/data/GuildCases.ts

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import { connection } from "./db";
77
import { Case } from "./entities/Case";
88
import { CaseNote } from "./entities/CaseNote";
99

10-
const CASE_SUMMARY_REASON_MAX_LENGTH = 300;
11-
1210
export class GuildCases extends BaseGuildRepository {
1311
private cases: Repository<Case>;
1412
private caseNotes: Repository<CaseNote>;

backend/src/data/GuildNicknameHistory.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ import { BaseGuildRepository } from "./BaseGuildRepository";
55
import { cleanupNicknames } from "./cleanup/nicknames";
66
import { NicknameHistoryEntry } from "./entities/NicknameHistoryEntry";
77

8-
if (!isAPI()) {
9-
const CLEANUP_INTERVAL = 5 * MINUTES;
8+
const CLEANUP_INTERVAL = 5 * MINUTES;
109

11-
async function cleanup() {
12-
await cleanupNicknames();
13-
setTimeout(cleanup, CLEANUP_INTERVAL);
14-
}
10+
async function cleanup() {
11+
await cleanupNicknames();
12+
setTimeout(cleanup, CLEANUP_INTERVAL);
13+
}
1514

15+
if (!isAPI()) {
1616
// Start first cleanup 30 seconds after startup
17+
// TODO: Move to bot startup code
1718
setTimeout(cleanup, 30 * SECONDS);
1819
}
1920

backend/src/data/GuildSavedMessages.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export class GuildSavedMessages extends BaseGuildRepository<SavedMessage> {
126126
return entity;
127127
}
128128

129-
entity.data = await decryptJson(entity.data as unknown as string);
129+
entity.data = (await decryptJson(entity.data as unknown as string)) as ISavedMessageData;
130130
return entity;
131131
}
132132

backend/src/data/UsernameHistory.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ import { BaseRepository } from "./BaseRepository";
55
import { cleanupUsernames } from "./cleanup/usernames";
66
import { UsernameHistoryEntry } from "./entities/UsernameHistoryEntry";
77

8-
if (!isAPI()) {
9-
const CLEANUP_INTERVAL = 5 * MINUTES;
8+
const CLEANUP_INTERVAL = 5 * MINUTES;
109

11-
async function cleanup() {
12-
await cleanupUsernames();
13-
setTimeout(cleanup, CLEANUP_INTERVAL);
14-
}
10+
async function cleanup() {
11+
await cleanupUsernames();
12+
setTimeout(cleanup, CLEANUP_INTERVAL);
13+
}
1514

15+
if (!isAPI()) {
1616
// Start first cleanup 30 seconds after startup
17+
// TODO: Move to bot startup code
1718
setTimeout(cleanup, 30 * SECONDS);
1819
}
1920

backend/src/data/apiAuditLogTypes.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ export type RemoveApiPermissionEventData = {
1919
target_id: string;
2020
};
2121

22-
export type EditConfigEventData = {};
23-
2422
export interface AuditLogEventData extends Record<AuditLogEventType, unknown> {
2523
ADD_API_PERMISSION: {
2624
type: ApiPermissionTypes;
@@ -41,7 +39,7 @@ export interface AuditLogEventData extends Record<AuditLogEventType, unknown> {
4139
target_id: string;
4240
};
4341

44-
EDIT_CONFIG: {};
42+
EDIT_CONFIG: Record<string, never>;
4543
}
4644

4745
export type AnyAuditLogEventData = AuditLogEventData[AuditLogEventType];

backend/src/data/buildEntity.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export function buildEntity<T extends any>(Entity: new () => T, data: Partial<T>): T {
1+
export function buildEntity<T extends object>(Entity: new () => T, data: Partial<T>): T {
22
const instance = new Entity();
33
for (const [key, value] of Object.entries(data)) {
44
instance[key] = value;

backend/src/data/db.ts

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { backendDir } from "../paths";
55
import { QueryLogger } from "./queryLogger";
66

77
const ormconfigPath = path.join(backendDir, "ormconfig.js");
8+
// eslint-disable-next-line @typescript-eslint/no-var-requires
89
const connectionOptions = require(ormconfigPath);
910

1011
let connectionPromise: Promise<Connection>;

backend/src/data/entities/ApiLogin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class ApiLogin {
1919
@Column()
2020
expires_at: string;
2121

22-
@ManyToOne((type) => ApiUserInfo, (userInfo) => userInfo.logins)
22+
@ManyToOne(() => ApiUserInfo, (userInfo) => userInfo.logins)
2323
@JoinColumn({ name: "user_id" })
2424
userInfo: ApiUserInfo;
2525
}

backend/src/data/entities/ApiPermissionAssignment.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class ApiPermissionAssignment {
2222
@Column({ type: String, nullable: true })
2323
expires_at: string | null;
2424

25-
@ManyToOne((type) => ApiUserInfo, (userInfo) => userInfo.permissionAssignments)
25+
@ManyToOne(() => ApiUserInfo, (userInfo) => userInfo.permissionAssignments)
2626
@JoinColumn({ name: "target_id" })
2727
userInfo: ApiUserInfo;
2828
}

backend/src/data/entities/ApiUserInfo.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ export class ApiUserInfo {
2020
@Column()
2121
updated_at: string;
2222

23-
@OneToMany((type) => ApiLogin, (login) => login.userInfo)
23+
@OneToMany(() => ApiLogin, (login) => login.userInfo)
2424
logins: ApiLogin[];
2525

26-
@OneToMany((type) => ApiPermissionAssignment, (p) => p.userInfo)
26+
@OneToMany(() => ApiPermissionAssignment, (p) => p.userInfo)
2727
permissionAssignments: ApiPermissionAssignment[];
2828
}

backend/src/data/entities/Case.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ export class Case {
3535
*/
3636
@Column({ type: String, nullable: true }) log_message_id: string | null;
3737

38-
@OneToMany((type) => CaseNote, (note) => note.case)
38+
@OneToMany(() => CaseNote, (note) => note.case)
3939
notes: CaseNote[];
4040
}

backend/src/data/entities/CaseNote.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class CaseNote {
1515

1616
@Column() created_at: string;
1717

18-
@ManyToOne((type) => Case, (theCase) => theCase.notes)
18+
@ManyToOne(() => Case, (theCase) => theCase.notes)
1919
@JoinColumn({ name: "case_id" })
2020
case: Case;
2121
}

backend/src/data/entities/Config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class Config {
2222
@Column()
2323
edited_at: string;
2424

25-
@ManyToOne((type) => ApiUserInfo)
25+
@ManyToOne(() => ApiUserInfo)
2626
@JoinColumn({ name: "edited_by" })
2727
userInfo: ApiUserInfo;
2828
}

backend/src/data/entities/StarboardMessage.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class StarboardMessage {
1616
@Column()
1717
guild_id: string;
1818

19-
@OneToOne((type) => SavedMessage)
19+
@OneToOne(() => SavedMessage)
2020
@JoinColumn({ name: "message_id" })
2121
message: SavedMessage;
2222
}

backend/src/data/entities/StarboardReaction.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class StarboardReaction {
1616
@Column()
1717
reactor_id: string;
1818

19-
@OneToOne((type) => SavedMessage)
19+
@OneToOne(() => SavedMessage)
2020
@JoinColumn({ name: "message_id" })
2121
message: SavedMessage;
2222
}

backend/src/data/queryLogger.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { QueryRunner } from "typeorm";
21
import { AdvancedConsoleLogger } from "typeorm/logger/AdvancedConsoleLogger";
32

43
let groupedQueryStats: Map<string, number> = new Map();
@@ -9,7 +8,7 @@ const deleteTableRegex = /FROM `?([^\s`]+)/;
98
const insertTableRegex = /INTO `?([^\s`]+)/;
109

1110
export class QueryLogger extends AdvancedConsoleLogger {
12-
logQuery(query: string, parameters?: any[], queryRunner?: QueryRunner): any {
11+
logQuery(query: string): any {
1312
let type: string | undefined;
1413
let table: string | undefined;
1514

backend/src/index.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,6 @@ connect().then(async (connection) => {
242242
// FIXME: TS doesn't see Client as a child of EventEmitter for some reason
243243
(client as unknown as EventEmitter).setMaxListeners(200);
244244

245-
client.rest.on(RESTEvents.RateLimited, (data) => {
246-
// tslint:disable-next-line:no-console
247-
// console.log(`[DEBUG] [RATE_LIMIT] ${JSON.stringify(data)}`);
248-
});
249-
250245
const safe429DecayInterval = 5 * SECONDS;
251246
const safe429MaxCount = 5;
252247
const safe429Counter = new DecayingCounter(safe429DecayInterval);
@@ -453,7 +448,7 @@ connect().then(async (connection) => {
453448
logger.info("Received SIGINT, exiting...");
454449
cleanupAndStop(0);
455450
});
456-
process.on("SIGTERM", (code) => {
451+
process.on("SIGTERM", () => {
457452
logger.info("Received SIGTERM, exiting...");
458453
cleanupAndStop(0);
459454
});

backend/src/migrations/1540519249973-CreatePreTypeORMTables.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export class CreatePreTypeORMTables1540519249973 implements MigrationInterface {
106106
`);
107107
}
108108

109-
public async down(queryRunner: QueryRunner): Promise<any> {
109+
public async down(): Promise<any> {
110110
// No down function since we're migrating (hehe) from another migration system (knex)
111111
}
112112
}

backend/src/migrations/1556909512501-MigrateUsernamesToNewHistoryTable.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ export class MigrateUsernamesToNewHistoryTable1556909512501 implements Migration
7777
await queryRunner.query("START TRANSACTION");
7878
}
7979

80-
// tslint:disable-next-line:no-empty
81-
public async down(queryRunner: QueryRunner): Promise<any> {}
80+
// eslint-disable-next-line @typescript-eslint/no-empty-function
81+
public async down(): Promise<any> {}
8282
}

backend/src/migrations/1573158035867-AddTypeAndPermissionsToApiPermissions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export class AddTypeAndPermissionsToApiPermissions1573158035867 implements Migra
44
public async up(queryRunner: QueryRunner): Promise<any> {
55
try {
66
await queryRunner.dropPrimaryKey("api_permissions");
7-
} catch {} // tslint:disable-line
7+
} catch {} // eslint-disable-line no-empty
88

99
const table = (await queryRunner.getTable("api_permissions"))!;
1010
if (table.indices.length) {

backend/src/migrations/1608753440716-CreateTempBansTable.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { MigrationInterface, QueryRunner, Table, TableIndex } from "typeorm";
22

33
export class CreateTempBansTable1608753440716 implements MigrationInterface {
44
public async up(queryRunner: QueryRunner): Promise<any> {
5-
const table = await queryRunner.createTable(
5+
await queryRunner.createTable(
66
new Table({
77
name: "tempbans",
88
columns: [

backend/src/pluginUtils.ts

-22
Original file line numberDiff line numberDiff line change
@@ -77,28 +77,6 @@ const PluginOverrideCriteriaType: t.Type<PluginOverrideCriteria<unknown>> = t.re
7777
}),
7878
);
7979

80-
const validTopLevelOverrideKeys = [
81-
"channel",
82-
"category",
83-
"thread",
84-
"is_thread",
85-
"level",
86-
"user",
87-
"role",
88-
"all",
89-
"any",
90-
"not",
91-
"extra",
92-
"config",
93-
];
94-
95-
const BasicPluginStructureType = t.type({
96-
enabled: tNullable(t.boolean),
97-
config: tNullable(t.unknown),
98-
overrides: tNullable(t.array(t.union([PluginOverrideCriteriaType, t.type({ config: t.unknown })]))),
99-
replaceDefaultOverrides: tNullable(t.boolean),
100-
});
101-
10280
export function strictValidationErrorToConfigValidationError(err: StrictValidationError) {
10381
return new ConfigValidationError(
10482
err

0 commit comments

Comments
 (0)