Skip to content
Permalink
Browse files
refactor(eslint): use cordova-eslint /w fix (#89)
  • Loading branch information
timbru31 committed Apr 15, 2020
1 parent 52ca18c commit b15e782ac205519dd6a536ddbf6f19ed122fe8f0
Showing 6 changed files with 147 additions and 96 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'
@@ -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"
}
}
@@ -17,7 +17,7 @@
* specific language governing permissions and limitations
* under the License.
*
*/
*/

module.exports = {
vibrate: function (success, fail, milliseconds) {
@@ -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) {
@@ -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'
);
};
@@ -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;
}

0 comments on commit b15e782

Please sign in to comment.