From ea1253963bc5d8a0e7b0684c7ecb7e231444a140 Mon Sep 17 00:00:00 2001 From: daserge Date: Fri, 19 Feb 2016 15:39:28 +0300 Subject: [PATCH] CB-10636 Add JSHint for plugins --- .gitignore | 1 + .jshintrc | 16 +++++++++++++++ .travis.yml | 4 ++++ README.md | 2 ++ package.json | 9 ++++++++- src/browser/InAppBrowserProxy.js | 24 +++++++++++++---------- src/firefoxos/InAppBrowserProxy.js | 24 ++++++++++------------- src/ubuntu/InAppBrowser_escapeScript.js | 3 +++ src/windows/InAppBrowserProxy.js | 26 ++++++++++++++----------- tests/resources/inject.js | 2 +- tests/tests.js | 15 ++++++++------ www/windows8/InAppBrowserProxy.js | 5 ----- 12 files changed, 83 insertions(+), 48 deletions(-) create mode 100644 .jshintrc create mode 100644 .travis.yml diff --git a/.gitignore b/.gitignore index 52b558e..2209f42 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ Thumbs.db *.swp *.user +node_modules diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..cf48aac --- /dev/null +++ b/.jshintrc @@ -0,0 +1,16 @@ +{ + "browser": true + , "devel": true + , "bitwise": true + , "undef": true + , "trailing": true + , "quotmark": false + , "indent": 4 + , "unused": "vars" + , "latedef": "nofunc" + , "globals": { + "module": false, + "exports": false, + "require": false + } +} diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..b9af4c5 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +sudo: false +node_js: + - "4.2" diff --git a/README.md b/README.md index 8e8f5f4..ada1786 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ # under the License. --> +[![Build Status](https://travis-ci.org/apache/cordova-plugin-inappbrowser.svg?branch=master)](https://travis-ci.org/apache/cordova-plugin-inappbrowser) + # cordova-plugin-inappbrowser This plugin provides a web browser view that displays when calling `cordova.InAppBrowser.open()`. diff --git a/package.json b/package.json index 42759f2..98e8371 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,10 @@ "cordova-windows", "cordova-firefoxos" ], + "scripts": { + "test": "npm run jshint", + "jshint": "node node_modules/jshint/bin/jshint www && node node_modules/jshint/bin/jshint src && node node_modules/jshint/bin/jshint tests" + }, "engines": [ { "name": "cordova", @@ -44,5 +48,8 @@ } ], "author": "Apache Software Foundation", - "license": "Apache-2.0" + "license": "Apache-2.0", + "devDependencies": { + "jshint": "^2.6.0" + } } diff --git a/src/browser/InAppBrowserProxy.js b/src/browser/InAppBrowserProxy.js index a9926f6..6dfdd1e 100644 --- a/src/browser/InAppBrowserProxy.js +++ b/src/browser/InAppBrowserProxy.js @@ -19,10 +19,7 @@ * */ -var cordova = require('cordova'), - channel = require('cordova/channel'), - modulemapper = require('cordova/modulemapper'), - urlutil = require('cordova/urlutil'); +var modulemapper = require('cordova/modulemapper'); var browserWrap, popup, @@ -69,8 +66,7 @@ var IAB = { open: function (win, lose, args) { var strUrl = args[0], target = args[1], - features = args[2], - url; + features = args[2]; if (target === "_self" || !target) { window.location = strUrl; @@ -193,7 +189,9 @@ var IAB = { if (browserWrap && popup) { try { popup.contentWindow.eval(code); - hasCallback && win([]); + if (hasCallback) { + win([]); + } } catch(e) { console.error('Error occured while trying to injectScriptCode: ' + JSON.stringify(e)); } @@ -203,19 +201,25 @@ var IAB = { injectScriptFile: function (win, fail, args) { var msg = 'Browser cordova-plugin-inappbrowser injectScriptFile is not yet implemented'; console.warn(msg); - fail && fail(msg); + if (fail) { + fail(msg); + } }, injectStyleCode: function (win, fail, args) { var msg = 'Browser cordova-plugin-inappbrowser injectStyleCode is not yet implemented'; console.warn(msg); - fail && fail(msg); + if (fail) { + fail(msg); + } }, injectStyleFile: function (win, fail, args) { var msg = 'Browser cordova-plugin-inappbrowser injectStyleFile is not yet implemented'; console.warn(msg); - fail && fail(msg); + if (fail) { + fail(msg); + } } }; diff --git a/src/firefoxos/InAppBrowserProxy.js b/src/firefoxos/InAppBrowserProxy.js index f0d44c1..c09e358 100644 --- a/src/firefoxos/InAppBrowserProxy.js +++ b/src/firefoxos/InAppBrowserProxy.js @@ -21,9 +21,7 @@ // https://developer.mozilla.org/en-US/docs/WebAPI/Browser -var cordova = require('cordova'), - channel = require('cordova/channel'), - modulemapper = require('cordova/modulemapper'); +var modulemapper = require('cordova/modulemapper'); var origOpenFunc = modulemapper.getOriginalSymbol(window, 'window.open'); var browserWrap; @@ -49,9 +47,7 @@ var IABExecs = { var strUrl = args[0], target = args[1], features_string = args[2] || "location=yes", //location=yes is default - features = {}, - url, - elem; + features = {}; var features_list = features_string.split(','); features_list.forEach(function(feature) { @@ -61,7 +57,7 @@ var IABExecs = { } else if (tup[1] == 'no') { tup[1] = false; } else { - var number = parseInt(tup[1]); + var number = parseInt(tup[1]); if (!isNaN(number)) { tup[1] = number; } @@ -115,7 +111,7 @@ var IABExecs = { back.classList.add('inAppBrowserBack'); forward.classList.add('inAppBrowserForward'); - function checkForwardBackward() { + var checkForwardBackward = function () { var backReq = browserElem.getCanGoBack(); backReq.onsuccess = function() { if (this.result) { @@ -123,7 +119,7 @@ var IABExecs = { } else { back.classList.add('disabled'); } - } + }; var forwardReq = browserElem.getCanGoForward(); forwardReq.onsuccess = function() { if (this.result) { @@ -131,7 +127,7 @@ var IABExecs = { } else { forward.classList.add('disabled'); } - } + }; }; browserElem.addEventListener('mozbrowserloadend', checkForwardBackward); @@ -163,16 +159,16 @@ var IABExecs = { win({ type:'loadstart', url : e.detail - }) + }); }, false); browserElem.addEventListener('mozbrowserloadend', function(e){ - win({type:'loadstop'}) + win({type:'loadstop'}); }, false); browserElem.addEventListener('mozbrowsererror', function(e){ - win({type:'loaderror'}) + win({type:'loaderror'}); }, false); browserElem.addEventListener('mozbrowserclose', function(e){ - win({type:'exit'}) + win({type:'exit'}); }, false); } else { window.location = strUrl; diff --git a/src/ubuntu/InAppBrowser_escapeScript.js b/src/ubuntu/InAppBrowser_escapeScript.js index 07661bb..b01daeb 100644 --- a/src/ubuntu/InAppBrowser_escapeScript.js +++ b/src/ubuntu/InAppBrowser_escapeScript.js @@ -19,6 +19,9 @@ * */ +/* jshint -W061 */ +/* global oxide */ + oxide.addMessageHandler("EXECUTE", function(msg) { var code = msg.args.code; try { diff --git a/src/windows/InAppBrowserProxy.js b/src/windows/InAppBrowserProxy.js index f6d1da6..b9880b3 100644 --- a/src/windows/InAppBrowserProxy.js +++ b/src/windows/InAppBrowserProxy.js @@ -19,10 +19,8 @@ * */ -/*jslint sloppy:true */ -/*global Windows:true, require, document, setTimeout, window, module */ - - +/* jslint sloppy:true */ +/* global Windows:true, setImmediate */ var cordova = require('cordova'), urlutil = require('cordova/urlutil'); @@ -188,7 +186,7 @@ var IAB = { }; navigationButtonsDivInner = document.createElement("div"); - navigationButtonsDivInner.className = "inappbrowser-app-bar-inner" + navigationButtonsDivInner.className = "inappbrowser-app-bar-inner"; navigationButtonsDivInner.onclick = function (e) { e.cancelBubble = true; }; @@ -253,9 +251,11 @@ var IAB = { if (isWebViewAvailable && browserWrap && popup) { var op = popup.invokeScriptAsync("eval", code); op.oncomplete = function (e) { - // return null if event target is unavailable by some reason - var result = (e && e.target) ? [e.target.result] : [null]; - hasCallback && win(result); + if (hasCallback) { + // return null if event target is unavailable by some reason + var result = (e && e.target) ? [e.target.result] : [null]; + win(result); + } }; op.onerror = function () { }; op.start(); @@ -278,8 +278,10 @@ var IAB = { Windows.Storage.FileIO.readTextAsync(file).done(function (code) { var op = popup.invokeScriptAsync("eval", code); op.oncomplete = function(e) { - var result = [e.target.result]; - hasCallback && win(result); + if (hasCallback) { + var result = [e.target.result]; + win(result); + } }; op.onerror = function () { }; op.start(); @@ -329,7 +331,9 @@ function injectCSS (webView, cssCode, callback) { var op = webView.invokeScriptAsync("eval", evalWrapper); op.oncomplete = function() { - callback && callback([]); + if (callback) { + callback([]); + } }; op.onerror = function () { }; op.start(); diff --git a/tests/resources/inject.js b/tests/resources/inject.js index 6f25493..a89a421 100644 --- a/tests/resources/inject.js +++ b/tests/resources/inject.js @@ -16,5 +16,5 @@ * specific language governing permissions and limitations * under the License. */ -var d = document.getElementById("header") +var d = document.getElementById("header"); d.innerHTML = "Script file successfully injected"; diff --git a/tests/tests.js b/tests/tests.js index 03e3e12..8ba8ee2 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -19,6 +19,9 @@ * */ +/* jshint jasmine: true */ +/* global MSApp */ + var cordova = require('cordova'); var isWindows = cordova.platformId == 'windows'; @@ -183,13 +186,13 @@ exports.defineManualTests = function (contentEl, createActionButton) { if (e.url != lastLoadStartURL) { alert('Unexpected: ' + e.type + ' event.url != loadstart\'s event.url'); } - if (numExpectedRedirects === 0 && counts['loadstart'] !== 1) { + if (numExpectedRedirects === 0 && counts.loadstart !== 1) { // Do allow a loaderror without a loadstart (e.g. in the case of an invalid URL). - if (!(e.type == 'loaderror' && counts['loadstart'] === 0)) { - alert('Unexpected: got multiple loadstart events. (' + counts['loadstart'] + ')'); + if (!(e.type == 'loaderror' && counts.loadstart === 0)) { + alert('Unexpected: got multiple loadstart events. (' + counts.loadstart + ')'); } - } else if (numExpectedRedirects > 0 && counts['loadstart'] < (numExpectedRedirects + 1)) { - alert('Unexpected: should have got at least ' + (numExpectedRedirects + 1) + ' loadstart events, but got ' + counts['loadstart']); + } else if (numExpectedRedirects > 0 && counts.loadstart < (numExpectedRedirects + 1)) { + alert('Unexpected: should have got at least ' + (numExpectedRedirects + 1) + ' loadstart events, but got ' + counts.loadstart); } wasReset = true; numExpectedRedirects = 0; @@ -197,7 +200,7 @@ exports.defineManualTests = function (contentEl, createActionButton) { } // Verify that loadend / loaderror was called. if (e.type == 'exit') { - var numStopEvents = counts['loadstop'] + counts['loaderror']; + var numStopEvents = counts.loadstop + counts.loaderror; if (numStopEvents === 0 && !wasReset) { alert('Unexpected: browser closed without a loadstop or loaderror.'); } else if (numStopEvents > 1) { diff --git a/www/windows8/InAppBrowserProxy.js b/www/windows8/InAppBrowserProxy.js index 42d15d2..ed95477 100644 --- a/www/windows8/InAppBrowserProxy.js +++ b/www/windows8/InAppBrowserProxy.js @@ -22,10 +22,6 @@ /*jslint sloppy:true */ /*global Windows:true, require, document, setTimeout, window, module */ - -var cordova = require('cordova'), - channel = require('cordova/channel'); - var browserWrap; var IAB = { @@ -45,7 +41,6 @@ var IAB = { open: function (win, lose, args) { var strUrl = args[0], target = args[1], - features = args[2], url, elem;