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/04/14 19:31:06 UTC

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

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

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

commit 1fca61804e3de1ca2961de3402b18d63dc2a183e
Author: Tim Brust <ti...@sinnerschrader.com>
AuthorDate: Tue Apr 14 21:30:44 2020 +0200

    refactor(eslint): use cordova-eslint
---
 .eslintrc.yml    |  31 ++++++++----
 package.json     |  12 ++---
 tests/tests.js   | 150 ++++++++++++++++++++++++++++++++-----------------------
 www/vibration.js |  13 ++---
 4 files changed, 120 insertions(+), 86 deletions(-)

diff --git a/.eslintrc.yml b/.eslintrc.yml
index 0cccb8c..4062d90 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'
\ No newline at end of file
diff --git a/package.json b/package.json
index 5233003..1469adf 100644
--- a/package.json
+++ b/package.json
@@ -27,8 +27,8 @@
     "cordova-windows"
   ],
   "scripts": {
-    "test": "npm run eslint",
-    "eslint": "eslint www && eslint src && eslint tests"
+    "test": "npm run lint",
+    "lint": "eslint ."
   },
   "author": "Apache Software Foundation",
   "license": "Apache-2.0",
@@ -40,12 +40,6 @@
     }
   },
   "devDependencies": {
-    "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"
+    "@cordova/eslint-config": "^3.0.0"
   }
 }
diff --git a/tests/tests.js b/tests/tests.js
index 675b002..2254fb6 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -19,8 +19,6 @@
  *
  */
 
-/* eslint-env jasmine */
-
 exports.defineManualTests = function (contentEl, createActionButton) {
     var logMessage = function (message, color) {
         var log = document.getElementById('info');
@@ -114,7 +112,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
         vibrateOn = false;
     }
 
-    var vibrate_tests = '<h1>Vibrate Tests</h1>' +
+    var vibrate_tests =
+        '<h1>Vibrate Tests</h1>' +
         '<h3>Starred tests only work for Android and Windows. </h3>' +
         '<h3>iOS ignores the time given for a vibrate </h3>' +
         '<p/> <div id="vibrate_int"></div>' +
@@ -137,77 +136,104 @@ exports.defineManualTests = function (contentEl, createActionButton) {
     contentEl.innerHTML = '<div id="info"></div>' + vibrate_tests;
 
     // standard vibrate with new call param int
-    createActionButton('Vibrate with int', function () {
-        vibrateWithInt();
-    }, 'vibrate_int');
+    createActionButton(
+        'Vibrate with int',
+        function () {
+            vibrateWithInt();
+        },
+        'vibrate_int'
+    );
 
     // standard vibrate with new call param array
-    createActionButton('Vibrate with array', function () {
-        vibrateWithArray();
-    }, 'vibrate_array');
+    createActionButton(
+        'Vibrate with array',
+        function () {
+            vibrateWithArray();
+        },
+        'vibrate_array'
+    );
 
     // vibrate with a pattern
-    createActionButton('* Vibrate with a pattern', function () {
-        vibrateWithPattern();
-    }, 'vibrate_with_pattern');
+    createActionButton(
+        '* Vibrate with a pattern',
+        function () {
+            vibrateWithPattern();
+        },
+        'vibrate_with_pattern'
+    );
 
     // cancel any existing vibrations with param 0
-    createActionButton('* Cancel vibration with 0', function () {
-
-        if (!vibrateOn) {
-            longVibrate();
-        } else {
-            cancelWithZero();
-            resetVibrateOn();
-            clearTimeout(timeout); // clear the timeout since user has canceled the vibrate
-        }
-    }, 'cancel_zero');
+    createActionButton(
+        '* Cancel vibration with 0',
+        function () {
+            if (!vibrateOn) {
+                longVibrate();
+            } else {
+                cancelWithZero();
+                resetVibrateOn();
+                clearTimeout(timeout); // clear the timeout since user has canceled the vibrate
+            }
+        },
+        'cancel_zero'
+    );
 
     // cancel any existing vibrations with param []
-    createActionButton('* Cancel vibration with []', function () {
-
-        if (!vibrateOn) {
-            longVibrate();
-        } else {
-            cancelWithEmpty();
-            resetVibrateOn();
-            clearTimeout(timeout); // clear the timeout since user has canceled the vibrate
-        }
-    }, 'cancel_array');
+    createActionButton(
+        '* Cancel vibration with []',
+        function () {
+            if (!vibrateOn) {
+                longVibrate();
+            } else {
+                cancelWithEmpty();
+                resetVibrateOn();
+                clearTimeout(timeout); // clear the timeout since user has canceled the vibrate
+            }
+        },
+        'cancel_array'
+    );
 
     // cancel vibration with pattern with param 0
-    createActionButton('* Cancel vibration with pattern with 0', function () {
-
-        if (!vibrateOn) {
-            longVibrateWithPattern();
-        } else {
-            cancelWithZero();
-            resetVibrateOn();
-            clearTimeout(timeout); // clear the timeout since user has canceled the vibrate
-        }
-    }, 'cancelWithPattern_zero');
+    createActionButton(
+        '* Cancel vibration with pattern with 0',
+        function () {
+            if (!vibrateOn) {
+                longVibrateWithPattern();
+            } else {
+                cancelWithZero();
+                resetVibrateOn();
+                clearTimeout(timeout); // clear the timeout since user has canceled the vibrate
+            }
+        },
+        'cancelWithPattern_zero'
+    );
 
     // cancel vibration with pattern with param []
-    createActionButton('* Cancel vibration with pattern with []', function () {
-
-        if (!vibrateOn) {
-            longVibrateWithPattern();
-        } else {
-            cancelWithEmpty();
-            resetVibrateOn();
-            clearTimeout(timeout); // clear the timeout since user has canceled the vibrate
-        }
-    }, 'cancelWithPattern_array');
+    createActionButton(
+        '* Cancel vibration with pattern with []',
+        function () {
+            if (!vibrateOn) {
+                longVibrateWithPattern();
+            } else {
+                cancelWithEmpty();
+                resetVibrateOn();
+                clearTimeout(timeout); // clear the timeout since user has canceled the vibrate
+            }
+        },
+        'cancelWithPattern_array'
+    );
 
     // cancel multiple vibrations
-    createActionButton('* Cancel multiple vibrations', function () {
-
-        if (!vibrateOn) {
-            multipleVibrations();
-        } else {
-            cancelWithZero();
-            resetVibrateOn();
-            clearTimeout(timeout); // clear the timeout since user has canceled the vibrate
-        }
-    }, 'cancelMultipleVibrations');
+    createActionButton(
+        '* Cancel multiple vibrations',
+        function () {
+            if (!vibrateOn) {
+                multipleVibrations();
+            } else {
+                cancelWithZero();
+                resetVibrateOn();
+                clearTimeout(timeout); // clear the timeout since user has canceled the vibrate
+            }
+        },
+        'cancelMultipleVibrations'
+    );
 };
diff --git a/www/vibration.js b/www/vibration.js
index 28dbc99..871f682 100644
--- a/www/vibration.js
+++ b/www/vibration.js
@@ -17,7 +17,7 @@
  * specific language governing permissions and limitations
  * under the License.
  *
-*/
+ */
 
 var exec = require('cordova/exec');
 
@@ -26,7 +26,6 @@ var exec = require('cordova/exec');
  */
 
 module.exports = {
-
     /**
      * Vibrates the device for a given amount of time or for a given pattern or immediately cancels any ongoing vibrations (depending on the parameter).
      *
@@ -54,11 +53,11 @@ 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) {
+        } else if (typeof param === 'object' && param.length === 1) {
             // cancel if vibrate([0])
             if (param[0] === 0) {
                 exec(null, null, 'Vibration', 'cancelVibration', []);
@@ -69,12 +68,14 @@ module.exports = {
             }
 
         // vibrate with a pattern
-        } else if ((typeof param === 'object') && param.length > 1) {
+        } else if (typeof param === 'object' && param.length > 1) {
             var repeat = -1; // no repeat
             exec(null, null, 'Vibration', 'vibrateWithPattern', [param, repeat]);
 
         // cancel vibration (param = 0 or [])
-        } else { exec(null, null, 'Vibration', 'cancelVibration', []); }
+        } else {
+            exec(null, null, 'Vibration', 'cancelVibration', []);
+        }
 
         return true;
     }


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