chore(lint): update eslint config and apply fixes (#1032)

This commit is contained in:
Niklas Merz 2023-11-06 22:14:27 +01:00 committed by GitHub
parent 4b3c0f126d
commit 51959ec268
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 2141 additions and 1983 deletions

3958
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -50,6 +50,6 @@
"author": "Apache Software Foundation",
"license": "Apache-2.0",
"devDependencies": {
"@cordova/eslint-config": "^3.0.0"
"@cordova/eslint-config": "^5.0.0"
}
}

View File

@ -19,35 +19,35 @@
*
*/
var modulemapper = require('cordova/modulemapper');
const modulemapper = require('cordova/modulemapper');
var browserWrap, popup, navigationButtonsDiv, navigationButtonsDivInner, backButton, forwardButton, closeButton;
let browserWrap, popup, navigationButtonsDiv, navigationButtonsDivInner, backButton, forwardButton, closeButton;
function attachNavigationEvents (element, callback) {
var onError = function () {
const onError = function () {
try {
callback({ type: 'loaderror', url: this.contentWindow.location.href }, { keepCallback: true }); // eslint-disable-line standard/no-callback-literal
callback({ type: 'loaderror', url: this.contentWindow.location.href }, { keepCallback: true }); // eslint-disable-line n/no-callback-literal
} catch (err) {
// blocked by CORS :\
callback({ type: 'loaderror', url: null }, { keepCallback: true }); // eslint-disable-line standard/no-callback-literal
callback({ type: 'loaderror', url: null }, { keepCallback: true }); // eslint-disable-line n/no-callback-literal
}
};
element.addEventListener('pageshow', function () {
try {
callback({ type: 'loadstart', url: this.contentWindow.location.href }, { keepCallback: true }); // eslint-disable-line standard/no-callback-literal
callback({ type: 'loadstart', url: this.contentWindow.location.href }, { keepCallback: true }); // eslint-disable-line n/no-callback-literal
} catch (err) {
// blocked by CORS :\
callback({ type: 'loadstart', url: null }, { keepCallback: true }); // eslint-disable-line standard/no-callback-literal
callback({ type: 'loadstart', url: null }, { keepCallback: true }); // eslint-disable-line n/no-callback-literal
}
});
element.addEventListener('load', function () {
try {
callback({ type: 'loadstop', url: this.contentWindow.location.href }, { keepCallback: true }); // eslint-disable-line standard/no-callback-literal
callback({ type: 'loadstop', url: this.contentWindow.location.href }, { keepCallback: true }); // eslint-disable-line n/no-callback-literal
} catch (err) {
// blocked by CORS :\
callback({ type: 'loadstop', url: null }, { keepCallback: true }); // eslint-disable-line standard/no-callback-literal
callback({ type: 'loadstop', url: null }, { keepCallback: true }); // eslint-disable-line n/no-callback-literal
}
});
@ -55,7 +55,7 @@ function attachNavigationEvents (element, callback) {
element.addEventListener('abort', onError);
}
var IAB = {
const IAB = {
close: function (win, lose) {
if (browserWrap) {
// use the "open" function callback so that the exit event is fired properly
@ -74,9 +74,9 @@ var IAB = {
},
open: function (win, lose, args) {
var strUrl = args[0];
var target = args[1];
var features = args[2];
const strUrl = args[0];
const target = args[1];
const features = args[2];
IAB._win = win;
@ -200,8 +200,8 @@ var IAB = {
},
injectScriptCode: function (win, fail, args) {
var code = args[0];
var hasCallback = args[1];
const code = args[0];
const hasCallback = args[1];
if (browserWrap && popup) {
try {
@ -216,7 +216,7 @@ var IAB = {
},
injectScriptFile: function (win, fail, args) {
var msg = 'Browser cordova-plugin-inappbrowser injectScriptFile is not yet implemented';
const msg = 'Browser cordova-plugin-inappbrowser injectScriptFile is not yet implemented';
console.warn(msg);
if (fail) {
fail(msg);
@ -224,7 +224,7 @@ var IAB = {
},
injectStyleCode: function (win, fail, args) {
var msg = 'Browser cordova-plugin-inappbrowser injectStyleCode is not yet implemented';
const msg = 'Browser cordova-plugin-inappbrowser injectStyleCode is not yet implemented';
console.warn(msg);
if (fail) {
fail(msg);
@ -232,7 +232,7 @@ var IAB = {
},
injectStyleFile: function (win, fail, args) {
var msg = 'Browser cordova-plugin-inappbrowser injectStyleFile is not yet implemented';
const msg = 'Browser cordova-plugin-inappbrowser injectStyleFile is not yet implemented';
console.warn(msg);
if (fail) {
fail(msg);

View File

@ -17,5 +17,5 @@
* under the License.
*/
var d = document.getElementById('header');
const d = document.getElementById('header');
d.innerHTML = 'Script file successfully injected';

View File

@ -19,15 +19,15 @@
*
*/
var cordova = require('cordova');
var isIos = cordova.platformId === 'ios';
var isAndroid = cordova.platformId === 'android';
var isBrowser = cordova.platformId === 'browser';
const cordova = require('cordova');
const isIos = cordova.platformId === 'ios';
const isAndroid = cordova.platformId === 'android';
const isBrowser = cordova.platformId === 'browser';
window.alert = window.alert || navigator.notification.alert;
exports.defineAutoTests = function () {
var createTests = function (platformOpts) {
const createTests = function (platformOpts) {
platformOpts = platformOpts || '';
describe('cordova.InAppBrowser', function () {
@ -47,10 +47,10 @@ exports.defineAutoTests = function () {
return;
}
var iabInstance;
var originalTimeout;
var url = 'https://dist.apache.org/repos/dist/dev/cordova/';
var badUrl = 'http://bad-uri/';
let iabInstance;
let originalTimeout;
const url = 'https://dist.apache.org/repos/dist/dev/cordova/';
const badUrl = 'http://bad-uri/';
beforeEach(function () {
// increase timeout to ensure test url could be loaded within test time
@ -104,7 +104,7 @@ exports.defineAutoTests = function () {
});
it('inappbrowser.spec.4 should support loadstart and loadstop events', function (done) {
var onLoadStart = jasmine.createSpy('loadstart event callback').and.callFake(function (evt) {
const onLoadStart = jasmine.createSpy('loadstart event callback').and.callFake(function (evt) {
verifyEvent(evt, 'loadstart');
});
@ -150,8 +150,8 @@ exports.defineAutoTests = function () {
if (!isAndroid && !isIos) {
return pending(cordova.platformId + " platform doesn't support message event");
}
var messageKey = 'my_message';
var messageValue = 'is_this';
const messageKey = 'my_message';
const messageValue = 'is_this';
iabInstance = cordova.InAppBrowser.open(url, '_blank', platformOpts);
iabInstance.addEventListener('message', function (evt) {
// Verify message event
@ -163,7 +163,7 @@ exports.defineAutoTests = function () {
done();
});
iabInstance.addEventListener('loadstop', function (evt) {
var code =
const code =
'(function(){\n' +
' var message = {' +
messageKey +
@ -172,7 +172,7 @@ exports.defineAutoTests = function () {
'"};\n' +
' webkit.messageHandlers.cordova_iab.postMessage(JSON.stringify(message));\n' +
'})()';
iabInstance.executeScript({ code: code });
iabInstance.executeScript({ code });
});
});
});
@ -181,17 +181,17 @@ exports.defineAutoTests = function () {
};
exports.defineManualTests = function (contentEl, createActionButton) {
var platformOpts = '';
var platform_info = '';
const platformOpts = '';
const platform_info = '';
function doOpen (url, target, params, numExpectedRedirects, useWindowOpen) {
numExpectedRedirects = numExpectedRedirects || 0;
useWindowOpen = useWindowOpen || false;
console.log('Opening ' + url);
var counts;
var lastLoadStartURL;
var wasReset = false;
let counts;
let lastLoadStartURL;
let wasReset = false;
function reset () {
counts = {
loaderror: 0,
@ -203,8 +203,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
}
reset();
var iab;
var callbacks = {
let iab;
const callbacks = {
loaderror: logEvent,
loadstart: logEvent,
loadstop: logEvent,
@ -258,7 +258,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
}
// Verify that loadend / loaderror was called.
if (e.type === 'exit') {
var numStopEvents = counts.loadstop + counts.loaderror;
const numStopEvents = counts.loadstop + counts.loaderror;
if (numStopEvents === 0 && !wasReset) {
alert('Unexpected: browser closed without a loadstop or loaderror.'); // eslint-disable-line no-undef
} else if (numStopEvents > 1) {
@ -271,8 +271,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
}
function doHookOpen (url, target, params, numExpectedRedirects) {
var originalFunc = window.open;
var wasClobbered = Object.prototype.hasOwnProperty.call(window, 'open');
const originalFunc = window.open;
const wasClobbered = Object.prototype.hasOwnProperty.call(window, 'open');
window.open = cordova.InAppBrowser.open;
try {
@ -288,8 +288,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
}
function openWithStyle (url, cssUrl, useCallback) {
var iab = doOpen(url, '_blank', 'location=yes');
var callback = function (results) {
const iab = doOpen(url, '_blank', 'location=yes');
const callback = function (results) {
if (results && results.length === 0) {
alert('Results verified'); // eslint-disable-line no-undef
} else {
@ -309,7 +309,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
}
function openWithScript (url, jsUrl, useCallback) {
var iab = doOpen(url, '_blank', 'location=yes');
const iab = doOpen(url, '_blank', 'location=yes');
if (jsUrl) {
iab.addEventListener('loadstop', function (event) {
iab.executeScript(
@ -327,14 +327,14 @@ exports.defineManualTests = function (contentEl, createActionButton) {
});
} else {
iab.addEventListener('loadstop', function (event) {
var code =
const code =
'(function(){\n' +
' var header = document.getElementById("header");\n' +
' header.innerHTML = "Script literal successfully injected";\n' +
' return "abc";\n' +
'})()';
iab.executeScript(
{ code: code },
{ code },
useCallback &&
function (results) {
if (results && results.length === 1 && results[0] === 'abc') {
@ -348,12 +348,12 @@ exports.defineManualTests = function (contentEl, createActionButton) {
});
}
}
var hiddenwnd = null;
var loadlistener = function (event) {
let hiddenwnd = null;
const loadlistener = function (event) {
alert('background window loaded ');
}; // eslint-disable-line no-undef
function openHidden (url, startHidden) {
var shopt = startHidden ? 'hidden=yes' : '';
let shopt = startHidden ? 'hidden=yes' : '';
if (platformOpts) {
shopt += (shopt ? ',' : '') + platformOpts;
}
@ -377,7 +377,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
}
}
var info_div =
const info_div =
'<h1>InAppBrowser</h1>' +
'<div id="info">' +
'Make sure http://cordova.apache.org and http://google.co.uk and https://www.google.co.uk are white listed. </br>' +
@ -386,7 +386,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
'<h4>User-Agent: <span id="user-agent"> </span></hr>' +
'</div>';
var local_tests =
const local_tests =
'<h1>Local URL</h1>' +
'<div id="openLocal"></div>' +
'Expected result: opens successfully in CordovaWebView.' +
@ -407,7 +407,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
'<p/><div id="openLocalRandomToolBarTopNoLocation"></div>' +
'Expected result: open successfully in InAppBrowser with no locationBar. On iOS the toolbar is at the top.';
var white_listed_tests =
const white_listed_tests =
'<h1>White Listed URL</h1>' +
'<div id="openWhiteListed"></div>' +
'Expected result: open successfully in CordovaWebView to cordova.apache.org' +
@ -424,7 +424,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
'<p/> <div id="openWhiteListedRandomNoLocation"></div>' +
'Expected result: open successfully in InAppBrowser to cordova.apache.org with no location bar.';
var non_white_listed_tests =
const non_white_listed_tests =
'<h1>Non White Listed URL</h1>' +
'<div id="openNonWhiteListed"></div>' +
'Expected result: open successfully in InAppBrowser to apple.com.' +
@ -441,21 +441,21 @@ exports.defineManualTests = function (contentEl, createActionButton) {
'<p/> <div id="openNonWhiteListedRandomNoLocation"></div>' +
'Expected result: open successfully in InAppBrowser to apple.com without locationBar.';
var page_with_redirects_tests =
const page_with_redirects_tests =
'<h1>Page with redirect</h1>' +
'<div id="openRedirect301"></div>' +
'Expected result: should 301 and open successfully in InAppBrowser to https://www.google.co.uk.' +
'<p/> <div id="openRedirect302"></div>' +
'Expected result: should 302 and open successfully in InAppBrowser to www.zhihu.com/answer/16714076.';
var pdf_url_tests =
const pdf_url_tests =
'<h1>PDF URL</h1>' +
'<div id="openPDF"></div>' +
'Expected result: InAppBrowser opens. PDF should render on iOS.' +
'<p/> <div id="openPDFBlank"></div>' +
'Expected result: InAppBrowser opens. PDF should render on iOS.';
var invalid_url_tests =
const invalid_url_tests =
'<h1>Invalid URL</h1>' +
'<div id="openInvalidScheme"></div>' +
'Expected result: fail to load in InAppBrowser.' +
@ -464,7 +464,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
'<p/> <div id="openInvalidMissing"></div>' +
'Expected result: fail to load in InAppBrowser (404).';
var css_js_injection_tests =
const css_js_injection_tests =
'<h1>CSS / JS Injection</h1>' +
'<div id="openOriginalDocument"></div>' +
'Expected result: open successfully in InAppBrowser without text "Style updated from..."' +
@ -485,7 +485,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
'<p/> <div id="openScriptLiteralInjectionCallback"></div>' +
'Expected result: open successfully in InAppBrowser with the text "Script literal successfully injected" and alert dialog with the text "Results verified".';
var open_hidden_tests =
const open_hidden_tests =
'<h1>Open Hidden </h1>' +
'<div id="openHidden"></div>' +
'Expected result: no additional browser window. Alert appears with the text "background window loaded".' +
@ -498,14 +498,14 @@ exports.defineManualTests = function (contentEl, createActionButton) {
'<p/> <div id="openVisibleAndHide"></div>' +
'Expected result: open successfully in InAppBrowser to https://www.google.co.uk. Hide after 2 seconds';
var clearing_cache_tests =
const clearing_cache_tests =
'<h1>Clearing Cache</h1>' +
'<div id="openClearCache"></div>' +
'Expected result: ?' +
'<p/> <div id="openClearSessionCache"></div>' +
'Expected result: ?';
var video_tag_tests =
const video_tag_tests =
'<h1>Video tag</h1>' +
'<div id="openRemoteVideo"></div>' +
'Expected result: open successfully in InAppBrowser with an embedded video plays automatically on iOS and Android.' +
@ -514,14 +514,14 @@ exports.defineManualTests = function (contentEl, createActionButton) {
'<div id="openRemoteNeedUserYesVideo"></div>' +
'Expected result: open successfully in InAppBrowser with an embedded video does not play automatically on iOS and Android but rather works after clicking the "play" button.';
var local_with_anchor_tag_tests =
const local_with_anchor_tag_tests =
'<h1>Local with anchor tag</h1>' +
'<div id="openAnchor1"></div>' +
'Expected result: open successfully in InAppBrowser to the local page, scrolled to the top as normal.' +
'<p/> <div id="openAnchor2"></div>' +
'Expected result: open successfully in InAppBrowser to the local page, scrolled to the beginning of the tall div with border.';
var hardwareback_tests =
const hardwareback_tests =
'<h1>HardwareBack</h1>' +
'<p/> <div id="openHardwareBackDefault"></div>' +
'Expected result: By default hardwareback is yes so pressing back button should navigate backwards in history then close InAppBrowser' +
@ -551,13 +551,13 @@ exports.defineManualTests = function (contentEl, createActionButton) {
document.getElementById('user-agent').textContent = navigator.userAgent;
// we are already in cdvtests directory
var basePath = 'iab-resources/';
var localhtml = basePath + 'local.html';
var localpdf = basePath + 'local.pdf';
var injecthtml = basePath + 'inject.html';
var injectjs = 'inject.js';
var injectcss = 'inject.css';
var videohtml = basePath + 'video.html';
const basePath = 'iab-resources/';
const localhtml = basePath + 'local.html';
const localpdf = basePath + 'local.pdf';
const injecthtml = basePath + 'inject.html';
const injectjs = 'inject.js';
const injectcss = 'inject.css';
const videohtml = basePath + 'video.html';
// Local
createActionButton(
@ -878,7 +878,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
createActionButton(
'google.co.uk shown for 2 seconds than hidden',
function () {
var iab = doOpen('https://www.google.co.uk/', 'random_sting');
const iab = doOpen('https://www.google.co.uk/', 'random_sting');
setTimeout(function () {
iab.hide();
}, 2000);
@ -966,12 +966,12 @@ exports.defineManualTests = function (contentEl, createActionButton) {
createActionButton(
'no hardwareback -> hardwareback=no -> no hardwareback',
function () {
var ref = cordova.InAppBrowser.open('https://google.com', '_blank', 'location=yes' + (platformOpts ? ',' + platformOpts : ''));
const ref = cordova.InAppBrowser.open('https://google.com', '_blank', 'location=yes' + (platformOpts ? ',' + platformOpts : ''));
ref.addEventListener('loadstop', function () {
ref.close();
});
ref.addEventListener('exit', function () {
var ref2 = cordova.InAppBrowser.open(
const ref2 = cordova.InAppBrowser.open(
'https://google.com',
'_blank',
'location=yes,hardwareback=no' + (platformOpts ? ',' + platformOpts : '')

View File

@ -20,10 +20,10 @@
*/
(function () {
var exec = require('cordova/exec');
var channel = require('cordova/channel');
var modulemapper = require('cordova/modulemapper');
var urlutil = require('cordova/urlutil');
const exec = require('cordova/exec');
const channel = require('cordova/channel');
const modulemapper = require('cordova/modulemapper');
const urlutil = require('cordova/urlutil');
function InAppBrowser () {
this.channels = {
@ -100,19 +100,19 @@
module.exports = function (strUrl, strWindowName, strWindowFeatures, callbacks) {
// Don't catch calls that write to existing frames (e.g. named iframes).
if (window.frames && window.frames[strWindowName]) {
var origOpenFunc = modulemapper.getOriginalSymbol(window, 'open');
const origOpenFunc = modulemapper.getOriginalSymbol(window, 'open');
return origOpenFunc.apply(window, arguments);
}
strUrl = urlutil.makeAbsolute(strUrl);
var iab = new InAppBrowser();
const iab = new InAppBrowser();
callbacks = callbacks || {};
for (var callbackName in callbacks) {
for (const callbackName in callbacks) {
iab.addEventListener(callbackName, callbacks[callbackName]);
}
var cb = function (eventname) {
const cb = function (eventname) {
iab._eventHandler(eventname);
};