Skip to content

Commit d56ab5b

Browse files
author
daserge
committed
CB-10636 Add JSHint for plugins
1 parent aa69e1b commit d56ab5b

File tree

8 files changed

+82
-48
lines changed

8 files changed

+82
-48
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Thumbs.db
1212
*.swp
1313
*.user
1414

15-
15+
node_modules
1616

1717

1818

.jshintrc

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"browser": true
3+
, "devel": true
4+
, "bitwise": true
5+
, "undef": true
6+
, "trailing": true
7+
, "quotmark": false
8+
, "indent": 4
9+
, "unused": "vars"
10+
, "latedef": "nofunc"
11+
, "globals": {
12+
"module": false,
13+
"exports": false,
14+
"require": false,
15+
"cordova": true
16+
}
17+
}

.travis.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
language: node_js
2+
sudo: false
3+
node_js:
4+
- "4.2"

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
# under the License.
1818
-->
1919

20+
[![Build Status](https://travis-ci.org/apache/cordova-plugin-geolocation.svg?branch=master)](https://travis-ci.org/apache/cordova-plugin-geolocation)
21+
2022
# cordova-plugin-geolocation
2123

2224
This plugin provides information about the device's location, such as

package.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@
3636
"cordova-windows",
3737
"cordova-firefoxos"
3838
],
39+
"scripts": {
40+
"test": "npm run jshint",
41+
"jshint": "node node_modules/jshint/bin/jshint www && node node_modules/jshint/bin/jshint src && node node_modules/jshint/bin/jshint tests"
42+
},
3943
"author": "Apache Software Foundation",
40-
"license": "Apache-2.0"
44+
"license": "Apache-2.0",
45+
"devDependencies": {
46+
"jshint": "^2.6.0"
47+
}
4148
}

src/windows/GeolocationProxy.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
/* global Windows, WinJS */
18+
1719
var PositionError = require('./PositionError');
1820
var callbacks = {};
1921
var locs = {};
@@ -128,11 +130,11 @@ module.exports = {
128130
var clientId = args[0];
129131
var highAccuracy = args[1];
130132

131-
onPositionChanged = function (e) {
133+
var onPositionChanged = function (e) {
132134
success(createResult(e.position), { keepCallback: true });
133-
},
135+
};
134136

135-
onStatusChanged = function (e) {
137+
var onStatusChanged = function (e) {
136138
switch (e.status) {
137139
case Windows.Devices.Geolocation.PositionStatus.noData:
138140
case Windows.Devices.Geolocation.PositionStatus.notAvailable:
@@ -183,7 +185,7 @@ module.exports = {
183185
clearWatch: function (success, fail, args, env) {
184186
var clientId = args[0];
185187
var callback = callbacks[clientId];
186-
var loc = locs[clientId]
188+
var loc = locs[clientId];
187189

188190
if (callback && loc) {
189191
loc.removeEventListener("positionchanged", callback.pos);

tests/tests.js

+40-36
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
* under the License.
1919
*
2020
*/
21+
22+
/* jshint jasmine: true */
23+
/* global WinJS, device */
24+
2125
exports.defineAutoTests = function () {
2226
var fail = function (done, context, message) {
2327
// prevents done() to be called several times
@@ -266,6 +270,40 @@ exports.defineAutoTests = function () {
266270
exports.defineManualTests = function (contentEl, createActionButton) {
267271
var watchLocationId = null;
268272

273+
/**
274+
* Set location status
275+
*/
276+
function setLocationStatus(status) {
277+
document.getElementById('location_status').innerHTML = status;
278+
}
279+
function setLocationDetails(p) {
280+
var date = (new Date(p.timestamp));
281+
document.getElementById('latitude').innerHTML = p.coords.latitude;
282+
document.getElementById('longitude').innerHTML = p.coords.longitude;
283+
document.getElementById('altitude').innerHTML = p.coords.altitude;
284+
document.getElementById('accuracy').innerHTML = p.coords.accuracy;
285+
document.getElementById('heading').innerHTML = p.coords.heading;
286+
document.getElementById('speed').innerHTML = p.coords.speed;
287+
document.getElementById('altitude_accuracy').innerHTML = p.coords.altitudeAccuracy;
288+
document.getElementById('timestamp').innerHTML = date.toDateString() + " " + date.toTimeString();
289+
}
290+
291+
/**
292+
* Stop watching the location
293+
*/
294+
function stopLocation() {
295+
var geo = navigator.geolocation;
296+
if (!geo) {
297+
alert('navigator.geolocation object is missing.');
298+
return;
299+
}
300+
setLocationStatus("Stopped");
301+
if (watchLocationId) {
302+
geo.clearWatch(watchLocationId);
303+
watchLocationId = null;
304+
}
305+
}
306+
269307
/**
270308
* Start watching location
271309
*/
@@ -292,22 +330,6 @@ exports.defineManualTests = function (contentEl, createActionButton) {
292330
setLocationStatus("Running");
293331
};
294332

295-
/**
296-
* Stop watching the location
297-
*/
298-
var stopLocation = function () {
299-
var geo = navigator.geolocation;
300-
if (!geo) {
301-
alert('navigator.geolocation object is missing.');
302-
return;
303-
}
304-
setLocationStatus("Stopped");
305-
if (watchLocationId) {
306-
geo.clearWatch(watchLocationId);
307-
watchLocationId = null;
308-
}
309-
};
310-
311333
/**
312334
* Get current location
313335
*/
@@ -340,24 +362,6 @@ exports.defineManualTests = function (contentEl, createActionButton) {
340362

341363
};
342364

343-
/**
344-
* Set location status
345-
*/
346-
var setLocationStatus = function (status) {
347-
document.getElementById('location_status').innerHTML = status;
348-
};
349-
var setLocationDetails = function (p) {
350-
var date = (new Date(p.timestamp));
351-
document.getElementById('latitude').innerHTML = p.coords.latitude;
352-
document.getElementById('longitude').innerHTML = p.coords.longitude;
353-
document.getElementById('altitude').innerHTML = p.coords.altitude;
354-
document.getElementById('accuracy').innerHTML = p.coords.accuracy;
355-
document.getElementById('heading').innerHTML = p.coords.heading;
356-
document.getElementById('speed').innerHTML = p.coords.speed;
357-
document.getElementById('altitude_accuracy').innerHTML = p.coords.altitudeAccuracy;
358-
document.getElementById('timestamp').innerHTML = date.toDateString() + " " + date.toTimeString();
359-
};
360-
361365
/******************************************************************************/
362366

363367
var location_div = '<div id="info">' +
@@ -423,8 +427,8 @@ exports.defineManualTests = function (contentEl, createActionButton) {
423427
note =
424428
'<h3>Allow use of current location, if prompted</h3>';
425429

426-
contentEl.innerHTML = values_info + location_div + latitude + longitude + altitude + accuracy + heading + speed
427-
+ altitude_accuracy + time + note + actions;
430+
contentEl.innerHTML = values_info + location_div + latitude + longitude + altitude + accuracy + heading + speed +
431+
altitude_accuracy + time + note + actions;
428432

429433
createActionButton('Get Location', function () {
430434
getLocation();

www/android/geolocation.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@
1919
*
2020
*/
2121

22-
2322
var exec = cordova.require('cordova/exec');
2423
var utils = require('cordova/utils');
2524
var PositionError = require('./PositionError');
2625

27-
module.exports = {
26+
// Native watchPosition method is called async after permissions prompt.
27+
// So we use additional map and own ids to return watch id synchronously.
28+
var pluginToNativeWatchMap = {};
2829

30+
module.exports = {
2931
getCurrentPosition: function(success, error, args) {
3032
var win = function() {
3133
var geo = cordova.require('cordova/modulemapper').getOriginalSymbol(window, 'navigator.geolocation');
@@ -67,7 +69,3 @@ module.exports = {
6769
exec(win, null, "Geolocation", "getPermission", []);
6870
}
6971
};
70-
71-
// Native watchPosition method is called async after permissions prompt.
72-
// So we use additional map and own ids to return watch id synchronously.
73-
var pluginToNativeWatchMap = {};

0 commit comments

Comments
 (0)