Skip to content

Commit

Permalink
refactor(eslint): use cordova-eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
timbru31 committed Apr 14, 2020
1 parent 63e7259 commit 1fca618
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 86 deletions.
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"
}
}
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

0 comments on commit 1fca618

Please sign in to comment.