From 8c131073730ec684145c2cc8ee8d6b39bbe9278d Mon Sep 17 00:00:00 2001 From: MCMXC <16797721+mcmxcdev@users.noreply.github.com> Date: Sun, 23 Jul 2023 20:08:52 -0600 Subject: chore: improve lint setup - update eslint config - merged eslint rules for JS and TS to avoid duplicates - extended stricter lint ruleset from typescript-eslint - corrected wrong setup for certain eslint rulesets - opt in to reportUnusedDisableDirectives config option - fix or disable a lot of lint issues throughout codebase - remove trailingComma: all from prettier config which is default in prettier v3 - add volta configuration to package.json to autoload correct node and pnpm versions - upgrade all eslint and prettier related dependencies to latest - remove config options from settings.json which are default anyways - remove config options from settings.json which are outdated/unknown - set up prettier as default formatter in settings.json --- src/webview/contextMenuBuilder.ts | 7 ++++--- src/webview/lib/Userscript.ts | 9 +++++---- src/webview/recipe.ts | 17 +++++++++-------- 3 files changed, 18 insertions(+), 15 deletions(-) (limited to 'src/webview') diff --git a/src/webview/contextMenuBuilder.ts b/src/webview/contextMenuBuilder.ts index 6d904eee3..d18bc56f9 100644 --- a/src/webview/contextMenuBuilder.ts +++ b/src/webview/contextMenuBuilder.ts @@ -52,8 +52,8 @@ function translatePopup(res, isError: boolean = false) { z-index: 999999; ${ isError - ? `background: rgb(255 37 37);` - : `background: rgb(131 131 131);` + ? 'background: rgb(255 37 37);' + : 'background: rgb(131 131 131);' } border-radius: 8px; top: 5%; @@ -148,7 +148,7 @@ const contextMenuStringTable: ContextMenuStringTable = { paste: () => 'Paste', pasteAndMatchStyle: () => 'Paste and match style', searchWith: ({ searchEngine }) => `Search with ${searchEngine}`, - translate: () => `Translate to ...`, + translate: () => 'Translate to ...', quickTranslate: ({ translatorLanguage }) => `Translate to ${translatorLanguage}`, translateLanguage: ({ translatorLanguage }) => `${translatorLanguage}`, @@ -798,6 +798,7 @@ export class ContextMenuBuilder { callback: { (dataURL: any): void; (dataURL: any): void; + // eslint-disable-next-line @typescript-eslint/unified-signatures (arg0: string): void; }, outputFormat: string = 'image/png', diff --git a/src/webview/lib/Userscript.ts b/src/webview/lib/Userscript.ts index b0e4fb805..5adc1ac3a 100644 --- a/src/webview/lib/Userscript.ts +++ b/src/webview/lib/Userscript.ts @@ -32,7 +32,7 @@ export default class Userscript { * * @param {*} settings */ - // eslint-disable-next-line camelcase + internal_setSettings(settings: any) { // This is needed to get a clean JS object from the settings itself to provide better accessibility // Otherwise this will be a mobX instance @@ -45,7 +45,7 @@ export default class Userscript { * @param {number} indirect Indirect messages */ setBadge(direct: number = 0, indirect: number = 0) { - if (this.recipe && this.recipe.setBadge) { + if (this.recipe?.setBadge) { this.recipe.setBadge(direct, indirect); } } @@ -55,7 +55,7 @@ export default class Userscript { * @param {*} title Dialog title */ setDialogTitle(title: string) { - if (this.recipe && this.recipe.setDialogTitle) { + if (this.recipe?.setDialogTitle) { this.recipe.setDialogTitle(title); } } @@ -66,7 +66,7 @@ export default class Userscript { * @param {...string} files */ injectCSSFiles(...files: string[]) { - if (this.recipe && this.recipe.injectCSS) { + if (this.recipe?.injectCSS) { // @ts-expect-error A spread argument must either have a tuple type or be passed to a rest parameter. this.recipe.injectCSS(...files); } @@ -99,6 +99,7 @@ export default class Userscript { * @param {string} key * @return Value of the key */ + // eslint-disable-next-line consistent-return get(key: string) { const ferdiumUserKey = window.localStorage.getItem(`ferdium-user-${key}`); diff --git a/src/webview/recipe.ts b/src/webview/recipe.ts index 0d18e4347..76615d234 100644 --- a/src/webview/recipe.ts +++ b/src/webview/recipe.ts @@ -1,6 +1,6 @@ /* eslint-disable global-require */ /* eslint-disable import/no-dynamic-require */ -/* eslint-disable import/first */ + import { noop, debounce } from 'lodash'; import { contextBridge, ipcRenderer } from 'electron'; import { join } from 'path'; @@ -52,7 +52,7 @@ import Service from '../models/Service'; // This will cause the service to fail loading // As the message API is not actually needed, we'll add this shim sendMessage // function in order for darkreader to continue working -// @ts-ignore +// @ts-expect-error Fix this window.chrome.runtime.sendMessage = noop; const debug = require('../preload-safe-debug')('Ferdium:Plugin'); @@ -143,9 +143,9 @@ class RecipeController { service: Service; } = { overrideSpellcheckerLanguage: false, - // @ts-ignore + // @ts-expect-error Fix this app: DEFAULT_APP_SETTINGS, - // @ts-ignore + // @ts-expect-error Fix this service: { isDarkModeEnabled: false, spellcheckerLanguage: '', @@ -233,6 +233,7 @@ class RecipeController { const modulePath = join(recipe.path, 'webview.js'); debug('module path', modulePath); // Delete module from cache + // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete require.cache[require.resolve(modulePath)]; try { this.recipe = new RecipeWebview( @@ -311,7 +312,7 @@ class RecipeController { debug('translatorEngine', this.settings.app.translatorEngine); debug('translatorLanguage', this.settings.app.translatorLanguage); - if (this.userscript && this.userscript.internal_setSettings) { + if (this.userscript?.internal_setSettings) { this.userscript.internal_setSettings(this.settings); } @@ -339,7 +340,7 @@ class RecipeController { 'Darkmode enabled?', this.settings.service.isDarkModeEnabled, 'Dark theme active?', - // @ts-ignore + // @ts-expect-error Fix this this.settings.app.isDarkThemeActive, ); @@ -356,7 +357,7 @@ class RecipeController { debug('Enable dark mode'); // Check if recipe has a custom dark mode handler - if (this.recipe && this.recipe.darkModeHandler) { + if (this.recipe?.darkModeHandler) { debug('Using custom dark mode handler'); // Remove other dark mode styles if they were already loaded @@ -399,7 +400,7 @@ class RecipeController { debug('Remove dark mode'); debug('DarkMode disabled - removing remaining styles'); - if (this.recipe && this.recipe.darkModeHandler) { + if (this.recipe?.darkModeHandler) { // Remove other dark mode styles if they were already loaded if (this.hasUpdatedBeforeRecipeLoaded) { this.hasUpdatedBeforeRecipeLoaded = false; -- cgit v1.2.3-70-g09d2