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/15 08:16:02 UTC
[cordova-plugin-vibration] branch master updated: refactor(eslint):
use cordova-eslint /w fix (#89)
This is an automated email from the ASF dual-hosted git repository.
timbru31 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-plugin-vibration.git
The following commit(s) were added to refs/heads/master by this push:
new b15e782 refactor(eslint): use cordova-eslint /w fix (#89)
b15e782 is described below
commit b15e782ac205519dd6a536ddbf6f19ed122fe8f0
Author: Tim Brust <gi...@timbrust.de>
AuthorDate: Wed Apr 15 08:15:53 2020 +0000
refactor(eslint): use cordova-eslint /w fix (#89)
---
.eslintrc.yml | 31 ++++++---
package.json | 12 +---
src/browser/Vibration.js | 2 +-
src/windows/VibrationProxy.js | 35 +++++++---
tests/tests.js | 150 +++++++++++++++++++++++++-----------------
www/vibration.js | 13 ++--
6 files changed, 147 insertions(+), 96 deletions(-)
diff --git a/.eslintrc.yml b/.eslintrc.yml
index 0cccb8c..17277f7 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 59d5fde..03e0900 100644
--- a/package.json
+++ b/package.json
@@ -22,8 +22,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",
@@ -35,12 +35,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/src/browser/Vibration.js b/src/browser/Vibration.js
index 26860c7..317d302 100644
--- a/src/browser/Vibration.js
+++ b/src/browser/Vibration.js
@@ -17,7 +17,7 @@
* specific language governing permissions and limitations
* under the License.
*
-*/
+ */
module.exports = {
vibrate: function (success, fail, milliseconds) {
diff --git a/src/windows/VibrationProxy.js b/src/windows/VibrationProxy.js
index a70e500..e229b81 100644
--- a/src/windows/VibrationProxy.js
+++ b/src/windows/VibrationProxy.js
@@ -22,7 +22,15 @@
/* 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) {
+ 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.');
return false;
}
@@ -129,12 +137,16 @@ function vibratePattern (patternArr, shouldRepeat, fail, patternCycle) {
return patternArr.reduce(function (previousValue, currentValue, index) {
if (index % 2 === 0) {
return previousValue.then(function () {
- module.exports.vibrate(function () { }, function (err) {
- console.error(err);
- if (fail) {
- fail(err);
- }
- }, [currentValue]);
+ module.exports.vibrate(
+ function () {},
+ function (err) {
+ console.error(err);
+ if (fail) {
+ fail(err);
+ }
+ },
+ [currentValue]
+ );
if (index === patternArr.length - 1 && shouldRepeat) {
return WinJS.Promise.timeout(currentValue).then(function () {
@@ -161,7 +173,12 @@ function vibratePattern (patternArr, shouldRepeat, fail, patternCycle) {
var DEFAULT_DURATION = 200;
var patternChainPromise;
-var VibrationDevice = (Windows.Phone && Windows.Phone.Devices && Windows.Phone.Devices.Notification && Windows.Phone.Devices.Notification.VibrationDevice && Windows.Phone.Devices.Notification.VibrationDevice);
+var VibrationDevice =
+ Windows.Phone &&
+ Windows.Phone.Devices &&
+ Windows.Phone.Devices.Notification &&
+ Windows.Phone.Devices.Notification.VibrationDevice &&
+ Windows.Phone.Devices.Notification.VibrationDevice;
if (VibrationDevice) {
// Windows Phone 10 code paths
module.exports = {
@@ -187,7 +204,7 @@ if (VibrationDevice) {
var pattern = checkReqsResult.patternParsingResult.parsed;
var repeatFromIndex = args[1];
- var shouldRepeat = (repeatFromIndex !== -1);
+ var shouldRepeat = repeatFromIndex !== -1;
var patternCycle;
if (shouldRepeat) {
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