Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(eslint): use cordova-eslint /w fix #89

Merged
merged 1 commit into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -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'
12 changes: 3 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
2 changes: 1 addition & 1 deletion src/browser/Vibration.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* specific language governing permissions and limitations
* under the License.
*
*/
*/

module.exports = {
vibrate: function (success, fail, milliseconds) {
Expand Down
35 changes: 26 additions & 9 deletions src/windows/VibrationProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 () {
Expand All @@ -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 = {
Expand All @@ -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) {
Expand Down
150 changes: 88 additions & 62 deletions tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
*
*/

/* eslint-env jasmine */

exports.defineManualTests = function (contentEl, createActionButton) {
var logMessage = function (message, color) {
var log = document.getElementById('info');
Expand Down Expand Up @@ -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>' +
Expand All @@ -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'
);
};
13 changes: 7 additions & 6 deletions www/vibration.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* specific language governing permissions and limitations
* under the License.
*
*/
*/

var exec = require('cordova/exec');

Expand All @@ -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).
*
Expand Down Expand Up @@ -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', []);
Expand All @@ -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;
}
Expand Down