Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

refactor(eslint): use cordova-eslint /w fix #164

Merged
merged 1 commit into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

root: true
extends: semistandard
rules:
indent:
- error
- 4
camelcase: off
padded-blocks: off
operator-linebreak: off
no-throw-literal: off
extends: "@cordova/eslint-config/browser"

overrides:
- files: [tests/**/*.js]
extends: "@cordova/eslint-config/node-tests"
12 changes: 3 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
"ecosystem:cordova"
],
"scripts": {
"test": "npm run eslint && npm run objc-tests",
"test": "npm run lint && npm run objc-tests",
"objc-tests": "cd tests/ios && npm test",
"preobjc-tests": "cd tests/ios && npm install",
"eslint": "node_modules/.bin/eslint src"
"lint": "eslint ."
},
"author": "Apache Software Foundation",
"license": "Apache-2.0",
Expand All @@ -33,12 +33,6 @@
}
},
"devDependencies": {
"eslint": "^3.19.0",
"eslint-config-semistandard": "^11.0.0",
"eslint-config-standard": "^10.2.1",
"eslint-plugin-import": "^2.3.0",
"eslint-plugin-node": "^5.0.0",
"eslint-plugin-promise": "^3.5.0",
"eslint-plugin-standard": "^3.0.1"
"@cordova/eslint-config": "^3.0.0"
}
}
31 changes: 20 additions & 11 deletions src/www/ios/ios-wkwebview-exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* specific language governing permissions and limitations
* under the License.
*
*/
*/

/**
* Creates the exec bridge used to notify the native code of
Expand All @@ -35,8 +35,8 @@ function massageArgsJsToNative (args) {
args.forEach(function (arg, i) {
if (utils.typeName(arg) === 'ArrayBuffer') {
ret.push({
'CDVType': 'ArrayBuffer',
'data': base64.fromArrayBuffer(arg)
CDVType: 'ArrayBuffer',
data: base64.fromArrayBuffer(arg)
});
} else {
ret.push(arg);
Expand Down Expand Up @@ -64,7 +64,7 @@ function massageMessageNativeToJs (message) {

function convertMessageToArgsNativeToJs (message) {
var args = [];
if (!message || !message.hasOwnProperty('CDVType')) {
if (!message || !Object.prototype.hasOwnProperty.call(message, 'CDVType')) {
args.push(message);
} else if (message.CDVType === 'MultiPart') {
message.messages.forEach(function (e) {
Expand Down Expand Up @@ -99,8 +99,10 @@ var iOSExec = function () {
// an invalid callbackId and passes it even if no callbacks were given.
callbackId = 'INVALID';
} else {
throw new Error('The old format of this exec call has been removed (deprecated since 2.1). Change to: ' + // eslint-disable-line
'cordova.exec(null, null, \'Service\', \'action\', [ arg1, arg2 ]);');
throw new Error(
'The old format of this exec call has been removed (deprecated since 2.1). Change to: ' + // eslint-disable-line
"cordova.exec(null, null, 'Service', 'action', [ arg1, arg2 ]);"
);
}

// If actionArgs is not provided, default to an empty array
Expand All @@ -110,8 +112,7 @@ var iOSExec = function () {
// arguments if given.
if (successCallback || failCallback) {
callbackId = service + cordova.callbackId++;
cordova.callbacks[callbackId] =
{success: successCallback, fail: failCallback};
cordova.callbacks[callbackId] = { success: successCallback, fail: failCallback };
}

actionArgs = massageArgsJsToNative(actionArgs);
Expand Down Expand Up @@ -142,8 +143,11 @@ iOSExec.nativeEvalAndFetch = function (func) {

function cordovaExec () {
var cexec = require('cordova/exec');
var cexec_valid = (typeof cexec.nativeFetchMessages === 'function') && (typeof cexec.nativeEvalAndFetch === 'function') && (typeof cexec.nativeCallback === 'function');
return (cexec_valid && execProxy !== cexec) ? cexec : iOSExec;
var cexec_valid =
typeof cexec.nativeFetchMessages === 'function' &&
typeof cexec.nativeEvalAndFetch === 'function' &&
typeof cexec.nativeCallback === 'function';
return cexec_valid && execProxy !== cexec ? cexec : iOSExec;
}

function execProxy () {
Expand All @@ -164,7 +168,12 @@ execProxy.nativeCallback = function () {

module.exports = execProxy;

if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.cordova && window.webkit.messageHandlers.cordova.postMessage) {
if (
window.webkit &&
window.webkit.messageHandlers &&
window.webkit.messageHandlers.cordova &&
window.webkit.messageHandlers.cordova.postMessage
) {
// unregister the old bridge
cordova.define.remove('cordova/exec');
// redefine bridge to our new bridge
Expand Down
2 changes: 1 addition & 1 deletion src/www/ios/ios-wkwebview.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* specific language governing permissions and limitations
* under the License.
*
*/
*/

var exec = require('cordova/exec');

Expand Down
30 changes: 17 additions & 13 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,32 @@
* specific language governing permissions and limitations
* under the License.
*
*/

/* jshint jasmine: true */
*/

exports.defineAutoTests = function () {
describe('cordova-plugin-wkwebview-engine (cordova)', function () {
it("cordova-plugin-wkwebview-engine.spec.1 should exist", function () {
//expect(window).toBeDefined();
it('cordova-plugin-wkwebview-engine.spec.1 should exist', function () {
expect(window).toBeDefined();
});
});
};

exports.defineManualTests = function (contentEl, createActionButton) {

contentEl.innerHTML = 'Your HTML instructions here';

createActionButton('Do something 1', function () {
// do something 1;
}, 'do-something-1');

createActionButton('Do something 2', function () {
// do something 2;
}, 'do-something-2');
createActionButton(
'Do something 1',
function () {
// do something 1;
},
'do-something-1'
);

createActionButton(
'Do something 2',
function () {
// do something 2;
},
'do-something-2'
);
};