cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject [3/4] cordova-plugin-vibration git commit: CB-10636 Add JSHint for plugins
Date Fri, 15 Apr 2016 20:49:59 GMT
CB-10636 Add JSHint for plugins


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/commit/db41c781
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/tree/db41c781
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/diff/db41c781

Branch: refs/heads/2.1.x
Commit: db41c781874962e4c5141606e5c5a124fbbc6065
Parents: 2475bfa
Author: daserge <v-seshak@microsoft.com>
Authored: Tue Mar 1 11:43:36 2016 +0300
Committer: daserge <v-seshak@microsoft.com>
Committed: Tue Mar 1 11:45:30 2016 +0300

----------------------------------------------------------------------
 .gitignore                      |  2 +-
 .jshintrc                       | 17 +++++++++++++++++
 .travis.yml                     |  4 ++++
 README.md                       |  2 ++
 package.json                    |  9 ++++++++-
 src/blackberry10/index.js       |  2 ++
 src/browser/Vibration.js        |  2 --
 src/firefoxos/VibrationProxy.js |  2 --
 src/windows/VibrationProxy.js   | 36 +++++++++++++++++++++++++++---------
 tests/tests.js                  | 16 ++++++++--------
 www/vibration.js                |  4 ++--
 11 files changed, 71 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/blob/db41c781/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 52b558e..6964ea0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,7 +12,7 @@ Thumbs.db
 *.swp
 *.user
 
-
+node_modules
 
 
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/blob/db41c781/.jshintrc
----------------------------------------------------------------------
diff --git a/.jshintrc b/.jshintrc
new file mode 100644
index 0000000..df32482
--- /dev/null
+++ b/.jshintrc
@@ -0,0 +1,17 @@
+{
+    "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
+    }
+}

http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/blob/db41c781/.travis.yml
----------------------------------------------------------------------
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"

http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/blob/db41c781/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 38a3742..a4cf899 100644
--- a/README.md
+++ b/README.md
@@ -17,6 +17,8 @@
 #         under the License.
 -->
 
+[![Build Status](https://travis-ci.org/apache/cordova-plugin-vibration.svg?branch=master)](https://travis-ci.org/apache/cordova-plugin-vibration)
+
 # cordova-plugin-vibration
 
 This plugin aligns with the W3C vibration specification http://www.w3.org/TR/vibration/

http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/blob/db41c781/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 56b6142..c6fbcae 100644
--- a/package.json
+++ b/package.json
@@ -34,6 +34,13 @@
     "cordova-blackberry10",
     "cordova-tizen"
   ],
+  "scripts": {
+    "test": "npm run jshint",
+    "jshint": "jshint www && jshint src && jshint tests"
+  },
   "author": "Apache Software Foundation",
-  "license": "Apache-2.0"
+  "license": "Apache-2.0",
+  "devDependencies": {
+    "jshint": "^2.6.0"
+  }
 }

http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/blob/db41c781/src/blackberry10/index.js
----------------------------------------------------------------------
diff --git a/src/blackberry10/index.js b/src/blackberry10/index.js
index a380962..b014f24 100644
--- a/src/blackberry10/index.js
+++ b/src/blackberry10/index.js
@@ -19,6 +19,8 @@
  *
 */
 
+/* global PluginResult, JNEXT */
+
 var vibration;
 
 module.exports = {

http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/blob/db41c781/src/browser/Vibration.js
----------------------------------------------------------------------
diff --git a/src/browser/Vibration.js b/src/browser/Vibration.js
index 04f1759..f803a8d 100644
--- a/src/browser/Vibration.js
+++ b/src/browser/Vibration.js
@@ -19,8 +19,6 @@
  *
 */
 
-var cordova = require('cordova');
-
 module.exports = {
     vibrate: function(success, fail, milliseconds) {
         console.log('Vibration is not supported');

http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/blob/db41c781/src/firefoxos/VibrationProxy.js
----------------------------------------------------------------------
diff --git a/src/firefoxos/VibrationProxy.js b/src/firefoxos/VibrationProxy.js
index 3c109a5..3d2a2cf 100644
--- a/src/firefoxos/VibrationProxy.js
+++ b/src/firefoxos/VibrationProxy.js
@@ -19,8 +19,6 @@
  *
 */
 
-var cordova = require('cordova');
-
 module.exports = {
 
     vibrate: function(success, fail, milliseconds) {

http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/blob/db41c781/src/windows/VibrationProxy.js
----------------------------------------------------------------------
diff --git a/src/windows/VibrationProxy.js b/src/windows/VibrationProxy.js
index 0c01eb1..eede750 100644
--- a/src/windows/VibrationProxy.js
+++ b/src/windows/VibrationProxy.js
@@ -19,6 +19,8 @@
  *
  */
 
+/* global Windows, WinJS, Vibration */
+
 function checkReqs(actionName, fail) {
     if (!(Windows.Phone && Windows.Phone.Devices && Windows.Phone.Devices.Notification
&& Windows.Phone.Devices.Notification.VibrationDevice) && WinJS.Utilities.isPhone
!== true) {       
         fail(actionName + ' is unsupported by this platform.');
@@ -35,7 +37,7 @@ function tryDoAction(actionName, success, fail, args, action) {
         }
 
         action(args);
-        success();        
+        success();
     } catch (e) {
         fail('Error occured while trying to ' + actionName + ': ' + e);
     }
@@ -102,7 +104,9 @@ function checkPatternReqs(args, fail) {
 
     if (!passed) {
         console.error(errMsg);
-        fail && fail(errMsg);
+        if (fail) {
+            fail(errMsg);
+        }
     }
 
     return {
@@ -125,7 +129,9 @@ function vibratePattern(patternArr, shouldRepeat, fail, patternCycle)
{
             return previousValue.then(function () {
                 module.exports.vibrate(function () { }, function (err) {
                     console.error(err);
-                    fail && fail(err);
+                    if (fail) {
+                        fail(err);
+                    }
                 }, [currentValue]);
 
                 if (index === patternArr.length - 1 && shouldRepeat) {
@@ -192,12 +198,18 @@ if (VibrationDevice) {
         },
         cancelVibration: function(success, fail, args) {
             try {
-                patternChainPromise && patternChainPromise.cancel();
+                if (patternChainPromise) {
+                    patternChainPromise.cancel();
+                }
                 VibrationDevice.getDefault().cancel();
-                success && success();
+                if (success) {
+                    success();
+                }
             }
             catch (e) {
-                fail && fail(e);
+                if (fail) {
+                    fail(e);
+                }
             }
         }
     };
@@ -220,14 +232,20 @@ if (VibrationDevice) {
     // code paths where no vibration mechanism is present
     module.exports = {
         vibrate: function (success, fail) {
-            fail && fail('"vibrate" is unsupported by this device.');
+            if (fail) {
+                fail('"vibrate" is unsupported by this device.');
+            }
         },
         vibrateWithPattern: function (success, fail, args) {
-            fail && fail('"vibrateWithPattern" is unsupported by this device.');
+            if (fail) {
+                fail('"vibrateWithPattern" is unsupported by this device.');
+            }
         },
 
         cancelVibration: function (success, fail, args) {
-            success && success();
+            if (success) {
+                success();
+            }
         }
     };
 }

http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/blob/db41c781/tests/tests.js
----------------------------------------------------------------------
diff --git a/tests/tests.js b/tests/tests.js
index 88dbc45..5fbfab6 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -19,6 +19,8 @@
  *
  */
 
+/* jshint jasmine: true */
+
 exports.defineAutoTests = function () {
 
     describe('Vibration (navigator.notification.vibrate)', function () {
@@ -42,12 +44,12 @@ exports.defineManualTests = function (contentEl, createActionButton) {
         }
         logLine.innerHTML = message;
         log.appendChild(logLine);
-    }
+    };
 
     var clearLog = function () {
         var log = document.getElementById('info');
         log.innerHTML = '';
-    }
+    };
 
     //-------------------------------------------------------------------------
     // Vibrations
@@ -119,6 +121,9 @@ exports.defineManualTests = function (contentEl, createActionButton) {
     //reference to the timeout variable
     var timeout;
 
+    //check whether there is an ongoing vibration
+    var vibrateOn = false;
+
     //special long vibrate used to test cancel
     var longVibrate = function() {
         clearLog();
@@ -145,17 +150,12 @@ exports.defineManualTests = function (contentEl, createActionButton)
{
         vibrateOn = true;
         logMessage("navigator.vibrate(15000)\nnavigator.vibrate(45000)", "green");
         timeout = setTimeout(resetVibrateOn, 45000); //if user doesn't cancel vibrate, reset
vibrateOn var after 45 seconds
-    }
+    };
 
     function resetVibrateOn() {
         vibrateOn = false;
     }
 
-    //check whether there is an ongoing vibration
-    var vibrateOn = false;
-
-
-
 
     var vibrate_tests = '<h1>Vibrate Tests</h1>' +
         '<h3>Starred tests only work for Android and Windows. </h3>' +

http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/blob/db41c781/www/vibration.js
----------------------------------------------------------------------
diff --git a/www/vibration.js b/www/vibration.js
index 16a7398..122c74d 100644
--- a/www/vibration.js
+++ b/www/vibration.js
@@ -55,14 +55,14 @@ module.exports = {
         /* Aligning with w3c spec */
         
         //vibrate
-        if ((typeof param == 'number') && param != 0)
+        if ((typeof param == 'number') && param !== 0)
             exec(null, null, "Vibration", "vibrate", [param]);
 
         //vibrate with array ( i.e. vibrate([3000]) )
         else if ((typeof param == 'object') && param.length == 1)
         {
             //cancel if vibrate([0])
-            if (param[0] == 0)
+            if (param[0] === 0)
                 exec(null, null, "Vibration", "cancelVibration", []);
 
             //else vibrate


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


Mime
View raw message