Bump eslint to 7.x, fix new lint errors

This commit is contained in:
Ronan Jouchet 2020-07-18 11:19:58 -04:00
parent 30f7aff7a9
commit 8684887fc6
15 changed files with 51 additions and 23 deletions

View File

@ -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',
},
};

View File

@ -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'
},
};

View File

@ -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({

View File

@ -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) => {

View File

@ -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<void> {
}
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);
}
});

View File

@ -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');
},
},

View File

@ -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",

View File

@ -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<string> {
log.info('Processing options...');
const options = await getOptions(rawOptions);

View File

@ -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');

View File

@ -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);

View File

@ -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)

View File

@ -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', () => {

View File

@ -17,9 +17,9 @@ async function tryToInferName(targetUrl: string): Promise<string> {
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;
}

View File

@ -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<AppOptions> {
const options: AppOptions = {
packager: {
@ -96,6 +97,7 @@ export async function getOptions(rawOptions: any): Promise<AppOptions> {
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(

View File

@ -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