From 8684887fc6ab8b99c6284199bf59fe22b6b0c317 Mon Sep 17 00:00:00 2001 From: Ronan Jouchet Date: Sat, 18 Jul 2020 11:19:58 -0400 Subject: [PATCH] Bump eslint to 7.x, fix new lint errors --- .eslintrc.js | 8 ++++++-- app/.eslintrc.js | 12 ++++++++---- app/src/components/contextMenu.ts | 2 +- app/src/components/loginWindow.ts | 1 + app/src/components/mainWindow.ts | 22 +++++++++++++++++----- app/src/components/menu.ts | 2 ++ package.json | 6 +++--- src/build/buildNativefierApp.ts | 1 + src/build/prepareElectronApp.ts | 2 +- src/infer/inferIcon.ts | 4 ++-- src/main.ts | 2 +- src/options/fields/name.test.ts | 4 +++- src/options/fields/name.ts | 4 ++-- src/options/optionsMain.ts | 2 ++ src/utils/sanitizeFilename.ts | 2 +- 15 files changed, 51 insertions(+), 23 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 503225e..5be31f4 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -16,8 +16,12 @@ module.exports = { ], rules: { 'prettier/prettier': 'error', - // TODO remove when done killing anys and making tsc strict + // TODO remove when done killing `any`s and making tsc strict + '@typescript-eslint/ban-ts-comment': 'off', '@typescript-eslint/no-explicit-any': 'off', - '@typescript-eslint/ban-ts-ignore': 'off', + '@typescript-eslint/no-unsafe-assignment': 'off', + '@typescript-eslint/no-unsafe-call': 'off', + '@typescript-eslint/no-unsafe-member-access': 'off', + '@typescript-eslint/no-unsafe-return': 'off', }, }; diff --git a/app/.eslintrc.js b/app/.eslintrc.js index e474023..5ea6a39 100644 --- a/app/.eslintrc.js +++ b/app/.eslintrc.js @@ -15,10 +15,14 @@ module.exports = { ], rules: { 'prettier/prettier': 'error', - // TODO remove when done killing anys and making tsc strict + // TODO remove when done killing `any`s and making tsc strict + '@typescript-eslint/ban-ts-comment': 'off', + '@typescript-eslint/explicit-module-boundary-types': 'off', '@typescript-eslint/no-explicit-any': 'off', - '@typescript-eslint/ban-ts-ignore': 'off', - '@typescript-eslint/no-use-before-define': 'off', - '@typescript-eslint/explicit-function-return-type': 'off', + '@typescript-eslint/no-unsafe-assignment': 'off', + '@typescript-eslint/no-unsafe-call': 'off', + '@typescript-eslint/no-unsafe-member-access': 'off', + '@typescript-eslint/no-unsafe-return': 'off', + '@typescript-eslint/restrict-template-expressions': 'off' }, }; diff --git a/app/src/components/contextMenu.ts b/app/src/components/contextMenu.ts index 37eebf9..6b8d395 100644 --- a/app/src/components/contextMenu.ts +++ b/app/src/components/contextMenu.ts @@ -9,7 +9,7 @@ export function initContextMenu(createNewWindow, createNewTab): void { items.push({ label: 'Open Link in Default Browser', click: () => { - shell.openExternal(params.linkURL); + shell.openExternal(params.linkURL); // eslint-disable-line @typescript-eslint/no-floating-promises }, }); items.push({ diff --git a/app/src/components/loginWindow.ts b/app/src/components/loginWindow.ts index 20c99c4..272bffa 100644 --- a/app/src/components/loginWindow.ts +++ b/app/src/components/loginWindow.ts @@ -12,6 +12,7 @@ export function createLoginWindow(loginCallback): BrowserWindow { nodeIntegration: true, // TODO work around this; insecure }, }); + // eslint-disable-next-line @typescript-eslint/no-floating-promises loginWindow.loadURL(`file://${path.join(__dirname, 'static/login.html')}`); ipcMain.once('login-message', (event, usernameAndPassword) => { diff --git a/app/src/components/mainWindow.ts b/app/src/components/mainWindow.ts index 482570e..b303b35 100644 --- a/app/src/components/mainWindow.ts +++ b/app/src/components/mainWindow.ts @@ -49,6 +49,7 @@ function injectCss(browserWindow: BrowserWindow): void { browserWindow.webContents.session.webRequest.onHeadersReceived( { urls: [] }, // Pass an empty filter list; null will not match _any_ urls (details, callback) => { + // eslint-disable-next-line @typescript-eslint/no-floating-promises browserWindow.webContents.insertCSS(cssToInject); callback({ cancel: false, responseHeaders: details.responseHeaders }); }, @@ -63,6 +64,7 @@ async function clearCache(browserWindow: BrowserWindow): Promise { } function setProxyRules(browserWindow: BrowserWindow, proxyRules): void { + // eslint-disable-next-line @typescript-eslint/no-floating-promises browserWindow.webContents.session.setProxy({ proxyRules, pacScript: '', @@ -136,9 +138,11 @@ export function createMainWindow( path.join(__dirname, '..', 'nativefier.json'), JSON.stringify(options), ); - } catch (exception) { + } catch (err) { // eslint-disable-next-line no-console - console.log(`WARNING: Ignored nativefier.json rewrital (${exception})`); + console.log( + `WARNING: Ignored nativefier.json rewrital (${(err as Error).toString()})`, + ); } } @@ -150,7 +154,10 @@ export function createMainWindow( return undefined; }; - const adjustWindowZoom = (window: BrowserWindow, adjustment): void => { + const adjustWindowZoom = ( + window: BrowserWindow, + adjustment: number, + ): void => { window.webContents.zoomFactor = window.webContents.zoomFactor + adjustment; }; @@ -206,7 +213,7 @@ export function createMainWindow( const onWillNavigate = (event: Event, urlToGo: string): void => { if (!linkIsInternal(options.targetUrl, urlToGo, options.internalUrls)) { event.preventDefault(); - shell.openExternal(urlToGo); + shell.openExternal(urlToGo); // eslint-disable-line @typescript-eslint/no-floating-promises } }; @@ -224,7 +231,7 @@ export function createMainWindow( sendParamsOnDidFinishLoad(window); window.webContents.on('new-window', onNewWindow); window.webContents.on('will-navigate', onWillNavigate); - window.loadURL(url); + window.loadURL(url); // eslint-disable-line @typescript-eslint/no-floating-promises return window; }; @@ -283,6 +290,7 @@ export function createMainWindow( // In children windows too: Restore pinch-to-zoom, disabled by default in recent Electron. // See https://github.com/jiahaog/nativefier/issues/379#issuecomment-598612128 // and https://github.com/electron/electron/pull/12679 + // eslint-disable-next-line @typescript-eslint/no-floating-promises window.webContents.setVisualZoomLevelLimits(1, 3); window.webContents.send('params', JSON.stringify(options)); @@ -353,6 +361,7 @@ export function createMainWindow( // Restore pinch-to-zoom, disabled by default in recent Electron. // See https://github.com/jiahaog/nativefier/issues/379#issuecomment-598309817 // and https://github.com/electron/electron/pull/12679 + // eslint-disable-next-line @typescript-eslint/no-floating-promises mainWindow.webContents.setVisualZoomLevelLimits(1, 3); // Remove potential css injection code set in `did-navigate`) (see injectCss code) @@ -360,9 +369,11 @@ export function createMainWindow( }); if (options.clearCache) { + // eslint-disable-next-line @typescript-eslint/no-floating-promises clearCache(mainWindow); } + // eslint-disable-next-line @typescript-eslint/no-floating-promises mainWindow.loadURL(options.targetUrl); // @ts-ignore @@ -382,6 +393,7 @@ export function createMainWindow( hideWindow(mainWindow, event, options.fastQuit, options.tray); if (options.clearCache) { + // eslint-disable-next-line @typescript-eslint/no-floating-promises clearCache(mainWindow); } }); diff --git a/app/src/components/menu.ts b/app/src/components/menu.ts index f2e7474..75fdedd 100644 --- a/app/src/components/menu.ts +++ b/app/src/components/menu.ts @@ -220,12 +220,14 @@ export function createMenu({ { label: `Built with Nativefier v${nativefierVersion}`, click: () => { + // eslint-disable-next-line @typescript-eslint/no-floating-promises shell.openExternal('https://github.com/jiahaog/nativefier'); }, }, { label: 'Report an Issue', click: () => { + // eslint-disable-next-line @typescript-eslint/no-floating-promises shell.openExternal('https://github.com/jiahaog/nativefier/issues'); }, }, diff --git a/package.json b/package.json index dd6d370..9fc30bd 100644 --- a/package.json +++ b/package.json @@ -75,9 +75,9 @@ }, "devDependencies": { "@types/jest": "26.x", - "@typescript-eslint/eslint-plugin": "2.x", - "@typescript-eslint/parser": "2.x", - "eslint": "6.x", + "@typescript-eslint/eslint-plugin": "3.x", + "@typescript-eslint/parser": "3.x", + "eslint": "7.x", "eslint-config-prettier": "6.x", "eslint-plugin-prettier": "3.x", "jest": "26.x", diff --git a/src/build/buildNativefierApp.ts b/src/build/buildNativefierApp.ts index 7598d3a..2f42a2c 100644 --- a/src/build/buildNativefierApp.ts +++ b/src/build/buildNativefierApp.ts @@ -98,6 +98,7 @@ function trimUnprocessableOptions(options: AppOptions): void { } } +// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export async function buildNativefierApp(rawOptions: any): Promise { log.info('Processing options...'); const options = await getOptions(rawOptions); diff --git a/src/build/prepareElectronApp.ts b/src/build/prepareElectronApp.ts index 7d2cb98..7a86d71 100644 --- a/src/build/prepareElectronApp.ts +++ b/src/build/prepareElectronApp.ts @@ -134,7 +134,7 @@ export async function prepareElectronApp( try { await copyFileOrDir(src, dest); } catch (err) { - throw `Error copying electron app from ${src} to temp dir ${dest}. Error: ${err}`; + throw `Error copying electron app from ${src} to temp dir ${dest}. Error: ${(err as Error).toString()}`; } const appJsonPath = path.join(dest, '/nativefier.json'); diff --git a/src/infer/inferIcon.ts b/src/infer/inferIcon.ts index 9dee947..a9ab2a7 100644 --- a/src/infer/inferIcon.ts +++ b/src/infer/inferIcon.ts @@ -39,7 +39,7 @@ function mapIconWithMatchScore(cloudIcons: any[], targetUrl: string): any { const normalisedTargetUrl = targetUrl.toLowerCase(); return cloudIcons.map((item) => { const itemWords = item.name.split(GITCLOUD_SPACE_DELIMITER); - const score = itemWords.reduce((currentScore, word) => { + const score = itemWords.reduce((currentScore: number, word: string) => { if (normalisedTargetUrl.includes(word)) { return currentScore + 1; } @@ -57,7 +57,7 @@ async function inferIconFromStore( log.debug(`Inferring icon from store for ${targetUrl} on ${platform}`); const allowedFormats = new Set(getAllowedIconFormats(platform)); - const cloudIcons = await gitCloud(GITCLOUD_URL); + const cloudIcons: any[] = await gitCloud(GITCLOUD_URL); log.debug(`Got ${cloudIcons.length} icons from gitcloud`); const iconWithScores = mapIconWithMatchScore(cloudIcons, targetUrl); const maxScore = getMaxMatchScore(iconWithScores); diff --git a/src/main.ts b/src/main.ts index db5b1b2..c453d53 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,7 +9,7 @@ export { buildNativefierApp }; * Use the better, modern async `buildNativefierApp` instead if you can! */ function buildNativefierAppOldCallbackStyle( - options: any, + options: any, // eslint-disable-line @typescript-eslint/explicit-module-boundary-types callback: (err: any, result?: any) => void, ): void { buildNativefierApp(options) diff --git a/src/options/fields/name.test.ts b/src/options/fields/name.test.ts index c7758c4..6d5cc39 100644 --- a/src/options/fields/name.test.ts +++ b/src/options/fields/name.test.ts @@ -24,7 +24,9 @@ const NAME_PARAMS_NEEDS_INFER = { }, }; beforeAll(() => { - (sanitizeFilename as jest.Mock).mockImplementation((_, filename) => filename); + (sanitizeFilename as jest.Mock).mockImplementation( + (_, filename: string) => filename, + ); }); describe('well formed name parameters', () => { diff --git a/src/options/fields/name.ts b/src/options/fields/name.ts index d63208f..4005f54 100644 --- a/src/options/fields/name.ts +++ b/src/options/fields/name.ts @@ -17,9 +17,9 @@ async function tryToInferName(targetUrl: string): Promise { log.debug('Inferring name for', targetUrl); const pageTitle = await inferTitle(targetUrl); return pageTitle || DEFAULT_APP_NAME; - } catch (error) { + } catch (err) { log.warn( - `Unable to automatically determine app name, falling back to '${DEFAULT_APP_NAME}'. Reason: ${error}`, + `Unable to automatically determine app name, falling back to '${DEFAULT_APP_NAME}'. Reason: ${(err as Error).toString()}`, ); return DEFAULT_APP_NAME; } diff --git a/src/options/optionsMain.ts b/src/options/optionsMain.ts index c5b43f0..f7af2df 100644 --- a/src/options/optionsMain.ts +++ b/src/options/optionsMain.ts @@ -20,6 +20,7 @@ const SEMVER_VERSION_NUMBER_REGEX = /\d+\.\d+\.\d+[-_\w\d.]*/; /** * Process and validate raw user arguments */ +// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export async function getOptions(rawOptions: any): Promise { const options: AppOptions = { packager: { @@ -96,6 +97,7 @@ export async function getOptions(rawOptions: any): Promise { if (options.nativefier.verbose) { log.setLevel('trace'); try { + // eslint-disable-next-line @typescript-eslint/no-var-requires require('debug').enable('electron-packager'); } catch (err) { log.debug( diff --git a/src/utils/sanitizeFilename.ts b/src/utils/sanitizeFilename.ts index 7e16fc7..7023dab 100644 --- a/src/utils/sanitizeFilename.ts +++ b/src/utils/sanitizeFilename.ts @@ -9,7 +9,7 @@ export function sanitizeFilename( platform: string, filenameToSanitize: string, ): string { - let result = sanitize(filenameToSanitize); + let result: string = sanitize(filenameToSanitize); // remove all non ascii or use default app name // eslint-disable-next-line no-control-regex