From dea34503ef61fe8f2600d2d9b0edb2eec90ebd1b Mon Sep 17 00:00:00 2001 From: Vendicated Date: Sat, 8 Oct 2022 20:36:57 +0200 Subject: [PATCH] Add more eslint rules --- .eslintrc.json | 14 +++++++++++++- browser/VencordNativeStub.ts | 2 +- scripts/patcher/install.js | 2 +- src/api/Commands.ts | 2 ++ src/components/Updater.tsx | 2 +- src/plugins/betterGifAltText.ts | 2 +- src/plugins/nitroBypass.ts | 4 ++-- src/plugins/quickreply.ts | 14 +++++++------- src/preload.ts | 3 +-- src/utils/IpcEvents.ts | 2 +- src/utils/misc.tsx | 2 +- src/utils/modal.tsx | 2 +- src/webpack/patchWebpack.ts | 3 +-- 13 files changed, 33 insertions(+), 21 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 2d51750c..08071542 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -23,6 +23,18 @@ "semi-style": ["error", "last"], "space-in-parens": ["error", "never"], "block-spacing": ["error", "always"], - "object-curly-spacing": ["error", "always"] + "object-curly-spacing": ["error", "always"], + "eqeqeq": ["error", "always", { "null": "ignore" }], + "spaced-comment": ["error", "always"], + "yoda": "error", + "prefer-destructuring": ["error", { "object": true, "array": false }], + "operator-assignment": ["error", "always"], + "no-useless-computed-key": "error", + "no-unneeded-ternary": ["error", { "defaultAssignment": false }], + "no-invalid-regexp": "error", + "no-constant-condition": ["error", { "checkLoops": false }], + "no-duplicate-imports": "error", + "no-extra-semi": "error", + "consistent-return": ["error", { "treatUndefinedAsUnspecified": true }] } } diff --git a/browser/VencordNativeStub.ts b/browser/VencordNativeStub.ts index bdcae4e1..b6d1121c 100644 --- a/browser/VencordNativeStub.ts +++ b/browser/VencordNativeStub.ts @@ -1,7 +1,7 @@ import IpcEvents from "../src/utils/IpcEvents"; // Discord deletes this so need to store in variable -var localStorage = window.localStorage; +var { localStorage } = window; const handlers = { [IpcEvents.GET_REPO]: () => "", // TODO diff --git a/scripts/patcher/install.js b/scripts/patcher/install.js index c9babc8f..4e75dbe1 100644 --- a/scripts/patcher/install.js +++ b/scripts/patcher/install.js @@ -43,7 +43,7 @@ async function install(installations) { // Attempt to give flatpak perms if (selected.isFlatpak) { try { - const branch = selected.branch; + const { branch } = selected; const cwd = process.cwd(); const globalCmd = `flatpak override ${branch} --filesystem=${cwd}`; const userCmd = `flatpak override --user ${branch} --filesystem=${cwd}`; diff --git a/src/api/Commands.ts b/src/api/Commands.ts index 10503e96..907a65d3 100644 --- a/src/api/Commands.ts +++ b/src/api/Commands.ts @@ -82,6 +82,8 @@ export function unregisterCommand(name: string) { BUILT_IN.splice(idx, 1); delete commands[name]; + + return true; } export interface CommandContext { diff --git a/src/components/Updater.tsx b/src/components/Updater.tsx index 5e7e84fa..31060b48 100644 --- a/src/components/Updater.tsx +++ b/src/components/Updater.tsx @@ -42,7 +42,7 @@ function withDispatcher(dispatcher: React.Dispatch dispatcher(false); } }; -}; +} interface CommonProps { repo: string; diff --git a/src/plugins/betterGifAltText.ts b/src/plugins/betterGifAltText.ts index 08fa07b7..4712f71d 100644 --- a/src/plugins/betterGifAltText.ts +++ b/src/plugins/betterGifAltText.ts @@ -26,7 +26,7 @@ export default definePlugin({ ], altify(props: any) { - if (props.alt !== "GIF") return; + if (props.alt !== "GIF") return props.alt; let url: string = props.original || props.src; try { diff --git a/src/plugins/nitroBypass.ts b/src/plugins/nitroBypass.ts index e3b6747e..8920bc67 100644 --- a/src/plugins/nitroBypass.ts +++ b/src/plugins/nitroBypass.ts @@ -55,7 +55,7 @@ export default definePlugin({ } this.preSend = addPreSendListener((_, messageObj) => { - const guildId = this.guildId; + const { guildId } = this; for (const emoji of messageObj.validNonShortcutEmojis) { if (!emoji.require_colons) continue; if (emoji.guildId === guildId && !emoji.animated) continue; @@ -69,7 +69,7 @@ export default definePlugin({ }); this.preEdit = addPreEditListener((_, __, messageObj) => { - const guildId = this.guildId; + const { guildId } = this; for (const [emojiStr, _, emojiId] of messageObj.content.matchAll(/(?/ig)) { const emoji = getCustomEmojiById(emojiId); diff --git a/src/plugins/quickreply.ts b/src/plugins/quickreply.ts index 111d9bba..f1a84518 100644 --- a/src/plugins/quickreply.ts +++ b/src/plugins/quickreply.ts @@ -15,21 +15,21 @@ export default definePlugin({ start() { Dispatcher.subscribe("DELETE_PENDING_REPLY", onDeletePendingReply); - document.addEventListener("keydown", keydown); + document.addEventListener("keydown", onKeydown); }, stop() { Dispatcher.unsubscribe("DELETE_PENDING_REPLY", onDeletePendingReply); - document.removeEventListener("keydown", keydown); + document.removeEventListener("keydown", onKeydown); }, }); let idx = -1; -const onDeletePendingReply = () => { +function onDeletePendingReply() { idx = -1; -}; +} -const keydown = e => { +function onKeydown(e: KeyboardEvent) { if ( (!e.ctrlKey && !e.metaKey) || (e.key !== "ArrowUp" && e.key !== "ArrowDown") @@ -46,7 +46,7 @@ const keydown = e => { if (idx > messages.length) idx = messages.length; if (idx < 0) { - return Dispatcher.dispatch({ + return void Dispatcher.dispatch({ type: "DELETE_PENDING_REPLY", channelId, }); @@ -58,4 +58,4 @@ const keydown = e => { message: messages[idx], showMentionToggle: channel.guild_id !== null, }); -}; +} diff --git a/src/preload.ts b/src/preload.ts index 9578bf6c..31558f52 100644 --- a/src/preload.ts +++ b/src/preload.ts @@ -1,8 +1,7 @@ -import electron, { contextBridge, webFrame } from "electron"; +import electron, { contextBridge, webFrame, ipcRenderer } from "electron"; import { readFileSync } from "fs"; import { join } from "path"; import VencordNative from "./VencordNative"; -import { ipcRenderer } from "electron"; import IpcEvents from "./utils/IpcEvents"; if (electron.desktopCapturer === void 0) { diff --git a/src/utils/IpcEvents.ts b/src/utils/IpcEvents.ts index b96abdc4..6b906f15 100644 --- a/src/utils/IpcEvents.ts +++ b/src/utils/IpcEvents.ts @@ -7,7 +7,7 @@ function strEnum>(obj: T): T { for (const key in obj) { o[key] = obj[key] as any; o[obj[key]] = key as any; - }; + } return Object.freeze(o); } diff --git a/src/utils/misc.tsx b/src/utils/misc.tsx index 989a54a2..2ebf91c5 100644 --- a/src/utils/misc.tsx +++ b/src/utils/misc.tsx @@ -56,7 +56,7 @@ export function useAwaiter(factory: () => Promise, fallbackValue: T | null }, []); return [state.value, state.error, state.pending]; -}; +} /** * A lazy component. The factory method is called on first render. For example useful diff --git a/src/utils/modal.tsx b/src/utils/modal.tsx index f59c26c0..b8e647cf 100644 --- a/src/utils/modal.tsx +++ b/src/utils/modal.tsx @@ -25,7 +25,7 @@ export function openModal(Component: React.ComponentType, modalProps: Record