You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ti...@apache.org on 2020/03/28 21:01:32 UTC

[cordova-plugin-battery-status] branch feat/adds-cordova-eslint created (now ddebcf0)

This is an automated email from the ASF dual-hosted git repository.

timbru31 pushed a change to branch feat/adds-cordova-eslint
in repository https://gitbox.apache.org/repos/asf/cordova-plugin-battery-status.git.


      at ddebcf0  refactor(eslint): use cordova-eslint

This branch includes the following new commits:

     new ddebcf0  refactor(eslint): use cordova-eslint

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


[cordova-plugin-battery-status] 01/01: refactor(eslint): use cordova-eslint

Posted by ti...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

timbru31 pushed a commit to branch feat/adds-cordova-eslint
in repository https://gitbox.apache.org/repos/asf/cordova-plugin-battery-status.git

commit ddebcf0f02afc41e30d884c93adef77c6a839d8a
Author: Tim Brust <gi...@timbrust.de>
AuthorDate: Sat Mar 28 22:00:45 2020 +0100

    refactor(eslint): use cordova-eslint
---
 .eslintrc.yml               |  31 +++++++----
 package.json                |  13 ++---
 src/browser/BatteryProxy.js |   7 ++-
 src/windows/BatteryProxy.js |  43 ++++++++-------
 tests/tests.js              | 125 +++++++++++++++++++++++++++-----------------
 www/battery.js              |  17 +++---
 6 files changed, 139 insertions(+), 97 deletions(-)

diff --git a/.eslintrc.yml b/.eslintrc.yml
index 0cccb8c..6a02457 100644
--- a/.eslintrc.yml
+++ b/.eslintrc.yml
@@ -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
\ No newline at end of file
+extends: "@cordova/eslint-config/browser"
+
+overrides:
+  - files: [tests/**/*.js]
+    extends: "@cordova/eslint-config/node-tests"
diff --git a/package.json b/package.json
index fb1bafa..7997a02 100644
--- a/package.json
+++ b/package.json
@@ -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"
   }
 }
diff --git a/src/browser/BatteryProxy.js b/src/browser/BatteryProxy.js
index 878f356..3abb051 100644
--- a/src/browser/BatteryProxy.js
+++ b/src/browser/BatteryProxy.js
@@ -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 = {
diff --git a/src/windows/BatteryProxy.js b/src/windows/BatteryProxy.js
index f83a8b1..2376a10 100644
--- a/src/windows/BatteryProxy.js
+++ b/src/windows/BatteryProxy.js
@@ -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
diff --git a/tests/tests.js b/tests/tests.js
index c956f45..88e659c 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -19,22 +19,24 @@
  *
  */
 
-/* eslint-env jasmine */
-/* global Windows, WinJS */
-
+/* global Windows, WinJS, cordova */
 exports.defineAutoTests = function () {
-    var hasPowerManagerAPI = cordova.platformId === 'windows' && // eslint-disable-line no-undef
-        Windows && Windows.System && Windows.System.Power &&
+    var hasPowerManagerAPI =
+        cordova.platformId === 'windows' && // eslint-disable-line no-undef
+        Windows &&
+        Windows.System &&
+        Windows.System.Power &&
         Windows.System.Power.PowerManager;
 
-    var batteryStatusUnsupported = (cordova.platformId === 'windows8' || // eslint-disable-line no-undef
-        // We don't test battery status on Windows when there is no corresponding APIs available
-        cordova.platformId === 'windows') && !(hasPowerManagerAPI || WinJS.Utilities.isPhone); // eslint-disable-line no-undef
+    var batteryStatusUnsupported =
+        (cordova.platformId === 'windows8' || // eslint-disable-line no-undef
+            // We don't test battery status on Windows when there is no corresponding APIs available
+            cordova.platformId === 'windows') &&
+        !(hasPowerManagerAPI || WinJS.Utilities.isPhone); // eslint-disable-line no-undef
 
     var onEvent;
 
     describe('Battery (navigator.battery)', function () {
-
         it('battery.spec.1 should exist', function () {
             if (batteryStatusUnsupported) {
                 pending('Battery status is not supported on windows store');
@@ -45,9 +47,7 @@ exports.defineAutoTests = function () {
     });
 
     describe('Battery Events', function () {
-
         describe('batterystatus', function () {
-
             afterEach(function () {
                 if (!batteryStatusUnsupported) {
                     try {
@@ -77,12 +77,10 @@ exports.defineAutoTests = function () {
                     expect(onEvent).toHaveBeenCalled();
                     done();
                 }, 100);
-
             });
         });
 
         describe('batterylow', function () {
-
             afterEach(function () {
                 if (!batteryStatusUnsupported) {
                     try {
@@ -117,7 +115,6 @@ exports.defineAutoTests = function () {
                     expect(onEvent).toHaveBeenCalled();
                     done();
                 }, 100);
-
             });
 
             it('battery.spec.3.1 should fire batterylow event (30 -> 19)', function (done) {
@@ -200,7 +197,6 @@ exports.defineAutoTests = function () {
         });
 
         describe('batterycritical', function () {
-
             afterEach(function () {
                 if (!batteryStatusUnsupported) {
                     try {
@@ -235,7 +231,6 @@ exports.defineAutoTests = function () {
                     expect(onEvent).toHaveBeenCalled();
                     done();
                 }, 100);
-
             });
 
             it('battery.spec.4.1 should fire batterycritical event (19 -> 4)', function (done) {
@@ -262,7 +257,6 @@ exports.defineAutoTests = function () {
                     expect(onEvent).toHaveBeenCalled();
                     done();
                 }, 100);
-
             });
 
             it('battery.spec.4.2 should fire batterycritical event (100 -> 4) when decreases', function (done) {
@@ -351,7 +345,6 @@ exports.defineAutoTests = function () {
 //* *****************************************************************************************
 
 exports.defineManualTests = function (contentEl, createActionButton) {
-
     /* Battery */
     function updateInfo (info) {
         document.getElementById('levelValue').innerText = info.level;
@@ -427,8 +420,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
         return table;
     }
     // Battery Elements
-    var batteryElements =
-        [{
+    var batteryElements = [
+        {
             id: 'statusTag',
             content: 'Status:',
             tag: 'div',
@@ -436,7 +429,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
                 row: 0,
                 cell: 0
             }
-        }, {
+        },
+        {
             id: 'statusValue',
             content: '',
             tag: 'div',
@@ -444,7 +438,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
                 row: 0,
                 cell: 1
             }
-        }, {
+        },
+        {
             id: 'levelTag',
             content: 'Level:',
             tag: 'div',
@@ -452,7 +447,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
                 row: 1,
                 cell: 0
             }
-        }, {
+        },
+        {
             id: 'levelValue',
             content: '',
             tag: 'div',
@@ -460,7 +456,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
                 row: 1,
                 cell: 1
             }
-        }, {
+        },
+        {
             id: 'pluggedTag',
             content: 'Plugged:',
             tag: 'div',
@@ -468,7 +465,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
                 row: 2,
                 cell: 0
             }
-        }, {
+        },
+        {
             id: 'pluggedValue',
             content: '',
             tag: 'div',
@@ -476,7 +474,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
                 row: 2,
                 cell: 1
             }
-        }, {
+        },
+        {
             id: 'lowTag',
             content: 'Low:',
             tag: 'div',
@@ -484,7 +483,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
                 row: 3,
                 cell: 0
             }
-        }, {
+        },
+        {
             id: 'lowValue',
             content: '',
             tag: 'div',
@@ -492,7 +492,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
                 row: 3,
                 cell: 1
             }
-        }, {
+        },
+        {
             id: 'criticalTag',
             content: 'Critical:',
             tag: 'div',
@@ -500,7 +501,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
                 row: 4,
                 cell: 0
             }
-        }, {
+        },
+        {
             id: 'criticalValue',
             content: '',
             tag: 'div',
@@ -509,7 +511,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
                 cell: 1
             }
         }
-        ];
+    ];
 
     // Title audio results
     var div = document.createElement('h2');
@@ -525,7 +527,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
     div.setAttribute('align', 'center');
     contentEl.appendChild(div);
 
-    contentEl.innerHTML += '<h3>Battery Status Tests</h3>' +
+    contentEl.innerHTML +=
+        '<h3>Battery Status Tests</h3>' +
         'Will update values for level and plugged when they change. If battery low and critical values are false, they will get updated in status box, but only once' +
         '<div id="addBS"></div><div id="remBs"></div>' +
         '<h3>Battery Low Tests</h3>' +
@@ -535,22 +538,46 @@ exports.defineManualTests = function (contentEl, createActionButton) {
         '</p> Will update value for battery critical to true when battery is below 5%' +
         '<div id="addBc"></div><div id="remBc"></div>';
 
-    createActionButton('Add "batterystatus" listener', function () {
-        addBattery();
-    }, 'addBS');
-    createActionButton('Remove "batterystatus" listener', function () {
-        removeBattery();
-    }, 'remBs');
-    createActionButton('Add "batterylow" listener', function () {
-        addLow();
-    }, 'addBl');
-    createActionButton('Remove "batterylow" listener', function () {
-        removeLow();
-    }, 'remBl');
-    createActionButton('Add "batterycritical" listener', function () {
-        addCritical();
-    }, 'addBc');
-    createActionButton('Remove "batterycritical" listener', function () {
-        removeCritical();
-    }, 'remBc');
+    createActionButton(
+        'Add "batterystatus" listener',
+        function () {
+            addBattery();
+        },
+        'addBS'
+    );
+    createActionButton(
+        'Remove "batterystatus" listener',
+        function () {
+            removeBattery();
+        },
+        'remBs'
+    );
+    createActionButton(
+        'Add "batterylow" listener',
+        function () {
+            addLow();
+        },
+        'addBl'
+    );
+    createActionButton(
+        'Remove "batterylow" listener',
+        function () {
+            removeLow();
+        },
+        'remBl'
+    );
+    createActionButton(
+        'Add "batterycritical" listener',
+        function () {
+            addCritical();
+        },
+        'addBc'
+    );
+    createActionButton(
+        'Remove "batterycritical" listener',
+        function () {
+            removeCritical();
+        },
+        'remBc'
+    );
 };
diff --git a/www/battery.js b/www/battery.js
index e3a69ed..45de470 100644
--- a/www/battery.js
+++ b/www/battery.js
@@ -17,7 +17,7 @@
  * specific language governing permissions and limitations
  * under the License.
  *
-*/
+ */
 
 /**
  * This class contains information about the current battery status.
@@ -44,9 +44,9 @@ var Battery = function () {
 };
 
 function handlers () {
-    return battery.channels.batterystatus.numHandlers +
-        battery.channels.batterylow.numHandlers +
-        battery.channels.batterycritical.numHandlers;
+    return (
+        battery.channels.batterystatus.numHandlers + battery.channels.batterylow.numHandlers + battery.channels.batterycritical.numHandlers
+    );
 }
 
 /**
@@ -55,7 +55,7 @@ function handlers () {
  * appropriately (and hopefully save on battery life!).
  */
 Battery.onHasSubscribersChange = function () {
-  // If we just registered the first handler, make sure native listener is started.
+    // If we just registered the first handler, make sure native listener is started.
     if (this.numHandlers === 1 && handlers() === 1) {
         exec(battery._status, battery._error, 'Battery', 'start', []);
     } else if (handlers() === 0) {
@@ -69,10 +69,8 @@ Battery.onHasSubscribersChange = function () {
  * @param {Object} info            keys: level, isPlugged
  */
 Battery.prototype._status = function (info) {
-
     if (info) {
         if (battery._level !== info.level || battery._isPlugged !== info.isPlugged) {
-
             if (info.level === null && battery._level !== null) {
                 return; // special case where callback is called because we stopped listening to the native side.
             }
@@ -80,7 +78,8 @@ Battery.prototype._status = function (info) {
             // Something changed. Fire batterystatus event
             cordova.fireWindowEvent('batterystatus', info);
 
-            if (!info.isPlugged) { // do not fire low/critical if we are charging. issue: CB-4520
+            // do not fire low/critical if we are charging. issue: CB-4520
+            if (!info.isPlugged) {
                 // note the following are NOT exact checks, as we want to catch a transition from
                 // above the threshold to below. issue: CB-4519
                 if (battery._level > STATUS_CRITICAL && info.level <= STATUS_CRITICAL) {
@@ -104,6 +103,6 @@ Battery.prototype._error = function (e) {
     console.log('Error initializing Battery: ' + e);
 };
 
-var battery = new Battery(); // jshint ignore:line
+var battery = new Battery();
 
 module.exports = battery;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org