CB-12895 : added eslint and removed eslint

This commit is contained in:
Audrey So
2017-06-12 11:15:35 -07:00
parent f9643daba0
commit 78691e43e1
11 changed files with 174 additions and 183 deletions
+10
View File
@@ -0,0 +1,10 @@
root: true
extends: semistandard
rules:
indent:
- error
- 4
camelcase: off
padded-blocks: off
operator-linebreak: off
no-throw-literal: off
-17
View File
@@ -1,17 +0,0 @@
{
"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,
"cordova": true
}
}
+9 -3
View File
@@ -46,8 +46,8 @@
"cordova-browser" "cordova-browser"
], ],
"scripts": { "scripts": {
"test": "npm run jshint", "test": "npm run eslint",
"jshint": "jshint www && jshint src && jshint tests" "eslint": "eslint www && eslint src && eslint tests"
}, },
"author": "Apache Software Foundation", "author": "Apache Software Foundation",
"license": "Apache-2.0", "license": "Apache-2.0",
@@ -59,6 +59,12 @@
} }
}, },
"devDependencies": { "devDependencies": {
"jshint": "^2.6.0" "eslint": "^4.0.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"
} }
} }
+8 -9
View File
@@ -21,9 +21,9 @@
/* global PluginResult */ /* global PluginResult */
//map from BB10 to cordova connection types: // map from BB10 to cordova connection types:
//https://github.com/apache/cordova-js/blob/master/lib/common/plugin/Connection.js // https://github.com/apache/cordova-js/blob/master/lib/common/plugin/Connection.js
function mapConnectionType(con) { function mapConnectionType (con) {
switch (con.type) { switch (con.type) {
case 'wired': case 'wired':
return 'ethernet'; return 'ethernet';
@@ -43,17 +43,16 @@ function mapConnectionType(con) {
case 'lte': case 'lte':
return '4g'; return '4g';
} }
return "cellular"; return 'cellular';
} }
return 'unknown'; return 'unknown';
} }
function currentConnectionType() { function currentConnectionType () {
try { try {
//possible for webplatform to throw pps exception // possible for webplatform to throw pps exception
return mapConnectionType(window.qnx.webplatform.device.activeConnection || { type : 'none' }); return mapConnectionType(window.qnx.webplatform.device.activeConnection || { type: 'none' });
} } catch (e) {
catch (e) {
return 'unknown'; return 'unknown';
} }
} }
+10 -12
View File
@@ -18,31 +18,29 @@
* *
*/ */
var cordova = require('cordova'), var cordova = require('cordova');
proxy = require("cordova/exec/proxy"), var proxy = require('cordova/exec/proxy');
Connection = require('./Connection'); var Connection = require('./Connection');
var type = navigator.onLine ? Connection.UNKNOWN : Connection.NONE; var type = navigator.onLine ? Connection.UNKNOWN : Connection.NONE;
// Subscribe to 'native' online/offline events // Subscribe to 'native' online/offline events
function onStatusChange(evt) { function onStatusChange (evt) {
type = navigator.onLine ? Connection.UNKNOWN : Connection.NONE; type = navigator.onLine ? Connection.UNKNOWN : Connection.NONE;
// force async // force async
setTimeout(function(){ setTimeout(function () {
cordova.fireDocumentEvent(evt.type); cordova.fireDocumentEvent(evt.type);
},0); }, 0);
} }
window.addEventListener('online', onStatusChange); window.addEventListener('online', onStatusChange);
window.addEventListener('offline', onStatusChange); window.addEventListener('offline', onStatusChange);
proxy.add("NetworkStatus", { proxy.add('NetworkStatus', {
getConnectionInfo:function(cbSuccess) { getConnectionInfo: function (cbSuccess) {
// force async // force async
setTimeout(function(){ setTimeout(function () {
cbSuccess(type); cbSuccess(type);
},0); }, 0);
} }
}); });
+59 -59
View File
@@ -24,73 +24,73 @@
and http://w3c.github.io/netinfo/ and http://w3c.github.io/netinfo/
*/ */
var Connection = require('./Connection'), var Connection = require('./Connection');
modulemapper = require('cordova/modulemapper'); var modulemapper = require('cordova/modulemapper');
var origConnection = modulemapper.getOriginalSymbol(window, 'navigator.connection'); var origConnection = modulemapper.getOriginalSymbol(window, 'navigator.connection');
module.exports = { module.exports = {
getConnectionInfo: function(successCallback, errorCallback) { getConnectionInfo: function (successCallback, errorCallback) {
var connection = origConnection || navigator.mozConnection, var connection = origConnection || navigator.mozConnection;
connectionType = Connection.UNKNOWN; var connectionType = Connection.UNKNOWN;
if (!connection) { if (!connection) {
setTimeout(function() { setTimeout(function () {
successCallback(connectionType);
}, 0);
return;
}
var bandwidth = connection.bandwidth;
var metered = connection.metered;
var type = connection.type;
if (type !== undefined) {
// For more information see:
// https://developer.mozilla.org/en-US/docs/Web/API/Network_Information_API
switch (type) {
case 'cellular':
connectionType = Connection.CELL;
break;
case 'ethernet':
connectionType = Connection.ETHERNET;
break;
case 'wifi':
connectionType = Connection.WIFI;
break;
case 'none':
connectionType = Connection.NONE;
break;
}
} else if (bandwidth !== undefined && metered !== undefined) {
/*
bandwidth of type double, readonly
The user agent must set the value of the bandwidth attribute to:
0 if the user is currently offline;
Infinity if the bandwidth is unknown;
an estimation of the current bandwidth in MB/s (Megabytes per seconds)
available for communication with the browsing context active document's
domain.
For more information see:
https://developer.mozilla.org/en-US/docs/Web/API/Connection
*/
if (bandwidth === 0) {
connectionType = Connection.NONE;
} else if (metered && isFinite(bandwidth)) {
connectionType = Connection.CELL;
} else if (!metered && isFinite(bandwidth)) {
connectionType = Connection.WIFI;
}
}
setTimeout(function () {
successCallback(connectionType); successCallback(connectionType);
}, 0); }, 0);
return;
} }
var bandwidth = connection.bandwidth,
metered = connection.metered,
type = connection.type;
if (type !== undefined) {
// For more information see:
// https://developer.mozilla.org/en-US/docs/Web/API/Network_Information_API
switch(type) {
case "cellular":
connectionType = Connection.CELL;
break;
case "ethernet":
connectionType = Connection.ETHERNET;
break;
case "wifi":
connectionType = Connection.WIFI;
break;
case "none":
connectionType = Connection.NONE;
break;
}
} else if (bandwidth !== undefined && metered !== undefined) {
/*
bandwidth of type double, readonly
The user agent must set the value of the bandwidth attribute to:
0 if the user is currently offline;
Infinity if the bandwidth is unknown;
an estimation of the current bandwidth in MB/s (Megabytes per seconds)
available for communication with the browsing context active document's
domain.
For more information see:
https://developer.mozilla.org/en-US/docs/Web/API/Connection
*/
if (bandwidth === 0) {
connectionType = Connection.NONE;
} else if (metered && isFinite(bandwidth)) {
connectionType = Connection.CELL;
} else if (!metered && isFinite(bandwidth)) {
connectionType = Connection.WIFI;
}
}
setTimeout(function() {
successCallback(connectionType);
}, 0);
}
}; };
require("cordova/exec/proxy").add("NetworkStatus", module.exports); require('cordova/exec/proxy').add('NetworkStatus', module.exports);
+12 -16
View File
@@ -24,15 +24,14 @@
var Connection = require('./Connection'); var Connection = require('./Connection');
module.exports = { module.exports = {
getConnectionInfo: function(successCallback, errorCallback) { getConnectionInfo: function (successCallback, errorCallback) {
var cncType = Connection.NONE; var cncType = Connection.NONE;
var infoCount = 0; var infoCount = 0;
var deviceCapabilities = null; var deviceCapabilities = null;
var timerId = 0; var timerId = 0;
var timeout = 300; var timeout = 300;
function connectionCB () {
function connectionCB() {
if (timerId !== null) { if (timerId !== null) {
clearTimeout(timerId); clearTimeout(timerId);
timerId = null; timerId = null;
@@ -47,47 +46,44 @@ module.exports = {
} }
} }
function errorCB(error) { function errorCB (error) {
console.log("Error: " + error.code + "," + error.name + "," + error.message); console.log('Error: ' + error.code + ',' + error.name + ',' + error.message);
if (errorCallback) { if (errorCallback) {
errorCallback(); errorCallback();
} }
} }
function wifiSuccessCB(wifi) { function wifiSuccessCB (wifi) {
if ((wifi.status === "ON") && (wifi.ipAddress.length !== 0)) { if ((wifi.status === 'ON') && (wifi.ipAddress.length !== 0)) {
cncType = Connection.WIFI; cncType = Connection.WIFI;
} }
connectionCB(); connectionCB();
} }
function cellularSuccessCB(cell) { function cellularSuccessCB (cell) {
if ((cncType === Connection.NONE) && (cell.status === "ON") && (cell.ipAddress.length !== 0)) { if ((cncType === Connection.NONE) && (cell.status === 'ON') && (cell.ipAddress.length !== 0)) {
cncType = Connection.CELL_2G; cncType = Connection.CELL_2G;
} }
connectionCB(); connectionCB();
} }
deviceCapabilities = tizen.systeminfo.getCapabilities(); deviceCapabilities = tizen.systeminfo.getCapabilities();
timerId = setTimeout(function () {
timerId = setTimeout(function() {
timerId = null; timerId = null;
infoCount = 1; infoCount = 1;
connectionCB(); connectionCB();
}, timeout); }, timeout);
if (deviceCapabilities.wifi) { if (deviceCapabilities.wifi) {
tizen.systeminfo.getPropertyValue("WIFI_NETWORK", wifiSuccessCB, errorCB); tizen.systeminfo.getPropertyValue('WIFI_NETWORK', wifiSuccessCB, errorCB);
} }
if (deviceCapabilities.telephony) { if (deviceCapabilities.telephony) {
tizen.systeminfo.getPropertyValue("CELLULAR_NETWORK", cellularSuccessCB, errorCB); tizen.systeminfo.getPropertyValue('CELLULAR_NETWORK', cellularSuccessCB, errorCB);
} }
} }
}; };
require("cordova/tizen/commandProxy").add("NetworkStatus", module.exports); require('cordova/tizen/commandProxy').add('NetworkStatus', module.exports);
+19 -20
View File
@@ -19,14 +19,14 @@
* *
*/ */
/*global Windows:true */ /* global Windows:true */
var Connection = require('./Connection'); var Connection = require('./Connection');
var winNetConn = Windows.Networking.Connectivity; var winNetConn = Windows.Networking.Connectivity;
var networkInfo = winNetConn.NetworkInformation; var networkInfo = winNetConn.NetworkInformation;
function getCurrrentConnectionType() { function getCurrrentConnectionType () {
var profile = networkInfo.getInternetConnectionProfile(); var profile = networkInfo.getInternetConnectionProfile();
@@ -40,26 +40,26 @@ function getCurrrentConnectionType() {
// since we use this to detect whether we are online or offline we do check agains InternetAccess // since we use this to detect whether we are online or offline we do check agains InternetAccess
// localAccess (airplane mode as an example) or constrainedInternetAccess mean there is no access to the internet available // localAccess (airplane mode as an example) or constrainedInternetAccess mean there is no access to the internet available
// https://msdn.microsoft.com/library/windows/apps/windows.networking.connectivity.networkconnectivitylevel.aspx // https://msdn.microsoft.com/library/windows/apps/windows.networking.connectivity.networkconnectivitylevel.aspx
if (conLevel != Windows.Networking.Connectivity.NetworkConnectivityLevel.internetAccess) { if (conLevel !== Windows.Networking.Connectivity.NetworkConnectivityLevel.internetAccess) {
return Connection.NONE; return Connection.NONE;
} }
var connectionType; var connectionType;
switch (interfaceType) { switch (interfaceType) {
case 71: case 71:
connectionType = Connection.WIFI; connectionType = Connection.WIFI;
break; break;
case 6: case 6:
connectionType = Connection.ETHERNET; connectionType = Connection.ETHERNET;
break; break;
case 243: // (3GPP WWAN) // Fallthrough is intentional case 243: // (3GPP WWAN) // Fallthrough is intentional
case 244: // (3GPP2 WWAN) case 244: // (3GPP2 WWAN)
connectionType = Connection.CELL_3G; connectionType = Connection.CELL_3G;
break; break;
default: default:
connectionType = Connection.UNKNOWN; connectionType = Connection.UNKNOWN;
break; break;
} }
return connectionType; return connectionType;
@@ -67,8 +67,7 @@ function getCurrrentConnectionType() {
module.exports = { module.exports = {
getConnectionInfo:function(win,fail,args) getConnectionInfo: function (win, fail, args) {
{
var reportConnectionInfoOnce = function () { var reportConnectionInfoOnce = function () {
win(getCurrrentConnectionType(), { keepCallback: true }); win(getCurrrentConnectionType(), { keepCallback: true });
}; };
@@ -76,8 +75,8 @@ module.exports = {
// report current connection type // report current connection type
setTimeout(reportConnectionInfoOnce, 0); setTimeout(reportConnectionInfoOnce, 0);
// start traking future changes // start traking future changes
networkInfo.addEventListener("networkstatuschanged", reportConnectionInfoOnce); networkInfo.addEventListener('networkstatuschanged', reportConnectionInfoOnce);
} }
}; };
require("cordova/exec/proxy").add("NetworkStatus",module.exports); require('cordova/exec/proxy').add('NetworkStatus', module.exports);
+22 -22
View File
@@ -19,17 +19,17 @@
* *
*/ */
/* jshint jasmine: true */ /* eslint-env jasmine */
/* global Connection */ /* global Connection */
exports.defineAutoTests = function () { exports.defineAutoTests = function () {
describe('Network (navigator.connection)', function () { describe('Network (navigator.connection)', function () {
it("network.spec.1 should exist", function () { it('network.spec.1 should exist', function () {
expect(navigator.network && navigator.network.connection).toBeDefined(); expect(navigator.network && navigator.network.connection).toBeDefined();
expect(navigator.connection).toBeDefined(); expect(navigator.connection).toBeDefined();
}); });
it("network.spec.2 should be set to a valid value", function () { it('network.spec.2 should be set to a valid value', function () {
var validValues = { var validValues = {
'unknown': 1, 'unknown': 1,
'ethernet': 1, 'ethernet': 1,
@@ -43,19 +43,19 @@ exports.defineAutoTests = function () {
expect(validValues[navigator.connection.type]).toBe(1); expect(validValues[navigator.connection.type]).toBe(1);
}); });
it("network.spec.3 should have the same value in deprecated and non-deprecated apis", function () { it('network.spec.3 should have the same value in deprecated and non-deprecated apis', function () {
expect(navigator.network.connection.type).toBe(navigator.connection.type); expect(navigator.network.connection.type).toBe(navigator.connection.type);
}); });
it("network.spec.4 should define constants for connection status", function () { it('network.spec.4 should define constants for connection status', function () {
expect(Connection.UNKNOWN).toBe("unknown"); expect(Connection.UNKNOWN).toBe('unknown');
expect(Connection.ETHERNET).toBe("ethernet"); expect(Connection.ETHERNET).toBe('ethernet');
expect(Connection.WIFI).toBe("wifi"); expect(Connection.WIFI).toBe('wifi');
expect(Connection.CELL_2G).toBe("2g"); expect(Connection.CELL_2G).toBe('2g');
expect(Connection.CELL_3G).toBe("3g"); expect(Connection.CELL_3G).toBe('3g');
expect(Connection.CELL_4G).toBe("4g"); expect(Connection.CELL_4G).toBe('4g');
expect(Connection.NONE).toBe("none"); expect(Connection.NONE).toBe('none');
expect(Connection.CELL).toBe("cellular"); expect(Connection.CELL).toBe('cellular');
}); });
}); });
}; };
@@ -65,17 +65,17 @@ exports.defineAutoTests = function () {
/******************************************************************************/ /******************************************************************************/
exports.defineManualTests = function (contentEl, createActionButton) { exports.defineManualTests = function (contentEl, createActionButton) {
function eventOutput(s) { function eventOutput (s) {
var el = document.getElementById("results"); var el = document.getElementById('results');
el.innerHTML = el.innerHTML + s + "<br>"; el.innerHTML = el.innerHTML + s + '<br>';
} }
function printNetwork() { function printNetwork () {
eventOutput("navigator.connection.type=" + navigator.connection.type); eventOutput('navigator.connection.type=' + navigator.connection.type);
eventOutput("navigator.network.connection.type=" + navigator.network.connection.type); eventOutput('navigator.network.connection.type=' + navigator.network.connection.type);
} }
function onEvent(e) { function onEvent (e) {
eventOutput('Event of type: ' + e.type); eventOutput('Event of type: ' + e.type);
printNetwork(); printNetwork();
} }
@@ -90,8 +90,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
' The result will be unknown, ethernet, wifi, 2g, 3g, 4g, none, or cellular. Make sure it matches what the device is connected to.' + ' The result will be unknown, ethernet, wifi, 2g, 3g, 4g, none, or cellular. Make sure it matches what the device is connected to.' +
'</p> <div id="actions"></div>'; '</p> <div id="actions"></div>';
document.addEventListener("online", onEvent, false); document.addEventListener('online', onEvent, false);
document.addEventListener("offline", onEvent, false); document.addEventListener('offline', onEvent, false);
contentEl.innerHTML = html; contentEl.innerHTML = html;
createActionButton('Show Network Connection', function () { createActionButton('Show Network Connection', function () {
+8 -8
View File
@@ -23,12 +23,12 @@
* Network status * Network status
*/ */
module.exports = { module.exports = {
UNKNOWN: "unknown", UNKNOWN: 'unknown',
ETHERNET: "ethernet", ETHERNET: 'ethernet',
WIFI: "wifi", WIFI: 'wifi',
CELL_2G: "2g", CELL_2G: '2g',
CELL_3G: "3g", CELL_3G: '3g',
CELL_4G: "4g", CELL_4G: '4g',
CELL:"cellular", CELL: 'cellular',
NONE: "none" NONE: 'none'
}; };
+17 -17
View File
@@ -18,23 +18,23 @@
* *
*/ */
var exec = require('cordova/exec'), var exec = require('cordova/exec');
cordova = require('cordova'), var cordova = require('cordova');
channel = require('cordova/channel'), var channel = require('cordova/channel');
utils = require('cordova/utils'); var utils = require('cordova/utils');
// Link the onLine property with the Cordova-supplied network info. // Link the onLine property with the Cordova-supplied network info.
// This works because we clobber the navigator object with our own // This works because we clobber the navigator object with our own
// object in bootstrap.js. // object in bootstrap.js.
// Browser platform do not need to define this property, because // Browser platform do not need to define this property, because
// it is already supported by modern browsers // it is already supported by modern browsers
if (cordova.platformId !== 'browser' && typeof navigator != 'undefined') { if (cordova.platformId !== 'browser' && typeof navigator !== 'undefined') {
utils.defineGetter(navigator, 'onLine', function() { utils.defineGetter(navigator, 'onLine', function () {
return this.connection.type != 'none'; return this.connection.type !== 'none';
}); });
} }
function NetworkConnection() { function NetworkConnection () {
this.type = 'unknown'; this.type = 'unknown';
} }
@@ -44,8 +44,8 @@ function NetworkConnection() {
* @param {Function} successCallback The function to call when the Connection data is available * @param {Function} successCallback The function to call when the Connection data is available
* @param {Function} errorCallback The function to call when there is an error getting the Connection data. (OPTIONAL) * @param {Function} errorCallback The function to call when there is an error getting the Connection data. (OPTIONAL)
*/ */
NetworkConnection.prototype.getInfo = function(successCallback, errorCallback) { NetworkConnection.prototype.getInfo = function (successCallback, errorCallback) {
exec(successCallback, errorCallback, "NetworkStatus", "getConnectionInfo", []); exec(successCallback, errorCallback, 'NetworkStatus', 'getConnectionInfo', []);
}; };
var me = new NetworkConnection(); var me = new NetworkConnection();
@@ -55,13 +55,13 @@ var timeout = 500;
channel.createSticky('onCordovaConnectionReady'); channel.createSticky('onCordovaConnectionReady');
channel.waitForInitialization('onCordovaConnectionReady'); channel.waitForInitialization('onCordovaConnectionReady');
channel.onCordovaReady.subscribe(function() { channel.onCordovaReady.subscribe(function () {
me.getInfo(function(info) { me.getInfo(function (info) {
me.type = info; me.type = info;
if (info === "none") { if (info === 'none') {
// set a timer if still offline at the end of timer send the offline event // set a timer if still offline at the end of timer send the offline event
timerId = setTimeout(function(){ timerId = setTimeout(function () {
cordova.fireDocumentEvent("offline"); cordova.fireDocumentEvent('offline');
timerId = null; timerId = null;
}, timeout); }, timeout);
} else { } else {
@@ -70,7 +70,7 @@ channel.onCordovaReady.subscribe(function() {
clearTimeout(timerId); clearTimeout(timerId);
timerId = null; timerId = null;
} }
cordova.fireDocumentEvent("online"); cordova.fireDocumentEvent('online');
} }
// should only fire this once // should only fire this once
@@ -84,7 +84,7 @@ channel.onCordovaReady.subscribe(function() {
if (channel.onCordovaConnectionReady.state !== 2) { if (channel.onCordovaConnectionReady.state !== 2) {
channel.onCordovaConnectionReady.fire(); channel.onCordovaConnectionReady.fire();
} }
console.log("Error initializing Network Connection: " + e); console.log('Error initializing Network Connection: ' + e);
}); });
}); });