mirror of https://github.com/jiahaog/Nativefier
Bump eslint to 7.x, fix new lint errors
This commit is contained in:
parent
30f7aff7a9
commit
8684887fc6
|
@ -16,8 +16,12 @@ module.exports = {
|
||||||
],
|
],
|
||||||
rules: {
|
rules: {
|
||||||
'prettier/prettier': 'error',
|
'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/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',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,10 +15,14 @@ module.exports = {
|
||||||
],
|
],
|
||||||
rules: {
|
rules: {
|
||||||
'prettier/prettier': 'error',
|
'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/no-explicit-any': 'off',
|
||||||
'@typescript-eslint/ban-ts-ignore': 'off',
|
'@typescript-eslint/no-unsafe-assignment': 'off',
|
||||||
'@typescript-eslint/no-use-before-define': 'off',
|
'@typescript-eslint/no-unsafe-call': 'off',
|
||||||
'@typescript-eslint/explicit-function-return-type': 'off',
|
'@typescript-eslint/no-unsafe-member-access': 'off',
|
||||||
|
'@typescript-eslint/no-unsafe-return': 'off',
|
||||||
|
'@typescript-eslint/restrict-template-expressions': 'off'
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,7 +9,7 @@ export function initContextMenu(createNewWindow, createNewTab): void {
|
||||||
items.push({
|
items.push({
|
||||||
label: 'Open Link in Default Browser',
|
label: 'Open Link in Default Browser',
|
||||||
click: () => {
|
click: () => {
|
||||||
shell.openExternal(params.linkURL);
|
shell.openExternal(params.linkURL); // eslint-disable-line @typescript-eslint/no-floating-promises
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
items.push({
|
items.push({
|
||||||
|
|
|
@ -12,6 +12,7 @@ export function createLoginWindow(loginCallback): BrowserWindow {
|
||||||
nodeIntegration: true, // TODO work around this; insecure
|
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')}`);
|
loginWindow.loadURL(`file://${path.join(__dirname, 'static/login.html')}`);
|
||||||
|
|
||||||
ipcMain.once('login-message', (event, usernameAndPassword) => {
|
ipcMain.once('login-message', (event, usernameAndPassword) => {
|
||||||
|
|
|
@ -49,6 +49,7 @@ function injectCss(browserWindow: BrowserWindow): void {
|
||||||
browserWindow.webContents.session.webRequest.onHeadersReceived(
|
browserWindow.webContents.session.webRequest.onHeadersReceived(
|
||||||
{ urls: [] }, // Pass an empty filter list; null will not match _any_ urls
|
{ urls: [] }, // Pass an empty filter list; null will not match _any_ urls
|
||||||
(details, callback) => {
|
(details, callback) => {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||||
browserWindow.webContents.insertCSS(cssToInject);
|
browserWindow.webContents.insertCSS(cssToInject);
|
||||||
callback({ cancel: false, responseHeaders: details.responseHeaders });
|
callback({ cancel: false, responseHeaders: details.responseHeaders });
|
||||||
},
|
},
|
||||||
|
@ -63,6 +64,7 @@ async function clearCache(browserWindow: BrowserWindow): Promise<void> {
|
||||||
}
|
}
|
||||||
|
|
||||||
function setProxyRules(browserWindow: BrowserWindow, proxyRules): void {
|
function setProxyRules(browserWindow: BrowserWindow, proxyRules): void {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||||
browserWindow.webContents.session.setProxy({
|
browserWindow.webContents.session.setProxy({
|
||||||
proxyRules,
|
proxyRules,
|
||||||
pacScript: '',
|
pacScript: '',
|
||||||
|
@ -136,9 +138,11 @@ export function createMainWindow(
|
||||||
path.join(__dirname, '..', 'nativefier.json'),
|
path.join(__dirname, '..', 'nativefier.json'),
|
||||||
JSON.stringify(options),
|
JSON.stringify(options),
|
||||||
);
|
);
|
||||||
} catch (exception) {
|
} catch (err) {
|
||||||
// eslint-disable-next-line no-console
|
// 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;
|
return undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
const adjustWindowZoom = (window: BrowserWindow, adjustment): void => {
|
const adjustWindowZoom = (
|
||||||
|
window: BrowserWindow,
|
||||||
|
adjustment: number,
|
||||||
|
): void => {
|
||||||
window.webContents.zoomFactor = window.webContents.zoomFactor + adjustment;
|
window.webContents.zoomFactor = window.webContents.zoomFactor + adjustment;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -206,7 +213,7 @@ export function createMainWindow(
|
||||||
const onWillNavigate = (event: Event, urlToGo: string): void => {
|
const onWillNavigate = (event: Event, urlToGo: string): void => {
|
||||||
if (!linkIsInternal(options.targetUrl, urlToGo, options.internalUrls)) {
|
if (!linkIsInternal(options.targetUrl, urlToGo, options.internalUrls)) {
|
||||||
event.preventDefault();
|
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);
|
sendParamsOnDidFinishLoad(window);
|
||||||
window.webContents.on('new-window', onNewWindow);
|
window.webContents.on('new-window', onNewWindow);
|
||||||
window.webContents.on('will-navigate', onWillNavigate);
|
window.webContents.on('will-navigate', onWillNavigate);
|
||||||
window.loadURL(url);
|
window.loadURL(url); // eslint-disable-line @typescript-eslint/no-floating-promises
|
||||||
return window;
|
return window;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -283,6 +290,7 @@ export function createMainWindow(
|
||||||
// In children windows too: Restore pinch-to-zoom, disabled by default in recent Electron.
|
// In children windows too: Restore pinch-to-zoom, disabled by default in recent Electron.
|
||||||
// See https://github.com/jiahaog/nativefier/issues/379#issuecomment-598612128
|
// See https://github.com/jiahaog/nativefier/issues/379#issuecomment-598612128
|
||||||
// and https://github.com/electron/electron/pull/12679
|
// and https://github.com/electron/electron/pull/12679
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||||
window.webContents.setVisualZoomLevelLimits(1, 3);
|
window.webContents.setVisualZoomLevelLimits(1, 3);
|
||||||
|
|
||||||
window.webContents.send('params', JSON.stringify(options));
|
window.webContents.send('params', JSON.stringify(options));
|
||||||
|
@ -353,6 +361,7 @@ export function createMainWindow(
|
||||||
// Restore pinch-to-zoom, disabled by default in recent Electron.
|
// Restore pinch-to-zoom, disabled by default in recent Electron.
|
||||||
// See https://github.com/jiahaog/nativefier/issues/379#issuecomment-598309817
|
// See https://github.com/jiahaog/nativefier/issues/379#issuecomment-598309817
|
||||||
// and https://github.com/electron/electron/pull/12679
|
// and https://github.com/electron/electron/pull/12679
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||||
mainWindow.webContents.setVisualZoomLevelLimits(1, 3);
|
mainWindow.webContents.setVisualZoomLevelLimits(1, 3);
|
||||||
|
|
||||||
// Remove potential css injection code set in `did-navigate`) (see injectCss code)
|
// Remove potential css injection code set in `did-navigate`) (see injectCss code)
|
||||||
|
@ -360,9 +369,11 @@ export function createMainWindow(
|
||||||
});
|
});
|
||||||
|
|
||||||
if (options.clearCache) {
|
if (options.clearCache) {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||||
clearCache(mainWindow);
|
clearCache(mainWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||||
mainWindow.loadURL(options.targetUrl);
|
mainWindow.loadURL(options.targetUrl);
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
@ -382,6 +393,7 @@ export function createMainWindow(
|
||||||
hideWindow(mainWindow, event, options.fastQuit, options.tray);
|
hideWindow(mainWindow, event, options.fastQuit, options.tray);
|
||||||
|
|
||||||
if (options.clearCache) {
|
if (options.clearCache) {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||||
clearCache(mainWindow);
|
clearCache(mainWindow);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -220,12 +220,14 @@ export function createMenu({
|
||||||
{
|
{
|
||||||
label: `Built with Nativefier v${nativefierVersion}`,
|
label: `Built with Nativefier v${nativefierVersion}`,
|
||||||
click: () => {
|
click: () => {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||||
shell.openExternal('https://github.com/jiahaog/nativefier');
|
shell.openExternal('https://github.com/jiahaog/nativefier');
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Report an Issue',
|
label: 'Report an Issue',
|
||||||
click: () => {
|
click: () => {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||||
shell.openExternal('https://github.com/jiahaog/nativefier/issues');
|
shell.openExternal('https://github.com/jiahaog/nativefier/issues');
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -75,9 +75,9 @@
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "26.x",
|
"@types/jest": "26.x",
|
||||||
"@typescript-eslint/eslint-plugin": "2.x",
|
"@typescript-eslint/eslint-plugin": "3.x",
|
||||||
"@typescript-eslint/parser": "2.x",
|
"@typescript-eslint/parser": "3.x",
|
||||||
"eslint": "6.x",
|
"eslint": "7.x",
|
||||||
"eslint-config-prettier": "6.x",
|
"eslint-config-prettier": "6.x",
|
||||||
"eslint-plugin-prettier": "3.x",
|
"eslint-plugin-prettier": "3.x",
|
||||||
"jest": "26.x",
|
"jest": "26.x",
|
||||||
|
|
|
@ -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> {
|
export async function buildNativefierApp(rawOptions: any): Promise<string> {
|
||||||
log.info('Processing options...');
|
log.info('Processing options...');
|
||||||
const options = await getOptions(rawOptions);
|
const options = await getOptions(rawOptions);
|
||||||
|
|
|
@ -134,7 +134,7 @@ export async function prepareElectronApp(
|
||||||
try {
|
try {
|
||||||
await copyFileOrDir(src, dest);
|
await copyFileOrDir(src, dest);
|
||||||
} catch (err) {
|
} 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');
|
const appJsonPath = path.join(dest, '/nativefier.json');
|
||||||
|
|
|
@ -39,7 +39,7 @@ function mapIconWithMatchScore(cloudIcons: any[], targetUrl: string): any {
|
||||||
const normalisedTargetUrl = targetUrl.toLowerCase();
|
const normalisedTargetUrl = targetUrl.toLowerCase();
|
||||||
return cloudIcons.map((item) => {
|
return cloudIcons.map((item) => {
|
||||||
const itemWords = item.name.split(GITCLOUD_SPACE_DELIMITER);
|
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)) {
|
if (normalisedTargetUrl.includes(word)) {
|
||||||
return currentScore + 1;
|
return currentScore + 1;
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ async function inferIconFromStore(
|
||||||
log.debug(`Inferring icon from store for ${targetUrl} on ${platform}`);
|
log.debug(`Inferring icon from store for ${targetUrl} on ${platform}`);
|
||||||
const allowedFormats = new Set(getAllowedIconFormats(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`);
|
log.debug(`Got ${cloudIcons.length} icons from gitcloud`);
|
||||||
const iconWithScores = mapIconWithMatchScore(cloudIcons, targetUrl);
|
const iconWithScores = mapIconWithMatchScore(cloudIcons, targetUrl);
|
||||||
const maxScore = getMaxMatchScore(iconWithScores);
|
const maxScore = getMaxMatchScore(iconWithScores);
|
||||||
|
|
|
@ -9,7 +9,7 @@ export { buildNativefierApp };
|
||||||
* Use the better, modern async `buildNativefierApp` instead if you can!
|
* Use the better, modern async `buildNativefierApp` instead if you can!
|
||||||
*/
|
*/
|
||||||
function buildNativefierAppOldCallbackStyle(
|
function buildNativefierAppOldCallbackStyle(
|
||||||
options: any,
|
options: any, // eslint-disable-line @typescript-eslint/explicit-module-boundary-types
|
||||||
callback: (err: any, result?: any) => void,
|
callback: (err: any, result?: any) => void,
|
||||||
): void {
|
): void {
|
||||||
buildNativefierApp(options)
|
buildNativefierApp(options)
|
||||||
|
|
|
@ -24,7 +24,9 @@ const NAME_PARAMS_NEEDS_INFER = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
beforeAll(() => {
|
beforeAll(() => {
|
||||||
(sanitizeFilename as jest.Mock).mockImplementation((_, filename) => filename);
|
(sanitizeFilename as jest.Mock).mockImplementation(
|
||||||
|
(_, filename: string) => filename,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('well formed name parameters', () => {
|
describe('well formed name parameters', () => {
|
||||||
|
|
|
@ -17,9 +17,9 @@ async function tryToInferName(targetUrl: string): Promise<string> {
|
||||||
log.debug('Inferring name for', targetUrl);
|
log.debug('Inferring name for', targetUrl);
|
||||||
const pageTitle = await inferTitle(targetUrl);
|
const pageTitle = await inferTitle(targetUrl);
|
||||||
return pageTitle || DEFAULT_APP_NAME;
|
return pageTitle || DEFAULT_APP_NAME;
|
||||||
} catch (error) {
|
} catch (err) {
|
||||||
log.warn(
|
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;
|
return DEFAULT_APP_NAME;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ const SEMVER_VERSION_NUMBER_REGEX = /\d+\.\d+\.\d+[-_\w\d.]*/;
|
||||||
/**
|
/**
|
||||||
* Process and validate raw user arguments
|
* Process and validate raw user arguments
|
||||||
*/
|
*/
|
||||||
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||||
export async function getOptions(rawOptions: any): Promise<AppOptions> {
|
export async function getOptions(rawOptions: any): Promise<AppOptions> {
|
||||||
const options: AppOptions = {
|
const options: AppOptions = {
|
||||||
packager: {
|
packager: {
|
||||||
|
@ -96,6 +97,7 @@ export async function getOptions(rawOptions: any): Promise<AppOptions> {
|
||||||
if (options.nativefier.verbose) {
|
if (options.nativefier.verbose) {
|
||||||
log.setLevel('trace');
|
log.setLevel('trace');
|
||||||
try {
|
try {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||||
require('debug').enable('electron-packager');
|
require('debug').enable('electron-packager');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log.debug(
|
log.debug(
|
||||||
|
|
|
@ -9,7 +9,7 @@ export function sanitizeFilename(
|
||||||
platform: string,
|
platform: string,
|
||||||
filenameToSanitize: string,
|
filenameToSanitize: string,
|
||||||
): string {
|
): string {
|
||||||
let result = sanitize(filenameToSanitize);
|
let result: string = sanitize(filenameToSanitize);
|
||||||
|
|
||||||
// remove all non ascii or use default app name
|
// remove all non ascii or use default app name
|
||||||
// eslint-disable-next-line no-control-regex
|
// eslint-disable-next-line no-control-regex
|
||||||
|
|
Loading…
Reference in New Issue