From 7ad06970a5845c5334072ab775969e13824b977c Mon Sep 17 00:00:00 2001 From: Ruthenic Date: Fri, 26 Aug 2022 18:04:11 -0400 Subject: [PATCH] prettierify: post-typescriptification edition --- prettier.config.js | 6 +++++ rollup.config.js | 2 +- src/api/patcher.ts | 30 +++++++++++++++---------- src/api/plugin.ts | 7 ++++-- src/api/ritual.ts | 26 +++++++++++++++++----- src/api/ui/settings/hummus.tsx | 8 +++---- src/api/ui/settings/plugincard.tsx | 5 +---- src/api/ui/settings/plugins.tsx | 4 ++-- src/api/utils/logger.ts | 7 ++++-- src/api/utils/memory.ts | 6 ++--- src/api/utils/modals.tsx | 29 ++++++++++++++++--------- src/api/webpack.ts | 14 ++++++------ src/global.d.ts | 35 +++++++++++++++++++----------- tsconfig.json | 8 +++---- 14 files changed, 119 insertions(+), 68 deletions(-) diff --git a/prettier.config.js b/prettier.config.js index 418e497..8592762 100644 --- a/prettier.config.js +++ b/prettier.config.js @@ -11,6 +11,12 @@ module.exports = { options: { parser: "babel" } + }, + { + files: "*.d.ts", + options: { + semi: false + } } ] }; diff --git a/rollup.config.js b/rollup.config.js index 2f2ceb9..23cfaf5 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -8,7 +8,7 @@ import { visualizer } from "rollup-plugin-visualizer"; import TOML from "@ltd/j-toml"; import jscc from "rollup-plugin-jscc"; import { readFileSync as readFile, existsSync as fileExists } from "fs"; -import typescript from '@rollup/plugin-typescript'; +import typescript from "@rollup/plugin-typescript"; const projectRootDir = resolvePath(__dirname); diff --git a/src/api/patcher.ts b/src/api/patcher.ts index d619d2b..801495f 100644 --- a/src/api/patcher.ts +++ b/src/api/patcher.ts @@ -1,12 +1,16 @@ -type BeforeFunc = (args: any[]) => void -type InsteadFunc = (args: any[], orig: (...args: any) => any) => any -type AfterFunc = (args: any[], res: any) => any +type BeforeFunc = (args: any[]) => void; +type InsteadFunc = (args: any[], orig: (...args: any) => any) => any; +type AfterFunc = (args: any[], res: any) => any; -function wackyPatch(parentObj: any, name: string, patches: { - before?: BeforeFunc, - instead?: InsteadFunc, - after?: AfterFunc -}) { +function wackyPatch( + parentObj: any, + name: string, + patches: { + before?: BeforeFunc; + instead?: InsteadFunc; + after?: AfterFunc; + } +) { if (typeof parentObj === "string") { //assume parentObj and name are switched around (for backcompat/convienence) const tmp = parentObj; @@ -18,12 +22,16 @@ function wackyPatch(parentObj: any, name: string, patches: { const instead = patches["instead"]; const after = patches["after"]; const handler = { - apply: (target: () => any, thisArg: any, [ctx, args]: [ctx: any, args: []]) => { + apply: ( + target: () => any, + thisArg: any, + [ctx, args]: [ctx: any, args: []] + ) => { if (before !== undefined) before.apply(ctx, [args]); const res = patches["instead"] !== undefined - //@ts-ignore; TS thinks that `instead` possibly being undefined is bad (meanwhile we literally check for that) - ? instead.apply(ctx, [args, target.bind(ctx)]) + ? //@ts-ignore; TS thinks that `instead` possibly being undefined is bad (meanwhile we literally check for that) + instead.apply(ctx, [args, target.bind(ctx)]) : target.apply(ctx, args); if (after === undefined) return res; return after.apply(ctx, [args, res]); diff --git a/src/api/plugin.ts b/src/api/plugin.ts index ded54cf..4f5625e 100644 --- a/src/api/plugin.ts +++ b/src/api/plugin.ts @@ -13,10 +13,13 @@ import logger from "./utils/logger"; const ctxNest: Nest = nests.make(); //Plugin context nest (I would create this in index, but it's not a good idea to expose that) -let pluginNest: Nest<{plugins: any}>; +let pluginNest: Nest<{ plugins: any }>; const pluginEval = (iife: string) => (0, eval)(iife); //defined as a separate function in case we want to do more things on plugin eval later -async function savePlugin(eve: string, { path, value }: { path: string[] | string, value: any }) { +async function savePlugin( + eve: string, + { path, value }: { path: string[] | string; value: any } +) { logger.debug( ["Plugins"], `Got ${eve} event for plugin manager's nest with path ${path} and val ${value}` diff --git a/src/api/ritual.ts b/src/api/ritual.ts index 2a28674..ef18dc7 100644 --- a/src/api/ritual.ts +++ b/src/api/ritual.ts @@ -2,7 +2,7 @@ import webpack from "./webpack"; import { instead } from "./patcher"; import { leak } from "./utils/memory"; -type Sins = Record void) | null> +type Sins = Record void) | null>; const sins: Sins = { Lust: null, @@ -75,7 +75,11 @@ function findByRitual(incantation: string) { args.shift() !== "upon" || args.shift() !== "the" ) { - ritualFail(Object.keys(sins)[Math.floor(Math.random() * Object.keys(sins).length)]); + ritualFail( + Object.keys(sins)[ + Math.floor(Math.random() * Object.keys(sins).length) + ] + ); return; } const embodiment = args.shift(); @@ -87,17 +91,29 @@ function findByRitual(incantation: string) { ) { //absolutely no clue where i heard them referred to as "king sin of X" before, but i think it sounds cool so i'll keep it //how did you even fuck this one up - ritualFail(Object.keys(sins)[Math.floor(Math.random() * Object.keys(sins).length)]); + ritualFail( + Object.keys(sins)[ + Math.floor(Math.random() * Object.keys(sins).length) + ] + ); return; } if (args.shift() !== "of") { - ritualFail(Object.keys(sins)[Math.floor(Math.random() * Object.keys(sins).length)]); + ritualFail( + Object.keys(sins)[ + Math.floor(Math.random() * Object.keys(sins).length) + ] + ); } //@ts-expect-error 2532 const sin = args.shift().replace(",", ""); if (!(sin in sins)) { //invalid sin, so we can't use it - ritualFail(Object.keys(sins)[Math.floor(Math.random() * Object.keys(sins).length)]); + ritualFail( + Object.keys(sins)[ + Math.floor(Math.random() * Object.keys(sins).length) + ] + ); return; } //@ts-expect-error 2532 diff --git a/src/api/ui/settings/hummus.tsx b/src/api/ui/settings/hummus.tsx index dc6f4a3..8614bda 100644 --- a/src/api/ui/settings/hummus.tsx +++ b/src/api/ui/settings/hummus.tsx @@ -5,7 +5,7 @@ import webpack from "../../webpack"; const Checkbox = webpack.findByDisplayName("Checkbox"); interface HummusUI extends React.Component { - state: { tg: number } //we love jank! + state: { tg: number }; //we love jank! } class HummusUI extends React.Component { @@ -31,9 +31,9 @@ class HummusUI extends React.Component { onChange={async () => { toggle(k); const ele = - (document.getElementsByClassName( + document.getElementsByClassName( `demon-stub-plugin-checkbox-${k}` - )[0]) as HTMLInputElement; + )[0] as HTMLInputElement; //ele.value = extNest.ghost.pluginsStatus[k].running if (!extNest.ghost.plugins[k].enabled) { ele.value = "on"; @@ -54,4 +54,4 @@ class HummusUI extends React.Component { } } -export default HummusUI \ No newline at end of file +export default HummusUI; diff --git a/src/api/ui/settings/plugincard.tsx b/src/api/ui/settings/plugincard.tsx index 241ec2e..a3fc319 100644 --- a/src/api/ui/settings/plugincard.tsx +++ b/src/api/ui/settings/plugincard.tsx @@ -10,10 +10,7 @@ const Button = webpack.findByProps("BorderColors", "Colors"); const FormDivider = webpack.findByDisplayName("FormDivider"); const Switch = webpack.findByDisplayName("Switch"); -export default (props: { - nest: Nest<{plugins: any}>, - name: string -}) => { +export default (props: { nest: Nest<{ plugins: any }>; name: string }) => { nestsReact.useNest(props.nest); if (!props.nest.ghost.plugins[props.name]) { return null; //you wouldn't think i'd have to do this but diff --git a/src/api/ui/settings/plugins.tsx b/src/api/ui/settings/plugins.tsx index 0658690..5a756c3 100644 --- a/src/api/ui/settings/plugins.tsx +++ b/src/api/ui/settings/plugins.tsx @@ -15,7 +15,7 @@ const TextInput = webpack.findByDisplayName("TextInput"); const Button = webpack.findByProps("BorderColors", "Colors"); export default () => { - const extNest: Nest<{plugins: any}> = demon.summon("internal/nest"); + const extNest: Nest<{ plugins: any }> = demon.summon("internal/nest"); const [input, setInput] = React.useState(""); nestsReact.useNest(extNest); return ( @@ -28,7 +28,7 @@ export default () => { type="text" value={input} onChange={setInput} - onKeyDown={async (eve: {key: string}) => { + onKeyDown={async (eve: { key: string }) => { if (eve.key === "Enter") { const text = await ( await fetch("$_CORS_URL" + input) diff --git a/src/api/utils/logger.ts b/src/api/utils/logger.ts index 57d86ab..8307131 100644 --- a/src/api/utils/logger.ts +++ b/src/api/utils/logger.ts @@ -6,8 +6,11 @@ const styleBg = `${styleBase} color: #1d1131; background-color: #aa8dd8; font-we const styleTxt = `${styleBase} color: #E2EECE; font-weight: 500; font-size: 0.9em;`; //TODO: make setting to save logs in idb, for debugging and troubleshooting purposes -function makeLogger(print: (...msg: string[]) => void, noDemoncord: boolean = false) { - return function(locs: string[], ...messages: string[]): void { +function makeLogger( + print: (...msg: string[]) => void, + noDemoncord: boolean = false +) { + return function (locs: string[], ...messages: string[]): void { let message = messages.join(""); if (locs === undefined) { locs = ["Default"]; diff --git a/src/api/utils/memory.ts b/src/api/utils/memory.ts index 31a9b80..f9371ee 100644 --- a/src/api/utils/memory.ts +++ b/src/api/utils/memory.ts @@ -5,7 +5,7 @@ export function leak(mb: number): void { window.beelzejuice = []; //weird fanfic reference; i've seen this name used multiple times for alcoholic beverages } const id = Math.random().toString(36).slice(2); - window.beelzejuice.push(new Uint8Array(Math.floor(mb * 1024 * 1024)).fill( - 666 - )); + window.beelzejuice.push( + new Uint8Array(Math.floor(mb * 1024 * 1024)).fill(666) + ); } diff --git a/src/api/utils/modals.tsx b/src/api/utils/modals.tsx index 05a7ca8..e18364b 100644 --- a/src/api/utils/modals.tsx +++ b/src/api/utils/modals.tsx @@ -8,7 +8,12 @@ const Colors = findByProps("button", "colorRed"); const ConfirmModal = findByDisplayName("ConfirmModal"); const Markdown = findByDisplayNameAll("Markdown")[1]; -function rawOpenConfirmModal(component: any, props: any, insideProps: any, insideContent: any) { +function rawOpenConfirmModal( + component: any, + props: any, + insideProps: any, + insideContent: any +) { if (insideProps === undefined) { insideProps = {}; } @@ -16,7 +21,7 @@ function rawOpenConfirmModal(component: any, props: any, insideProps: any, insid insideContent = ""; } let confirmed; - openModal((e: {transitionState: any, onClose: () => void}) => { + openModal((e: { transitionState: any; onClose: () => void }) => { if (e.transitionState === 3) { return false; //TODO: the fuck does this do? } @@ -24,10 +29,10 @@ function rawOpenConfirmModal(component: any, props: any, insideProps: any, insid return ( (confirmed = false)} + onClose={() => (confirmed = false)} //@ts-ignore onCancel={() => (confirmed = false & e.onClose())} - //@ts-ignore + //@ts-ignore onConfirm={() => (confirmed = true & e.onClose())} {...props} > @@ -40,12 +45,16 @@ function rawOpenConfirmModal(component: any, props: any, insideProps: any, insid return confirmed; } -function openConfirmModal(content: string, type: string, opts: { - header: string, - confirmText: string, - cancelText: string, - color: any -}) { +function openConfirmModal( + content: string, + type: string, + opts: { + header: string; + confirmText: string; + cancelText: string; + color: any; + } +) { let buttonColor; if (!!opts.color) { buttonColor = opts.color; diff --git a/src/api/webpack.ts b/src/api/webpack.ts index 533dee8..390184d 100644 --- a/src/api/webpack.ts +++ b/src/api/webpack.ts @@ -1,9 +1,9 @@ -type Filter = (module: any) => boolean +type Filter = (module: any) => boolean; interface Module { exports: { - default?: any - __esModule?: any - } + default?: any; + __esModule?: any; + }; } let getModules: () => []; @@ -13,7 +13,7 @@ let getModules: () => []; //TODO: account for different versions of webpackJsonp, ie ones that aren't a function (if/when hummus-like things come out) if (!window.webpackChunkdiscord_app) { let modules: { - c: [] + c: []; } = window.webpackJsonp( [], [ @@ -25,12 +25,12 @@ if (!window.webpackChunkdiscord_app) { getModules = () => modules.c; } else { let modules: { - c: [] + c: []; }; window.webpackChunkdiscord_app.push([ [Math.random().toString(36)], {}, - (e: {c:[]}) => { + (e: { c: [] }) => { modules = e; } ]); diff --git a/src/global.d.ts b/src/global.d.ts index 1da0dbd..b0d4f10 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -1,19 +1,25 @@ interface Nest { - ghost: Schema, - store: Schema, - on: (event: string, callback: (eve: string, { path, value }: { path: string[] | string, value: any }) => void) => void, - get: any, - set: any, - delete: any, - update: any, - listeners: any, - once: any, - off: any, + ghost: Schema + store: Schema + on: ( + event: string, + callback: ( + eve: string, + { path, value }: { path: string[] | string; value: any } + ) => void + ) => void + get: any + set: any + delete: any + update: any + listeners: any + once: any + off: any emit: any } type DemonGlobal = { - summon: (mod: string) => any + summon: (mod: string) => any } const demon: DemonGlobal @@ -22,7 +28,10 @@ interface Window { demon: DemonGlobal beelzejuice: Uint8Array[] webpackChunkdiscord_app: any - webpackJsonp: (thing1: [], thing2: [(mod: any, _exports: any, req: any) => void]) => any + webpackJsonp: ( + thing1: [], + thing2: [(mod: any, _exports: any, req: any) => void] + ) => any } namespace JSX { @@ -36,4 +45,4 @@ namespace JSX { } } -const _: any \ No newline at end of file +const _: any diff --git a/tsconfig.json b/tsconfig.json index a0ee890..e3db0f8 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "jsx": "preserve", "paths": { - "nests/*": ["./node_modules/nests/esm/*"] + "nests/*": ["./node_modules/nests/esm/*"] }, /* Visit https://aka.ms/tsconfig.json to read more about this file */ /* Language and Environment */ @@ -10,7 +10,7 @@ /* Modules */ "module": "ESNext" /* Specify what module code is generated. */, // "rootDir": "./", /* Specify the root folder within your source files. */ - "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ + "moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */, // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ @@ -82,6 +82,6 @@ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */ }, - "include": ["src/*", "src/**/*"], - "exclude": [], + "include": ["src/*", "src/**/*"], + "exclude": [] }