add eslint config (#53)

* eslint

* workflow

* lint main
This commit is contained in:
Ven 2022-10-06 00:42:58 +02:00 committed by GitHub
parent e563521416
commit 74c3930e0a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
41 changed files with 141 additions and 87 deletions

View file

@ -12,7 +12,7 @@ export { Settings };
import "./webpack/patchWebpack";
import "./utils/quickCss";
import { checkForUpdates, UpdateLogger } from './utils/updater';
import { checkForUpdates, UpdateLogger } from "./utils/updater";
import { onceReady } from "./webpack";
import { Router } from "./webpack/common";

View file

@ -1,5 +1,5 @@
import IPC_EVENTS from './utils/IpcEvents';
import { IpcRenderer, ipcRenderer } from 'electron';
import IPC_EVENTS from "./utils/IpcEvents";
import { IpcRenderer, ipcRenderer } from "electron";
function assertEventAllowed(event: string) {
if (!(event in IPC_EVENTS)) throw new Error(`Event ${event} not allowed.`);

View file

@ -1,5 +1,5 @@
import { Channel, Guild } from "discord-types/general";
import { waitFor } from '../webpack';
import { waitFor } from "../webpack";
export function _init(cmds: Command[]) {
try {

View file

@ -1,5 +1,5 @@
import type { Message, Channel } from 'discord-types/general';
import Logger from '../utils/logger';
import type { Message, Channel } from "discord-types/general";
import Logger from "../utils/logger";
const MessageEventsLogger = new Logger("MessageEvents", "#e5c890");

View file

@ -1,7 +1,7 @@
import plugins from "plugins";
import IpcEvents from "../utils/IpcEvents";
import { React } from "../webpack/common";
import { mergeDefaults } from '../utils/misc';
import { mergeDefaults } from "../utils/misc";
interface Settings {
notifyAboutUpdates: boolean;

View file

@ -15,7 +15,7 @@ const NO_ERROR = {};
export default class ErrorBoundary extends React.Component<React.PropsWithChildren<Props>> {
static wrap<T = any>(Component: React.ComponentType<T>): (props: T) => React.ReactElement {
return (props) => (
return props => (
<ErrorBoundary>
<Component {...props as any/* I hate react typings ??? */} />
</ErrorBoundary>

View file

@ -1,5 +1,4 @@
import { PropsWithChildren } from "react";
import type { React } from '../webpack/common';
import type { React } from "../webpack/common";
export function Flex(props: React.PropsWithChildren<{
flexDirection?: React.CSSProperties["flexDirection"];

View file

@ -1,14 +1,14 @@
import { classes, humanFriendlyJoin, useAwaiter } from "../utils/misc";
import Plugins from 'plugins';
import Plugins from "plugins";
import { useSettings } from "../api/settings";
import IpcEvents from "../utils/IpcEvents";
import { Button, Switch, Forms, React, Margins, Toasts, Alerts, Parser } from "../webpack/common";
import ErrorBoundary from "./ErrorBoundary";
import { startPlugin } from "../plugins";
import { stopPlugin } from '../plugins/index';
import { Flex } from './Flex';
import { ChangeList } from '../utils/ChangeList';
import { stopPlugin } from "../plugins/index";
import { Flex } from "./Flex";
import { ChangeList } from "../utils/ChangeList";
function showErrorToast(message: string) {
Toasts.show({
@ -35,7 +35,7 @@ export default ErrorBoundary.wrap(function Settings() {
<div>{changes.map((s, i) => (
<>
{i > 0 && ", "}
{Parser.parse('`' + s + '`')}
{Parser.parse("`" + s + "`")}
</>
))}</div>
</>
@ -69,7 +69,7 @@ export default ErrorBoundary.wrap(function Settings() {
</Forms.FormTitle>
<Forms.FormText>
SettingsDir: <code style={{ userSelect: 'text', cursor: 'text' }}>{settingsDir}</code>
SettingsDir: <code style={{ userSelect: "text", cursor: "text" }}>{settingsDir}</code>
</Forms.FormText>
{!IS_WEB && <Flex className={classes(Margins.marginBottom20)}>

View file

@ -1,8 +1,8 @@
import gitHash from "git-hash";
import { changes, checkForUpdates, getRepo, rebuild, update, UpdateLogger, updateError, isOutdated, isNewer } from '../utils/updater';
import { React, Forms, Button, Margins, Alerts, Card, Parser, Toasts } from '../webpack/common';
import { changes, checkForUpdates, getRepo, rebuild, update, UpdateLogger, updateError, isOutdated, isNewer } from "../utils/updater";
import { React, Forms, Button, Margins, Alerts, Card, Parser, Toasts } from "../webpack/common";
import { Flex } from "./Flex";
import { classes, useAwaiter } from '../utils/misc';
import { classes, useAwaiter } from "../utils/misc";
import { Link } from "./Link";
import ErrorBoundary from "./ErrorBoundary";
import { ErrorCard } from "./ErrorCard";

View file

@ -1,9 +1,9 @@
import { app, BrowserWindow, desktopCapturer, ipcMain, shell } from "electron";
import { mkdirSync, readFileSync, watch } from "fs";
import { open, readFile, writeFile } from "fs/promises";
import { join } from 'path';
import { join } from "path";
import { debounce } from "../utils/debounce";
import IpcEvents from '../utils/IpcEvents';
import IpcEvents from "../utils/IpcEvents";
import "./updater";
@ -47,7 +47,7 @@ ipcMain.handle(IpcEvents.OPEN_EXTERNAL, (_, url) => {
ipcMain.handle(IpcEvents.GET_QUICK_CSS, () => readCss());
ipcMain.handle(IpcEvents.GET_SETTINGS_DIR, () => SETTINGS_DIR);
ipcMain.on(IpcEvents.GET_SETTINGS, (e) => e.returnValue = readSettings());
ipcMain.on(IpcEvents.GET_SETTINGS, e => e.returnValue = readSettings());
let settingsWriteQueue = Promise.resolve();
ipcMain.handle(IpcEvents.SET_SETTINGS, (_, s) => {

View file

@ -1,10 +1,10 @@
import { ipcMain } from 'electron';
import { ipcMain } from "electron";
import { promisify } from "util";
import IpcEvents from "../utils/IpcEvents";
import { execFile as cpExecFile } from 'child_process';
import { join } from 'path';
import { createReadStream } from 'fs';
import { createHash } from 'crypto';
import { execFile as cpExecFile } from "child_process";
import { join } from "path";
import { createReadStream } from "fs";
import { createHash } from "crypto";
const VENCORD_SRC_DIR = join(__dirname, "..");
@ -64,7 +64,7 @@ async function getRepo() {
async function calculateGitChanges() {
await git("fetch");
const res = await git("log", `HEAD...origin/main`, "--pretty=format:%an/%h/%s");
const res = await git("log", "HEAD...origin/main", "--pretty=format:%an/%h/%s");
const commits = res.stdout.trim();
return commits ? commits.split("\n").map(line => {

View file

@ -1,7 +1,7 @@
import electron, { app, BrowserWindowConstructorOptions } from "electron";
import installExt, { REACT_DEVELOPER_TOOLS } from "electron-devtools-installer";
import { join } from "path";
import { initIpc } from './ipcMain';
import { initIpc } from "./ipcMain";
console.log("[Vencord] Starting up...");
@ -49,7 +49,7 @@ process.env.DATA_DIR = join(app.getPath("userData"), "..", "Vencord");
electron.app.whenReady().then(() => {
installExt(REACT_DEVELOPER_TOOLS)
.then(() => console.info("Installed React DevTools"))
.catch((err) => console.error("Failed to install React DevTools", err));
.catch(err => console.error("Failed to install React DevTools", err));
// Remove CSP
electron.session.defaultSession.webRequest.onHeadersReceived(({ responseHeaders, url }, cb) => {

View file

@ -1,5 +1,5 @@
import definePlugin from "../utils/types";
import { Devs } from '../utils/constants';
import { Devs } from "../utils/constants";
export default definePlugin({
name: "STFU",

View file

@ -7,7 +7,7 @@ export default definePlugin({
description: "Api required by anything that uses commands",
patches: [
{
find: `"giphy","tenor"`,
find: '"giphy","tenor"',
replacement: [
{
// Matches BUILT_IN_COMMANDS. This is not exported so this is

View file

@ -13,7 +13,7 @@ export default definePlugin({
{
match: /;(.{1,2}=null;)(?=.{0,50}updateNotice)/g,
replace:
';if(Vencord.Api.Notices.currentNotice)return !1;$1'
";if(Vencord.Api.Notices.currentNotice)return !1;$1"
},
{
match: /(?<=NOTICE_DISMISS:function.+?){(?=if\(null==(.+?)\))/,

View file

@ -90,7 +90,7 @@ export default definePlugin({
}
// Check all universal rules
this.universalRules.forEach((rule) => {
this.universalRules.forEach(rule => {
url.searchParams.forEach((_value, param, parent) => {
this.removeParam(rule, param, parent);
});
@ -99,7 +99,7 @@ export default definePlugin({
// Check rules for each hosts that match
this.hostRules.forEach((regex, hostRuleName) => {
if (!regex.test(url.hostname)) return;
this.rulesByHost.get(hostRuleName).forEach((rule) => {
this.rulesByHost.get(hostRuleName).forEach(rule => {
url.searchParams.forEach((_value, param, parent) => {
this.removeParam(rule, param, parent);
});
@ -114,7 +114,7 @@ export default definePlugin({
if (msg.content.match(/http(s)?:\/\//)) {
msg.content = msg.content.replace(
/(https?:\/\/[^\s<]+[^<.,:;"'>)|\]\s])/g,
(match) => this.replacer(match)
match => this.replacer(match)
);
}
},

View file

@ -1,6 +1,6 @@
import { Devs } from "../utils/constants";
import definePlugin from "../utils/types";
import { Toasts } from '../webpack/common';
import { Toasts } from "../webpack/common";
export default definePlugin({
name: "ClickableRoleDot",

View file

@ -1,5 +1,5 @@
import { Devs } from "../utils/constants";
import definePlugin from '../utils/types';
import definePlugin from "../utils/types";
export default definePlugin({
name: "Experiments",

View file

@ -12,7 +12,7 @@ export default definePlugin({
name: "lenny",
description: "Sends a lenny face",
options: [OptionalMessageOption],
execute: (opts) => ({
execute: opts => ({
content: findOption(opts, "message", "") + " ( ͡° ͜ʖ ͡°)"
}),
},

View file

@ -1,4 +1,4 @@
import { addClickListener, removeClickListener } from '../api/MessageEvents';
import { addClickListener, removeClickListener } from "../api/MessageEvents";
import { Devs } from "../utils/constants";
import definePlugin from "../utils/types";
import { find, findByProps } from "../webpack";

View file

@ -1,5 +1,5 @@
import definePlugin from "../utils/types";
import {Devs} from "../utils/constants";
import { Devs } from "../utils/constants";
export default definePlugin({
name: "MuteNewGuild",
@ -14,4 +14,4 @@ export default definePlugin({
}
}
],
})
});

View file

@ -1,8 +1,8 @@
import { addPreSendListener, addPreEditListener, SendListener, removePreSendListener, removePreEditListener } from '../api/MessageEvents';
import { addPreSendListener, addPreEditListener, removePreSendListener, removePreEditListener } from "../api/MessageEvents";
import { findByProps } from "../webpack";
import definePlugin from "../utils/types";
import { Devs } from '../utils/constants';
import { UserStore } from '../webpack/common';
import { Devs } from "../utils/constants";
import { UserStore } from "../webpack/common";
export default definePlugin({
name: "NitroBypass",
@ -11,7 +11,7 @@ export default definePlugin({
dependencies: ["MessageEventsAPI"],
patches: [
{
find: `canUseAnimatedEmojis:function`,
find: "canUseAnimatedEmojis:function",
replacement: [
"canUseAnimatedEmojis",
"canUseEmojisEverywhere",
@ -58,8 +58,8 @@ export default definePlugin({
if (!emoji.require_colons) continue;
if (emoji.guildId === guildId && !emoji.animated) continue;
const emojiString = `<${emoji.animated ? 'a' : ''}:${emoji.originalName || emoji.name}:${emoji.id}>`;
const url = emoji.url.replace(/\?size=[0-9]+/, `?size=48`);
const emojiString = `<${emoji.animated ? "a" : ""}:${emoji.originalName || emoji.name}:${emoji.id}>`;
const url = emoji.url.replace(/\?size=[0-9]+/, "?size=48");
messageObj.content = messageObj.content.replace(emojiString, (match, offset, origStr) => {
return `${getWordBoundary(origStr, offset - 1)}${url}${getWordBoundary(origStr, offset + match.length)}`;
});
@ -74,7 +74,7 @@ export default definePlugin({
if (emoji == null || (emoji.guildId === guildId && !emoji.animated)) continue;
if (!emoji.require_colons) continue;
const url = emoji.url.replace(/\?size=[0-9]+/, `?size=48`);
const url = emoji.url.replace(/\?size=[0-9]+/, "?size=48");
messageObj.content = messageObj.content.replace(emojiStr, (match, offset, origStr) => {
return `${getWordBoundary(origStr, offset - 1)}${url}${getWordBoundary(origStr, offset + match.length)}`;
});

View file

@ -16,4 +16,4 @@ export default definePlugin({
}
}
]
})
});

View file

@ -1,5 +1,5 @@
import definePlugin from "../utils/types";
import { Devs } from '../utils/constants';
import { Devs } from "../utils/constants";
export default definePlugin({
name: "NoTrack",

View file

@ -23,6 +23,6 @@ export default definePlugin({
{ length: 7 },
() => chars[Math.floor(Math.random() * chars.length)]
).join("");
return rand + (file.lastIndexOf(".") > -1 ? file.slice(file.lastIndexOf(".")) : "")
return rand + (file.lastIndexOf(".") > -1 ? file.slice(file.lastIndexOf(".")) : "");
},
});

View file

@ -1,6 +1,6 @@
import definePlugin from "../utils/types";
import gitHash from "git-hash";
import { Devs } from '../utils/constants';
import { Devs } from "../utils/constants";
export default definePlugin({
name: "Settings",
@ -30,8 +30,8 @@ export default definePlugin({
match: /\{section:(.{1,2})\.ID\.HEADER,\s*label:(.{1,2})\..{1,2}\.Messages\.ACTIVITY_SETTINGS\}/,
replace: (m, mod) =>
`{section:${mod}.ID.HEADER,label:"Vencord"},` +
`{section:"VencordSetting",label:"Vencord",element:Vencord.Components.Settings},` +
`{section:"VencordUpdater",label:"Updater",element:Vencord.Components.Updater,predicate:()=>!IS_WEB},` +
'{section:"VencordSetting",label:"Vencord",element:Vencord.Components.Settings},' +
'{section:"VencordUpdater",label:"Updater",element:Vencord.Components.Updater,predicate:()=>!IS_WEB},' +
`{section:${mod}.ID.DIVIDER},${m}`
}

View file

@ -1,5 +1,5 @@
import definePlugin from '../utils/types';
import { Devs } from '../utils/constants';
import definePlugin from "../utils/types";
import { Devs } from "../utils/constants";
export default definePlugin({
name: "SilentTyping",

View file

@ -1,6 +1,6 @@
import definePlugin from "../utils/types";
import { addPreSendListener, addPreEditListener, MessageObject, removePreSendListener, removePreEditListener } from '../api/MessageEvents';
import { Devs } from '../utils/constants';
import { addPreSendListener, addPreEditListener, MessageObject, removePreSendListener, removePreEditListener } from "../api/MessageEvents";
import { Devs } from "../utils/constants";
export default definePlugin({
name: "Unindent",

View file

@ -1,6 +1,6 @@
import { Devs } from "../utils/constants";
import IpcEvents from "../utils/IpcEvents";
import definePlugin from '../utils/types';
import definePlugin from "../utils/types";
const OPEN_URL = "Vencord.Plugins.plugins.ViewIcons.openImage(";
export default definePlugin({

View file

@ -2,7 +2,7 @@ import electron, { contextBridge, webFrame } from "electron";
import { readFileSync } from "fs";
import { join } from "path";
import VencordNative from "./VencordNative";
import { ipcRenderer } from 'electron';
import { ipcRenderer } from "electron";
import IpcEvents from "./utils/IpcEvents";
if (electron.desktopCapturer === void 0) {
@ -15,7 +15,7 @@ if (electron.desktopCapturer === void 0) {
require.cache[electronPath]!.exports = {
...electron,
desktopCapturer: {
getSources: (opts) => ipcRenderer.invoke(IpcEvents.GET_DESKTOP_CAPTURE_SOURCES, opts)
getSources: opts => ipcRenderer.invoke(IpcEvents.GET_DESKTOP_CAPTURE_SOURCES, opts)
}
};
}

View file

@ -18,11 +18,11 @@ let modalId = 1337;
*/
export function openModal(Component: React.ComponentType, modalProps: Record<string, any>) {
let key = `Vencord${modalId++}`;
modals.openModal(props =>
modals.openModal(props => (
<Modal.ModalRoot {...props} {...modalProps}>
<Component />
</Modal.ModalRoot>
, { modalKey: key });
), { modalKey: key });
return key;
};

View file

@ -1,7 +1,7 @@
import IpcEvents from "./IpcEvents";
import Logger from "./logger";
import { IpcRes } from './types';
import gitHash from 'git-hash';
import { IpcRes } from "./types";
import gitHash from "git-hash";
export const UpdateLogger = new Logger("Updater", "white");
export let isOutdated = false;

View file

@ -1,8 +1,8 @@
import { waitFor, filters, _resolveReady } from './webpack';
import { waitFor, filters, _resolveReady } from "./webpack";
import type Components from "discord-types/components";
import type Stores from "discord-types/stores";
import type Other from "discord-types/other";
import { lazyWebpack } from '../utils/misc';
import { lazyWebpack } from "../utils/misc";
export const Margins = lazyWebpack(filters.byProps(["marginTop20"]));

View file

@ -1,4 +1,4 @@
import { WEBPACK_CHUNK } from '../utils/constants';
import { WEBPACK_CHUNK } from "../utils/constants";
import Logger from "../utils/logger";
import { _initWebpack } from ".";
@ -8,7 +8,7 @@ const logger = new Logger("WebpackInterceptor", "#8caaee");
Object.defineProperty(window, WEBPACK_CHUNK, {
get: () => webpackChunk,
set: (v) => {
set: v => {
if (v?.push !== Array.prototype.push) {
logger.info(`Patching ${WEBPACK_CHUNK}.push`);
_initWebpack(v);
@ -141,7 +141,7 @@ function patchPush() {
handlePush.original = window[WEBPACK_CHUNK].push;
Object.defineProperty(window[WEBPACK_CHUNK], "push", {
get: () => handlePush,
set: (v) => (handlePush.original = v),
set: v => (handlePush.original = v),
configurable: true
});
}

View file

@ -36,7 +36,7 @@ export type CallbackFn = (mod: any) => void;
export function _initWebpack(instance: typeof window.webpackChunkdiscord_app) {
if (cache !== void 0) throw "no.";
wreq = instance.push([[Symbol()], {}, (r) => r]);
wreq = instance.push([[Symbol()], {}, r => r]);
cache = wreq.c;
instance.pop();
}