forked from github/cordova-android
Ensure to lint as many files as possible (#854)
* Lint everything, including bins w/out extension * Apply eslint --fix to all linted files * Manually fix all remaining lint rule violations * Remove ESLint inline config
This commit is contained in:
parent
c35a990c09
commit
5dfa995a4b
@ -16,8 +16,6 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
/* eslint no-self-assign: 0 */
|
||||
/* eslint no-unused-vars: 0 */
|
||||
|
||||
var Q = require('q');
|
||||
var fs = require('fs');
|
||||
@ -356,7 +354,7 @@ function findOutputApksHelper (dir, build_type, arch) {
|
||||
return true;
|
||||
}).sort(apkSorter);
|
||||
|
||||
shellSilent = shellSilent;
|
||||
shell.config.silent = shellSilent;
|
||||
|
||||
if (ret.length === 0) {
|
||||
return ret;
|
||||
@ -381,10 +379,6 @@ function findOutputApksHelper (dir, build_type, arch) {
|
||||
// While replacing shell with fs-extra, it might be a good idea to see if we can
|
||||
// generalise these findOutput methods.
|
||||
function findOutputBundlesHelper (dir, build_type) {
|
||||
// This is an unused variable that was copied from findOutputApksHelper
|
||||
// we are pretty sure it was meant to reset shell.config.silent back to
|
||||
// the original value. However shell is planned to be replaced,
|
||||
// it was left as is to avoid unintended consequences.
|
||||
const shellSilent = shell.config.silent;
|
||||
shell.config.silent = true;
|
||||
|
||||
@ -404,6 +398,8 @@ function findOutputBundlesHelper (dir, build_type) {
|
||||
return true;
|
||||
});
|
||||
|
||||
shell.config.silent = shellSilent;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
7
bin/templates/cordova/lib/prepare.js
vendored
7
bin/templates/cordova/lib/prepare.js
vendored
@ -16,7 +16,6 @@
|
||||
specific language governing permissions and limitations
|
||||
under the License.
|
||||
*/
|
||||
/* eslint no-useless-escape: 0 */
|
||||
|
||||
var Q = require('q');
|
||||
var fs = require('fs');
|
||||
@ -186,11 +185,11 @@ function updateProjectAccordingTo (platformConfig, locations) {
|
||||
var strings = xmlHelpers.parseElementtreeSync(locations.strings);
|
||||
|
||||
var name = platformConfig.name();
|
||||
strings.find('string[@name="app_name"]').text = name.replace(/\'/g, '\\\'');
|
||||
strings.find('string[@name="app_name"]').text = name.replace(/'/g, '\\\'');
|
||||
|
||||
var shortName = platformConfig.shortName && platformConfig.shortName();
|
||||
if (shortName && shortName !== name) {
|
||||
strings.find('string[@name="launcher_name"]').text = shortName.replace(/\'/g, '\\\'');
|
||||
strings.find('string[@name="launcher_name"]').text = shortName.replace(/'/g, '\\\'');
|
||||
}
|
||||
|
||||
fs.writeFileSync(locations.strings, strings.write({ indent: 4 }), 'utf-8');
|
||||
@ -225,7 +224,7 @@ function updateProjectAccordingTo (platformConfig, locations) {
|
||||
|
||||
var destFile = path.join(locations.root, 'app', 'src', 'main', 'java', androidPkgName.replace(/\./g, '/'), path.basename(java_files[0]));
|
||||
shell.mkdir('-p', path.dirname(destFile));
|
||||
shell.sed(/package [\w\.]*;/, 'package ' + androidPkgName + ';', java_files[0]).to(destFile);
|
||||
shell.sed(/package [\w.]*;/, 'package ' + androidPkgName + ';', java_files[0]).to(destFile);
|
||||
events.emit('verbose', 'Wrote out Android package name "' + androidPkgName + '" to ' + destFile);
|
||||
|
||||
var removeOrigPkg = checkReqs.isWindows() || checkReqs.isDarwin() ?
|
||||
|
@ -20,7 +20,7 @@
|
||||
*/
|
||||
|
||||
// Coho updates this line:
|
||||
var VERSION = "8.2.0-dev";
|
||||
var VERSION = '8.2.0-dev';
|
||||
|
||||
module.exports.version = VERSION;
|
||||
|
||||
|
4
cordova-js-src/.eslintrc.yml
Normal file
4
cordova-js-src/.eslintrc.yml
Normal file
@ -0,0 +1,4 @@
|
||||
env:
|
||||
node: false
|
||||
commonjs: true
|
||||
browser: true
|
79
cordova-js-src/exec.js
vendored
79
cordova-js-src/exec.js
vendored
@ -33,16 +33,16 @@
|
||||
* @param {String} action Action to be run in cordova
|
||||
* @param {String[]} [args] Zero or more arguments to pass to the method
|
||||
*/
|
||||
var cordova = require('cordova'),
|
||||
nativeApiProvider = require('cordova/android/nativeapiprovider'),
|
||||
utils = require('cordova/utils'),
|
||||
base64 = require('cordova/base64'),
|
||||
channel = require('cordova/channel'),
|
||||
jsToNativeModes = {
|
||||
var cordova = require('cordova');
|
||||
var nativeApiProvider = require('cordova/android/nativeapiprovider');
|
||||
var utils = require('cordova/utils');
|
||||
var base64 = require('cordova/base64');
|
||||
var channel = require('cordova/channel');
|
||||
var jsToNativeModes = {
|
||||
PROMPT: 0,
|
||||
JS_OBJECT: 1
|
||||
},
|
||||
nativeToJsModes = {
|
||||
};
|
||||
var nativeToJsModes = {
|
||||
// Polls for messages using the JS->Native bridge.
|
||||
POLLING: 0,
|
||||
// For LOAD_URL to be viable, it would need to have a work-around for
|
||||
@ -53,15 +53,15 @@ var cordova = require('cordova'),
|
||||
// as set the navigator property itself.
|
||||
ONLINE_EVENT: 2,
|
||||
EVAL_BRIDGE: 3
|
||||
},
|
||||
jsToNativeBridgeMode, // Set lazily.
|
||||
nativeToJsBridgeMode = nativeToJsModes.EVAL_BRIDGE,
|
||||
pollEnabled = false,
|
||||
bridgeSecret = -1;
|
||||
};
|
||||
var jsToNativeBridgeMode; // Set lazily.
|
||||
var nativeToJsBridgeMode = nativeToJsModes.EVAL_BRIDGE;
|
||||
var pollEnabled = false;
|
||||
var bridgeSecret = -1;
|
||||
|
||||
var messagesFromNative = [];
|
||||
var isProcessing = false;
|
||||
var resolvedPromise = typeof Promise == 'undefined' ? null : Promise.resolve();
|
||||
var resolvedPromise = typeof Promise === 'undefined' ? null : Promise.resolve();
|
||||
var nextTick = resolvedPromise ? function (fn) { resolvedPromise.then(fn); } : function (fn) { setTimeout(fn); };
|
||||
|
||||
function androidExec (success, fail, service, action, args) {
|
||||
@ -83,13 +83,13 @@ function androidExec(success, fail, service, action, args) {
|
||||
|
||||
// Process any ArrayBuffers in the args into a string.
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
if (utils.typeName(args[i]) == 'ArrayBuffer') {
|
||||
if (utils.typeName(args[i]) === 'ArrayBuffer') {
|
||||
args[i] = base64.fromArrayBuffer(args[i]);
|
||||
}
|
||||
}
|
||||
|
||||
var callbackId = service + cordova.callbackId++,
|
||||
argsJson = JSON.stringify(args);
|
||||
var callbackId = service + cordova.callbackId++;
|
||||
var argsJson = JSON.stringify(args);
|
||||
if (success || fail) {
|
||||
cordova.callbacks[callbackId] = { success: success, fail: fail };
|
||||
}
|
||||
@ -97,7 +97,7 @@ function androidExec(success, fail, service, action, args) {
|
||||
var msgs = nativeApiProvider.get().exec(bridgeSecret, service, action, callbackId, argsJson);
|
||||
// If argsJson was received by Java as null, try again with the PROMPT bridge mode.
|
||||
// This happens in rare circumstances, such as when certain Unicode characters are passed over the bridge on a Galaxy S2. See CB-2666.
|
||||
if (jsToNativeBridgeMode == jsToNativeModes.JS_OBJECT && msgs === "@Null arguments.") {
|
||||
if (jsToNativeBridgeMode === jsToNativeModes.JS_OBJECT && msgs === '@Null arguments.') {
|
||||
androidExec.setJsToNativeBridgeMode(jsToNativeModes.PROMPT);
|
||||
androidExec(success, fail, service, action, args);
|
||||
androidExec.setJsToNativeBridgeMode(jsToNativeModes.JS_OBJECT);
|
||||
@ -160,18 +160,18 @@ androidExec.jsToNativeModes = jsToNativeModes;
|
||||
androidExec.nativeToJsModes = nativeToJsModes;
|
||||
|
||||
androidExec.setJsToNativeBridgeMode = function (mode) {
|
||||
if (mode == jsToNativeModes.JS_OBJECT && !window._cordovaNative) {
|
||||
if (mode === jsToNativeModes.JS_OBJECT && !window._cordovaNative) {
|
||||
mode = jsToNativeModes.PROMPT;
|
||||
}
|
||||
nativeApiProvider.setPreferPrompt(mode == jsToNativeModes.PROMPT);
|
||||
nativeApiProvider.setPreferPrompt(mode === jsToNativeModes.PROMPT);
|
||||
jsToNativeBridgeMode = mode;
|
||||
};
|
||||
|
||||
androidExec.setNativeToJsBridgeMode = function (mode) {
|
||||
if (mode == nativeToJsBridgeMode) {
|
||||
if (mode === nativeToJsBridgeMode) {
|
||||
return;
|
||||
}
|
||||
if (nativeToJsBridgeMode == nativeToJsModes.POLLING) {
|
||||
if (nativeToJsBridgeMode === nativeToJsModes.POLLING) {
|
||||
pollEnabled = false;
|
||||
}
|
||||
|
||||
@ -182,7 +182,7 @@ androidExec.setNativeToJsBridgeMode = function(mode) {
|
||||
nativeApiProvider.get().setNativeToJsBridgeMode(bridgeSecret, mode);
|
||||
}
|
||||
|
||||
if (mode == nativeToJsModes.POLLING) {
|
||||
if (mode === nativeToJsModes.POLLING) {
|
||||
pollEnabled = true;
|
||||
setTimeout(pollingTimerFunc, 1);
|
||||
}
|
||||
@ -190,24 +190,24 @@ androidExec.setNativeToJsBridgeMode = function(mode) {
|
||||
|
||||
function buildPayload (payload, message) {
|
||||
var payloadKind = message.charAt(0);
|
||||
if (payloadKind == 's') {
|
||||
if (payloadKind === 's') {
|
||||
payload.push(message.slice(1));
|
||||
} else if (payloadKind == 't') {
|
||||
} else if (payloadKind === 't') {
|
||||
payload.push(true);
|
||||
} else if (payloadKind == 'f') {
|
||||
} else if (payloadKind === 'f') {
|
||||
payload.push(false);
|
||||
} else if (payloadKind == 'N') {
|
||||
} else if (payloadKind === 'N') {
|
||||
payload.push(null);
|
||||
} else if (payloadKind == 'n') {
|
||||
} else if (payloadKind === 'n') {
|
||||
payload.push(+message.slice(1));
|
||||
} else if (payloadKind == 'A') {
|
||||
} else if (payloadKind === 'A') {
|
||||
var data = message.slice(1);
|
||||
payload.push(base64.toArrayBuffer(data));
|
||||
} else if (payloadKind == 'S') {
|
||||
} else if (payloadKind === 'S') {
|
||||
payload.push(window.atob(message.slice(1)));
|
||||
} else if (payloadKind == 'M') {
|
||||
} else if (payloadKind === 'M') {
|
||||
var multipartMessages = message.slice(1);
|
||||
while (multipartMessages !== "") {
|
||||
while (multipartMessages !== '') {
|
||||
var spaceIdx = multipartMessages.indexOf(' ');
|
||||
var msgLen = +multipartMessages.slice(0, spaceIdx);
|
||||
var multipartMessage = multipartMessages.substr(spaceIdx + 1, msgLen);
|
||||
@ -222,12 +222,13 @@ function buildPayload(payload, message) {
|
||||
// Processes a single message, as encoded by NativeToJsMessageQueue.java.
|
||||
function processMessage (message) {
|
||||
var firstChar = message.charAt(0);
|
||||
if (firstChar == 'J') {
|
||||
if (firstChar === 'J') {
|
||||
// This is deprecated on the .java side. It doesn't work with CSP enabled.
|
||||
// eslint-disable-next-line no-eval
|
||||
eval(message.slice(1));
|
||||
} else if (firstChar == 'S' || firstChar == 'F') {
|
||||
var success = firstChar == 'S';
|
||||
var keepCallback = message.charAt(1) == '1';
|
||||
} else if (firstChar === 'S' || firstChar === 'F') {
|
||||
var success = firstChar === 'S';
|
||||
var keepCallback = message.charAt(1) === '1';
|
||||
var spaceIdx = message.indexOf(' ', 2);
|
||||
var status = +message.slice(2, spaceIdx);
|
||||
var nextSpaceIdx = message.indexOf(' ', spaceIdx + 1);
|
||||
@ -237,7 +238,7 @@ function processMessage(message) {
|
||||
buildPayload(payload, payloadMessage);
|
||||
cordova.callbackFromNative(callbackId, success, status, payload, keepCallback);
|
||||
} else {
|
||||
console.log("processMessage failed: invalid message: " + JSON.stringify(message));
|
||||
console.log('processMessage failed: invalid message: ' + JSON.stringify(message));
|
||||
}
|
||||
}
|
||||
|
||||
@ -254,7 +255,7 @@ function processMessages() {
|
||||
var msg = popMessageFromQueue();
|
||||
// The Java side can send a * message to indicate that it
|
||||
// still has messages waiting to be retrieved.
|
||||
if (msg == '*' && messagesFromNative.length === 0) {
|
||||
if (msg === '*' && messagesFromNative.length === 0) {
|
||||
nextTick(pollOnce);
|
||||
return;
|
||||
}
|
||||
@ -269,7 +270,7 @@ function processMessages() {
|
||||
|
||||
function popMessageFromQueue () {
|
||||
var messageBatch = messagesFromNative.shift();
|
||||
if (messageBatch == '*') {
|
||||
if (messageBatch === '*') {
|
||||
return '*';
|
||||
}
|
||||
|
||||
|
21
cordova-js-src/platform.js
vendored
21
cordova-js-src/platform.js
vendored
@ -25,10 +25,10 @@ var lastResumeEvent = null;
|
||||
module.exports = {
|
||||
id: 'android',
|
||||
bootstrap: function () {
|
||||
var channel = require('cordova/channel'),
|
||||
cordova = require('cordova'),
|
||||
exec = require('cordova/exec'),
|
||||
modulemapper = require('cordova/modulemapper');
|
||||
var channel = require('cordova/channel');
|
||||
var cordova = require('cordova');
|
||||
var exec = require('cordova/exec');
|
||||
var modulemapper = require('cordova/modulemapper');
|
||||
|
||||
// Get the shared secret needed to use the bridge.
|
||||
exec.init();
|
||||
@ -43,7 +43,7 @@ module.exports = {
|
||||
backButtonChannel.onHasSubscribersChange = function () {
|
||||
// If we just attached the first handler or detached the last handler,
|
||||
// let native know we need to override the back button.
|
||||
exec(null, null, APP_PLUGIN_NAME, "overrideBackbutton", [this.numHandlers == 1]);
|
||||
exec(null, null, APP_PLUGIN_NAME, 'overrideBackbutton', [this.numHandlers === 1]);
|
||||
};
|
||||
|
||||
// Add hardware MENU and SEARCH button handlers
|
||||
@ -54,7 +54,7 @@ module.exports = {
|
||||
// generic button bind used for volumeup/volumedown buttons
|
||||
var volumeButtonChannel = cordova.addDocumentEventHandler(buttonName + 'button');
|
||||
volumeButtonChannel.onHasSubscribersChange = function () {
|
||||
exec(null, null, APP_PLUGIN_NAME, "overrideButton", [buttonName, this.numHandlers == 1]);
|
||||
exec(null, null, APP_PLUGIN_NAME, 'overrideButton', [buttonName, this.numHandlers === 1]);
|
||||
};
|
||||
}
|
||||
// Inject a listener for the volume buttons on the document.
|
||||
@ -78,7 +78,7 @@ module.exports = {
|
||||
// Native code will then un-hide the WebView.
|
||||
channel.onCordovaReady.subscribe(function () {
|
||||
exec(onMessageFromNative, null, APP_PLUGIN_NAME, 'messageChannel', []);
|
||||
exec(null, null, APP_PLUGIN_NAME, "show", []);
|
||||
exec(null, null, APP_PLUGIN_NAME, 'show', []);
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -87,15 +87,12 @@ function onMessageFromNative(msg) {
|
||||
var cordova = require('cordova');
|
||||
var action = msg.action;
|
||||
|
||||
switch (action)
|
||||
{
|
||||
// Button events
|
||||
switch (action) {
|
||||
// pause and resume are Android app life cycle events
|
||||
case 'backbutton':
|
||||
case 'menubutton':
|
||||
case 'searchbutton':
|
||||
// App life cycle events
|
||||
case 'pause':
|
||||
// Volume events
|
||||
case 'volumedownbutton':
|
||||
case 'volumeupbutton':
|
||||
cordova.fireDocumentEvent(action);
|
||||
|
16
cordova-js-src/plugin/android/app.js
vendored
16
cordova-js-src/plugin/android/app.js
vendored
@ -27,7 +27,7 @@ module.exports = {
|
||||
* Clear the resource cache.
|
||||
*/
|
||||
clearCache: function () {
|
||||
exec(null, null, APP_PLUGIN_NAME, "clearCache", []);
|
||||
exec(null, null, APP_PLUGIN_NAME, 'clearCache', []);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -45,14 +45,14 @@ module.exports = {
|
||||
* navigator.app.loadUrl("http://server/myapp/index.html", {wait:2000, loadingDialog:"Wait,Loading App", loadUrlTimeoutValue: 60000});
|
||||
*/
|
||||
loadUrl: function (url, props) {
|
||||
exec(null, null, APP_PLUGIN_NAME, "loadUrl", [url, props]);
|
||||
exec(null, null, APP_PLUGIN_NAME, 'loadUrl', [url, props]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Cancel loadUrl that is waiting to be loaded.
|
||||
*/
|
||||
cancelLoadUrl: function () {
|
||||
exec(null, null, APP_PLUGIN_NAME, "cancelLoadUrl", []);
|
||||
exec(null, null, APP_PLUGIN_NAME, 'cancelLoadUrl', []);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -60,7 +60,7 @@ module.exports = {
|
||||
* Instead of BACK button loading the previous web page, it will exit the app.
|
||||
*/
|
||||
clearHistory: function () {
|
||||
exec(null, null, APP_PLUGIN_NAME, "clearHistory", []);
|
||||
exec(null, null, APP_PLUGIN_NAME, 'clearHistory', []);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -68,7 +68,7 @@ module.exports = {
|
||||
* This is the same as pressing the backbutton on Android device.
|
||||
*/
|
||||
backHistory: function () {
|
||||
exec(null, null, APP_PLUGIN_NAME, "backHistory", []);
|
||||
exec(null, null, APP_PLUGIN_NAME, 'backHistory', []);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -81,7 +81,7 @@ module.exports = {
|
||||
* @param override T=override, F=cancel override
|
||||
*/
|
||||
overrideBackbutton: function (override) {
|
||||
exec(null, null, APP_PLUGIN_NAME, "overrideBackbutton", [override]);
|
||||
exec(null, null, APP_PLUGIN_NAME, 'overrideBackbutton', [override]);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -96,13 +96,13 @@ module.exports = {
|
||||
* @param override T=override, F=cancel override
|
||||
*/
|
||||
overrideButton: function (button, override) {
|
||||
exec(null, null, APP_PLUGIN_NAME, "overrideButton", [button, override]);
|
||||
exec(null, null, APP_PLUGIN_NAME, 'overrideButton', [button, override]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Exit and terminate the application.
|
||||
*/
|
||||
exitApp: function () {
|
||||
return exec(null, null, APP_PLUGIN_NAME, "exitApp", []);
|
||||
return exec(null, null, APP_PLUGIN_NAME, 'exitApp', []);
|
||||
}
|
||||
};
|
||||
|
@ -24,7 +24,7 @@
|
||||
"cover": "nyc jasmine --config=spec/coverage.json",
|
||||
"e2e-tests": "jasmine --config=spec/e2e/jasmine.json",
|
||||
"java-unit-tests": "node test/run_java_unit_tests.js",
|
||||
"eslint": "eslint bin spec test"
|
||||
"eslint": "eslint . \"bin/**/!(*.*|gitignore)\""
|
||||
},
|
||||
"author": "Apache Software Foundation",
|
||||
"license": "Apache-2.0",
|
||||
|
@ -260,13 +260,10 @@ describe('android project handler', function () {
|
||||
});
|
||||
|
||||
describe('of <asset> elements', function () {
|
||||
var asset = { src: 'www/dummyPlugin.js', target: 'foo/dummy.js' };
|
||||
var wwwDest; /* eslint no-unused-vars: "off" */
|
||||
var platformWwwDest; /* eslint no-unused-vars: "off" */
|
||||
var asset;
|
||||
|
||||
beforeEach(function () {
|
||||
wwwDest = path.resolve(dummyProject.www, asset.target);
|
||||
platformWwwDest = path.resolve(dummyProject.platformWww, asset.target);
|
||||
asset = { src: 'www/dummyPlugin.js', target: 'foo/dummy.js' };
|
||||
});
|
||||
|
||||
it('Test#015 : should put asset to both www and platform_www when options.usePlatformWww flag is specified', function () {
|
||||
|
Loading…
Reference in New Issue
Block a user