From 4ab72b8dd981b3c3362f9c9aa7ee30b11db42d13 Mon Sep 17 00:00:00 2001 From: amsyarasyiq <82711525+amsyarasyiq@users.noreply.github.com> Date: Sun, 12 Feb 2023 22:48:12 +0800 Subject: [PATCH] Main: add ESLint --- .eslintrc.json | 41 +++++++++++++++++++++++++++++ build.mjs | 8 +++++- package.json | 10 ++++++- plugins/HideGiftButton/src/index.ts | 4 +-- plugins/Last.fm/src/index.ts | 14 +++++----- plugins/Last.fm/src/settings.tsx | 23 +++++++++------- plugins/Last.fm/src/types.ts | 1 + plugins/Last.fm/src/utils.ts | 24 ++++++++--------- plugins/MoreConfirm/src/index.ts | 4 +-- plugins/NoIdle/src/index.ts | 2 +- 10 files changed, 96 insertions(+), 35 deletions(-) create mode 100644 .eslintrc.json diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..ab5b5aa --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,41 @@ +{ + "env": { + "es2021": true, + "node": true + }, + "extends": [ + "eslint:recommended", + "plugin:react/recommended", + "plugin:@typescript-eslint/recommended" + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaFeatures": { + "jsx": true + }, + "ecmaVersion": "latest", + "sourceType": "module" + }, + "plugins": [ + "react", + "@typescript-eslint" + ], + "rules": { + "indent": [ + "error", + 4 + ], + "quotes": [ + "error", + "double" + ], + "semi": [ + "error", + "always" + ], + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/ban-ts-comment": "off", + "@typescript-eslint/triple-slash-reference": "off", + "eol-last": "error" + } +} diff --git a/build.mjs b/build.mjs index 12e53aa..677b678 100644 --- a/build.mjs +++ b/build.mjs @@ -13,7 +13,13 @@ for (const plug of await readdir("./plugins")) { try { const bundle = await rollup({ input: `./plugins/${plug}/${manifest.main}`, - onwarn: () => { }, + onwarn: (warning) => { + ![ + "UNRESOLVED_IMPORT", + "MISSING_NAME_OPTION_FOR_IIFE_EXPORT", + "CIRCULAR_DEPENDENCY" + ].includes(warning.code) && console.warn(warning); + }, plugins: [ nodeResolve(), commonjs(), diff --git a/package.json b/package.json index 8017d32..abcfa29 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,21 @@ { "scripts": { - "build": "node build.mjs" + "build": "node build.mjs", + "lint": "eslint plugins" }, "devDependencies": { "@rollup/plugin-commonjs": "^24.0.1", + "@rollup/plugin-eslint": "^9.0.3", "@rollup/plugin-node-resolve": "^15.0.1", + "@rollup/plugin-typescript": "^11.0.0", + "@typescript-eslint/eslint-plugin": "^5.51.0", + "@typescript-eslint/parser": "^5.51.0", "esbuild": "^0.16.17", + "eslint": "^8.34.0", + "eslint-plugin-react": "^7.32.2", "rollup": "^3.15.0", "rollup-plugin-esbuild": "^5.0.0", + "typescript": "^4.9.5", "vendetta-types": "^2.3.4" } } diff --git a/plugins/HideGiftButton/src/index.ts b/plugins/HideGiftButton/src/index.ts index 17e82d4..80df01e 100644 --- a/plugins/HideGiftButton/src/index.ts +++ b/plugins/HideGiftButton/src/index.ts @@ -1,7 +1,7 @@ import { logger } from "@vendetta"; import { findByDisplayName } from "@vendetta/metro"; -let origState: Boolean; +let origState: boolean; const ChatInput = findByDisplayName("ChatInput"); export default { @@ -14,4 +14,4 @@ export default { logger.log("Unloading HideGiftButton.."); ChatInput.defaultProps.hideGiftButton = origState; } -} +}; diff --git a/plugins/Last.fm/src/index.ts b/plugins/Last.fm/src/index.ts index af7c2e1..29de04e 100644 --- a/plugins/Last.fm/src/index.ts +++ b/plugins/Last.fm/src/index.ts @@ -1,23 +1,23 @@ import { plugin } from "@vendetta"; -import { findByProps, findByStoreName } from '@vendetta/metro'; -import { FluxDispatcher } from '@vendetta/metro/common'; +import { findByProps, findByStoreName } from "@vendetta/metro"; +import { FluxDispatcher } from "@vendetta/metro/common"; import Settings from "./Settings"; import { flush, initialize, patchActivityType } from "./utils"; export const global = {} as { - stopped?: Boolean, + stopped?: boolean, lastActivity?: Activity, updateInterval?: NodeJS.Timer, lastTrackUrl?: string, activityTypeUnpatch?: () => boolean -} +}; export const currentSettings = { ...plugin.storage } as PluginSettings; // Discord modules that we need -export const UserStore = findByStoreName("UserStore") -export const SET_ACTIVITY = findByProps('SET_ACTIVITY').SET_ACTIVITY; +export const UserStore = findByStoreName("UserStore"); +export const SET_ACTIVITY = findByProps("SET_ACTIVITY").SET_ACTIVITY; export const verboseLog = (...message: any) => currentSettings.verboseLogging && console.log(...message); @@ -47,4 +47,4 @@ export default { global.activityTypeUnpatch = null; }, settings: Settings -} +}; diff --git a/plugins/Last.fm/src/settings.tsx b/plugins/Last.fm/src/settings.tsx index 5e6afbc..c16b811 100644 --- a/plugins/Last.fm/src/settings.tsx +++ b/plugins/Last.fm/src/settings.tsx @@ -3,13 +3,14 @@ import { storage } from "@vendetta/plugin"; import { useProxy } from "@vendetta/storage"; import { getAssetIDByName } from "@vendetta/ui/assets"; import { Forms } from "@vendetta/ui/components"; +import { showToast } from "@vendetta/ui/toasts"; import { currentSettings } from "."; import Constants from "./constants"; import { flush, initialize } from "./utils"; const { ScrollView, TouchableOpacity, Text } = ReactNative; -const { FormInput, FormDivider, FormSwitchRow, FormText, FormIcon, FormTextColors } = Forms; +const { FormInput, FormDivider, FormSwitchRow, FormText, FormIcon } = Forms; export default function Settings() { const settings = useProxy(storage) as PluginSettings; @@ -17,8 +18,8 @@ export default function Settings() { React.useEffect(() => { navigation.setOptions({ - headerRight: () => ( - { + headerRight: () => { + async function onPressCallback() { for (const key in storage) { if (typeof storage[key] === "boolean" || storage[key]) { currentSettings[key] = settings[key]; @@ -26,11 +27,15 @@ export default function Settings() { } console.log("Applying settings..."); - flush().then(() => initialize()); - }}> - UPDATE - - ) + await flush(); + await initialize(); + showToast("Settings updated!", getAssetIDByName("Check")); + } + + return + {"UPDATE"} + ; + } }); }, []); @@ -77,5 +82,5 @@ export default function Settings() { onValueChange={(value: boolean) => settings.verboseLogging = value} /> - ) + ); } diff --git a/plugins/Last.fm/src/types.ts b/plugins/Last.fm/src/types.ts index aff6d5d..44c43e4 100644 --- a/plugins/Last.fm/src/types.ts +++ b/plugins/Last.fm/src/types.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ type PluginSettings = { /** Application's name */ appName: string; diff --git a/plugins/Last.fm/src/utils.ts b/plugins/Last.fm/src/utils.ts index 23de96e..01762fe 100644 --- a/plugins/Last.fm/src/utils.ts +++ b/plugins/Last.fm/src/utils.ts @@ -8,12 +8,12 @@ import Constants from "./constants"; /** Fetches the latest user's scrobble */ async function fetchLatestScrobble(): Promise { const params = new URLSearchParams({ - 'method': 'user.getrecenttracks', - 'user': currentSettings.username, - 'api_key': Constants.LFM_API_KEY, - 'format': 'json', - 'limit': '1', - 'extended': '1' + "method": "user.getrecenttracks", + "user": currentSettings.username, + "api_key": Constants.LFM_API_KEY, + "format": "json", + "limit": "1", + "extended": "1" }).toString(); const info = await fetch(`https://ws.audioscrobbler.com/2.0/?${params}`).then(x => { @@ -24,12 +24,12 @@ async function fetchLatestScrobble(): Promise { return { name: lastTrack.name, artist: lastTrack.artist.name, - album: lastTrack.album['#text'], - albumArt: handleAlbumCover(lastTrack.image[3]['#text']), + album: lastTrack.album["#text"], + albumArt: handleAlbumCover(lastTrack.image[3]["#text"]), url: lastTrack.url, - date: lastTrack.date?.['#text'] ?? 'now', - nowPlaying: Boolean(lastTrack['@attr']?.nowplaying), - loved: lastTrack.loved === '1', + date: lastTrack.date?.["#text"] ?? "now", + nowPlaying: Boolean(lastTrack["@attr"]?.nowplaying), + loved: lastTrack.loved === "1", } as Track; } @@ -129,7 +129,7 @@ export async function update() { activity.assets = { large_image: lastTrack.albumArt, large_text: `on ${lastTrack.album}` - } + }; } const response = await sendRequest(activity).catch(async function (err) { diff --git a/plugins/MoreConfirm/src/index.ts b/plugins/MoreConfirm/src/index.ts index 4961292..b48eedf 100644 --- a/plugins/MoreConfirm/src/index.ts +++ b/plugins/MoreConfirm/src/index.ts @@ -46,7 +46,7 @@ export default { logger.error("Failed to start call", e); } }, - }) + }); }); } -} +}; diff --git a/plugins/NoIdle/src/index.ts b/plugins/NoIdle/src/index.ts index b95c36b..c261aff 100644 --- a/plugins/NoIdle/src/index.ts +++ b/plugins/NoIdle/src/index.ts @@ -17,4 +17,4 @@ export default { logger.log("Disabling NoIdle.."); unpatch?.(); } -} +};