chore: upgrade eslint and prettier (#2376)

* chore: upgrade eslint and prettier

* chore: add restrict-template-expressions
This commit is contained in:
Mo
2023-07-27 14:36:05 -05:00
committed by GitHub
parent acc41edb02
commit 4a29e2a24c
1283 changed files with 4416 additions and 5131 deletions

View File

@@ -72,6 +72,7 @@ export class FilesManager implements FilesManagerInterface {
if (!stat.isDirectory()) {
throw new Error('Tried to create a directory where a file of the same ' + `name already exists: ${dirPath}`)
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
if (error.code === FileErrorCodes.FileDoesNotExist) {
/**
@@ -83,6 +84,7 @@ export class FilesManager implements FilesManagerInterface {
/** Now that its parent(s) exist, create the directory */
try {
await fs.promises.mkdir(dirPath)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
if (error.code === FileErrorCodes.FileAlreadyExists) {
/**
@@ -257,6 +259,7 @@ export class FilesManager implements FilesManagerInterface {
try {
await this.ensureDirectoryExists(path.dirname(filepath))
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
return tryReject(error)
}
@@ -299,6 +302,7 @@ export class FilesManager implements FilesManagerInterface {
try {
await fs.promises.unlink(filePath)
break
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
if (error.code === FileErrorCodes.OperationNotPermitted || error.code === FileErrorCodes.DeviceIsBusy) {
await new Promise((resolve) => setTimeout(resolve, 300))

View File

@@ -4,7 +4,12 @@ import { downloadData } from './FileNetworking'
export class FileDownloader {
writeStream: WriteStream
constructor(private chunkSizes: number[], private valetToken: string, private url: string, filePath: string) {
constructor(
private chunkSizes: number[],
private valetToken: string,
private url: string,
filePath: string,
) {
this.writeStream = createWriteStream(filePath, { flags: 'a' })
}

View File

@@ -33,7 +33,10 @@ export class HomeServerManager implements HomeServerManagerInterface {
private homeServer?: TempHomeServerInterface
constructor(private webContents: WebContents, private filesManager: FilesManagerInterface) {}
constructor(
private webContents: WebContents,
private filesManager: FilesManagerInterface,
) {}
async getHomeServerUrl(): Promise<string | undefined> {
const homeServerConfiguration = await this.getHomeServerConfigurationObject()

View File

@@ -17,9 +17,7 @@ import { TrayManager } from '../TrayManager'
import { autoUpdatingAvailable } from '../Types/Constants'
import { isLinux, isMac } from '../Types/Platforms'
import { checkForUpdate, openChangelog, showUpdateInstallationDialog } from '../UpdateManager'
import { handleTestMessage } from '../Utils/Testing'
import { isDev, isTesting } from '../Utils/Utils'
import { MessageType } from './../../../../test/TestIpcMessage'
import { isDev } from '../Utils/Utils'
import { SpellcheckerManager } from './../SpellcheckerManager'
import { MenuManagerInterface } from './MenuManagerInterface'
@@ -123,42 +121,7 @@ export function createMenuManager({
}): MenuManagerInterface {
let menu: Menu
if (isTesting()) {
// eslint-disable-next-line no-var
var hasReloaded = false
// eslint-disable-next-line no-var
var hasReloadedTimeout: any
handleTestMessage(MessageType.AppMenuItems, () =>
menu.items.map((item) => ({
label: item.label,
role: item.role,
submenu: {
items: item.submenu?.items?.map((subItem) => ({
id: subItem.id,
label: subItem.label,
})),
},
})),
)
handleTestMessage(MessageType.ClickLanguage, (code) => {
menu.getMenuItemById(MessageType.ClickLanguage + code)!.click()
})
handleTestMessage(MessageType.HasReloadedMenu, () => hasReloaded)
}
function reload() {
if (isTesting()) {
// eslint-disable-next-line block-scoped-var
hasReloaded = true
// eslint-disable-next-line block-scoped-var
clearTimeout(hasReloadedTimeout)
// eslint-disable-next-line block-scoped-var
hasReloadedTimeout = setTimeout(() => {
// eslint-disable-next-line block-scoped-var
hasReloaded = false
}, 300)
}
menu = Menu.buildFromTemplate([
...(isMac() ? [macAppMenu(app.name)] : []),
editMenu(spellcheckerManager, reload),
@@ -270,7 +233,10 @@ function macAppMenu(appName: string): MenuItemConstructorOptions {
}
}
function editMenu(spellcheckerManager: SpellcheckerManager | undefined, reload: () => any): MenuItemConstructorOptions {
function editMenu(
spellcheckerManager: SpellcheckerManager | undefined,
reload: () => void,
): MenuItemConstructorOptions {
if (isDev()) {
/** Check for invalid state */
if (!isMac() && spellcheckerManager === undefined) {
@@ -323,13 +289,13 @@ function macSpeechMenu(): MenuItemConstructorOptions {
}
}
function spellcheckerMenu(spellcheckerManager: SpellcheckerManager, reload: () => any): MenuItemConstructorOptions {
function spellcheckerMenu(spellcheckerManager: SpellcheckerManager, reload: () => void): MenuItemConstructorOptions {
return {
id: MenuId.SpellcheckerLanguages,
label: str().spellcheckerLanguages,
submenu: spellcheckerManager.languages().map(
({ name, code, enabled }): MenuItemConstructorOptions => ({
...(isTesting() ? { id: MessageType.ClickLanguage + code } : {}),
...{},
label: name,
type: MenuItemTypes.CheckBox,
checked: enabled,
@@ -346,7 +312,7 @@ function spellcheckerMenu(spellcheckerManager: SpellcheckerManager, reload: () =
}
}
function viewMenu(window: Electron.BrowserWindow, store: Store, reload: () => any): MenuItemConstructorOptions {
function viewMenu(window: Electron.BrowserWindow, store: Store, reload: () => void): MenuItemConstructorOptions {
return {
label: str().view,
submenu: [
@@ -375,7 +341,7 @@ function viewMenu(window: Electron.BrowserWindow, store: Store, reload: () => an
}
}
function menuBarOptions(window: Electron.BrowserWindow, store: Store, reload: () => any) {
function menuBarOptions(window: Electron.BrowserWindow, store: Store, reload: () => void) {
const useSystemMenuBar = store.get(StoreKeys.UseSystemMenuBar)
let isMenuBarVisible = store.get(StoreKeys.MenuBarVisible)
window.setMenuBarVisibility(isMenuBarVisible)
@@ -406,7 +372,7 @@ function menuBarOptions(window: Electron.BrowserWindow, store: Store, reload: ()
]
}
function windowMenu(store: Store, trayManager: TrayManager, reload: () => any): MenuItemConstructorOptions {
function windowMenu(store: Store, trayManager: TrayManager, reload: () => void): MenuItemConstructorOptions {
return {
role: Roles.Window,
submenu: [
@@ -446,7 +412,7 @@ function macWindowItems(): MenuItemConstructorOptions[] {
]
}
function minimizeToTrayItem(store: Store, trayManager: TrayManager, reload: () => any) {
function minimizeToTrayItem(store: Store, trayManager: TrayManager, reload: () => void) {
const minimizeToTray = trayManager.shouldMinimizeToTray()
return {
label: str().minimizeToTrayOnClose,

View File

@@ -48,7 +48,10 @@ class MappingFileHandler {
return new MappingFileHandler(mapping, filesManager)
}
constructor(private mapping: MappingFile, private filesManager: FilesManagerInterface) {}
constructor(
private mapping: MappingFile,
private filesManager: FilesManagerInterface,
) {}
get = (componendId: string) => {
return this.mapping[componendId]

View File

@@ -5,6 +5,7 @@ import { StoreData, StoreKeys } from './StoreKeys'
import { logError } from './Store'
import { FileErrorCodes } from '../File/FileErrorCodes'
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function createSanitizedStoreData(data: any = {}): StoreData {
return {
[StoreKeys.MenuBarVisible]: ensureIsBoolean(data[StoreKeys.MenuBarVisible], true),
@@ -27,6 +28,8 @@ export function createSanitizedStoreData(data: any = {}): StoreData {
[StoreKeys.LegacyFileBackupsLocation]: data[StoreKeys.LegacyFileBackupsLocation],
}
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function sanitizeZoomFactor(factor?: any): number {
if (typeof factor === 'number' && factor > 0) {
return factor
@@ -67,7 +70,9 @@ export function parseDataFile(filePath: string) {
const fileData = fs.readFileSync(filePath)
const userData = JSON.parse(fileData.toString())
return createSanitizedStoreData(userData)
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
// eslint-disable-next-line no-console
console.log('Error reading store file', error)
if (error.code !== FileErrorCodes.FileDoesNotExist) {
logError(error)