Skip to content
Permalink
Browse files
refactor(eslint): use cordova-eslint (#81)
  • Loading branch information
timbru31 committed Mar 29, 2020
1 parent feaabf1 commit f6b27a1cc4198e7ab87ebc3e281a529094298f2b
Showing 6 changed files with 137 additions and 99 deletions.
@@ -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"
@@ -27,8 +27,8 @@
"cordova-ios"
],
"scripts": {
"test": "npm run eslint",
"eslint": "node node_modules/eslint/bin/eslint www && node node_modules/eslint/bin/eslint src && node node_modules/eslint/bin/eslint tests"
"test": "npm run lint",
"lint": "eslint ."
},
"author": "Apache Software Foundation",
"license": "Apache-2.0",
@@ -40,13 +40,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",
"jshint": "^2.6.0"
"@cordova/eslint-config": "^3.0.0"
}
}
@@ -19,11 +19,16 @@
*
*/

/* global cordova */

var w3cBattery;
var winCallBack;

function success () {
winCallBack({ level: w3cBattery.level * 100, isPlugged: w3cBattery.charging });
winCallBack({
level: w3cBattery.level * 100,
isPlugged: w3cBattery.charging
});
}

var Battery = {
@@ -49,7 +54,7 @@ var Battery = {
subscribe(battery);
});
} else {
var origBattery = cordova.require('cordova/modulemapper').getOriginalSymbol(window, 'navigator.battery'); // eslint-disable-line no-undef
var origBattery = cordova.require('cordova/modulemapper').getOriginalSymbol(window, 'navigator.battery');

if (origBattery) {
subscribe(origBattery);
@@ -21,8 +21,7 @@

/* global Windows, WinJS, BatteryStatus */

var PowerManager = Windows && Windows.System &&
Windows.System.Power && Windows.System.Power.PowerManager;
var PowerManager = Windows && Windows.System && Windows.System.Power && Windows.System.Power.PowerManager;

if (PowerManager) {
var pluginCallback;
@@ -31,10 +30,13 @@ if (PowerManager) {
return;
}

pluginCallback({
level: PowerManager.remainingChargePercent,
isPlugged: PowerManager.powerSupplyStatus !== Windows.System.Power.PowerSupplyStatus.notPresent
}, { keepCallback: true });
pluginCallback(
{
level: PowerManager.remainingChargePercent,
isPlugged: PowerManager.powerSupplyStatus !== Windows.System.Power.PowerSupplyStatus.notPresent
},
{ keepCallback: true }
);
};

var BatteryWin10 = {
@@ -57,15 +59,13 @@ if (PowerManager) {
};

require('cordova/exec/proxy').add('Battery', BatteryWin10);

} else {

var stopped;

var handleResponse = function (successCb, errorCb, jsonResponse) {
var info = JSON.parse(jsonResponse);

if (info.hasOwnProperty('exceptionMessage')) {
if ({}.hasOwnProperty.call(info, 'exceptionMessage')) {
errorCb(info.exceptionMessage);
return;
}
@@ -80,17 +80,22 @@ if (PowerManager) {
}

function getBatteryStatusLevelChangeEvent (success, error) {
return BatteryStatus.BatteryStatus.getBatteryStatusChangeEvent().done(function (result) {
if (stopped) {
return;
return BatteryStatus.BatteryStatus.getBatteryStatusChangeEvent().done(
function (result) {
if (stopped) {
return;
}

handleResponse(success, error, result);

setTimeout(function () {
getBatteryStatusLevelChangeEvent(success, error);
}, 0);
},
function (err) {
fail(err);
}

handleResponse(success, error, result);

setTimeout(function () { getBatteryStatusLevelChangeEvent(success, error); }, 0);
}, function (err) {
fail(err);
});
);
}

// Battery API supported on Phone devices only so in case of

0 comments on commit f6b27a1

Please sign in to comment.