diff --git a/.eslintrc.yml b/.eslintrc.yml index 0cccb8c7..17277f7f 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 24d53c29..854b1044 100644 --- a/package.json +++ b/package.json @@ -26,8 +26,8 @@ "cordova-windows" ], "scripts": { - "test": "npm run eslint", - "eslint": "node node_modules/eslint/bin/eslint www && node node_modules/eslint/bin/eslint src && node node_modules/eslint/bin/eslint tests" + "test": "npm run lint", + "lint": "eslint ." }, "author": "Apache Software Foundation", "license": "Apache-2.0", @@ -42,12 +42,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/windows/GeolocationProxy.js b/src/windows/GeolocationProxy.js index f792b912..e60d058b 100644 --- a/src/windows/GeolocationProxy.js +++ b/src/windows/GeolocationProxy.js @@ -14,7 +14,7 @@ * limitations under the License. */ -/* global Windows, WinJS */ +/* global cordova, Windows, WinJS */ var PositionError = require('./PositionError'); var callbacks = {}; @@ -50,13 +50,13 @@ function createErrorCode (loc) { /* eslint-disable no-fallthrough */ switch (loc.locationStatus) { case Windows.Devices.Geolocation.PositionStatus.initializing: - // This status indicates that a location device is still initializing + // This status indicates that a location device is still initializing case Windows.Devices.Geolocation.PositionStatus.noData: - // No location data is currently available + // No location data is currently available case Windows.Devices.Geolocation.PositionStatus.notInitialized: - // This status indicates that the app has not yet requested - // location data by calling GetGeolocationAsync() or - // registering an event handler for the positionChanged event. + // This status indicates that the app has not yet requested + // location data by calling GetGeolocationAsync() or + // registering an event handler for the positionChanged event. case Windows.Devices.Geolocation.PositionStatus.notAvailable: // Location is not available on this version of Windows return PositionError.POSITION_UNAVAILABLE; @@ -84,7 +84,8 @@ function createResult (pos) { res.latitude = pos.coordinate.point.position.latitude; res.longitude = pos.coordinate.point.position.longitude; res.altitude = pos.coordinate.point.position.altitude; - } else { // compatibility with old windows8.0 api + } else { + // compatibility with old windows8.0 api res.latitude = pos.coordinate.latitude; res.longitude = pos.coordinate.longitude; res.altitude = pos.coordinate.altitude; @@ -100,9 +101,9 @@ module.exports = { var highAccuracy = args[0]; var maxAge = args[1]; - loc.desiredAccuracy = highAccuracy ? - Windows.Devices.Geolocation.PositionAccuracy.high : - Windows.Devices.Geolocation.PositionAccuracy.default; + loc.desiredAccuracy = highAccuracy + ? Windows.Devices.Geolocation.PositionAccuracy.high + : Windows.Devices.Geolocation.PositionAccuracy.default; loc.reportInterval = maxAge || 0; @@ -141,7 +142,8 @@ module.exports = { case Windows.Devices.Geolocation.PositionStatus.notAvailable: fail({ code: PositionError.POSITION_UNAVAILABLE, - message: 'Data from location services is currently unavailable or you do not have the required location services present on your system.' + message: + 'Data from location services is currently unavailable or you do not have the required location services present on your system.' }); break; @@ -159,11 +161,12 @@ module.exports = { } }; - loc.desiredAccuracy = highAccuracy ? - Windows.Devices.Geolocation.PositionAccuracy.high : - Windows.Devices.Geolocation.PositionAccuracy.default; + loc.desiredAccuracy = highAccuracy + ? Windows.Devices.Geolocation.PositionAccuracy.high + : Windows.Devices.Geolocation.PositionAccuracy.default; - if (cordova.platformId === 'windows') { // eslint-disable-line no-undef + if (cordova.platformId === 'windows') { + // eslint-disable-line no-undef // 'positionchanged' event fails with error below if movementThreshold is not set // JavaScript runtime error: Operation aborted // You must set the MovementThreshold property or the ReportInterval property before adding event handlers. diff --git a/tests/tests.js b/tests/tests.js index cf3a5ab5..f6d12506 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -17,9 +17,8 @@ * specific language governing permissions and limitations * under the License. * -*/ + */ -/* eslint-env jasmine */ /* global WinJS, device */ exports.defineAutoTests = function () { @@ -60,7 +59,7 @@ exports.defineAutoTests = function () { }; // On Windows, some tests prompt user for permission to use geolocation and interrupt autotests run - var isWindowsStore = (cordova.platformId === 'windows8') || (cordova.platformId === 'windows' && !WinJS.Utilities.isPhone); // eslint-disable-line no-undef + var isWindowsStore = cordova.platformId === 'windows8' || (cordova.platformId === 'windows' && !WinJS.Utilities.isPhone); // eslint-disable-line no-undef var majorDeviceVersion = null; var versionRegex = /(\d)\..+/.exec(device.version); if (versionRegex !== null) { @@ -72,7 +71,6 @@ exports.defineAutoTests = function () { var isIOSSim = false; // if iOS simulator does not have a location set, it will fail. describe('Geolocation (navigator.geolocation)', function () { - it('geolocation.spec.1 should exist', function () { expect(navigator.geolocation).toBeDefined(); }); @@ -91,25 +89,19 @@ exports.defineAutoTests = function () { expect(typeof navigator.geolocation.clearWatch).toBeDefined(); expect(typeof navigator.geolocation.clearWatch === 'function').toBe(true); }); - }); describe('getCurrentPosition method', function () { - describe('error callback', function () { - it('geolocation.spec.5 should be called if we set timeout to 0 and maximumAge to a very small number', function (done) { if (isWindowsStore || skipAndroid) { pending(); } - navigator.geolocation.getCurrentPosition( - fail.bind(null, done), - succeed.bind(null, done), - { - maximumAge: 0, - timeout: 0 - }); + navigator.geolocation.getCurrentPosition(fail.bind(null, done), succeed.bind(null, done), { + maximumAge: 0, + timeout: 0 + }); }); it('geolocation.spec.9 on failure should return PositionError object with error code constants', function (done) { @@ -129,42 +121,42 @@ exports.defineAutoTests = function () { { maximumAge: 0, timeout: 0 - }); + } + ); }); - }); describe('success callback', function () { - it('geolocation.spec.6 should be called with a Position object', function (done) { if (isWindowsStore || skipAndroid) { pending(); } - navigator.geolocation.getCurrentPosition(function (p) { - expect(p.coords).toBeDefined(); - expect(p.timestamp).toBeDefined(); - done(); - }, function (err) { - if (err.message && err.message.indexOf('kCLErrorDomain') > -1) { - console.log('Error: Location not set in simulator, tests will fail.'); - expect(true).toBe(true); - isIOSSim = true; + navigator.geolocation.getCurrentPosition( + function (p) { + expect(p.coords).toBeDefined(); + expect(p.timestamp).toBeDefined(); done(); - } else { - fail(done); + }, + function (err) { + if (err.message && err.message.indexOf('kCLErrorDomain') > -1) { + console.log('Error: Location not set in simulator, tests will fail.'); + expect(true).toBe(true); + isIOSSim = true; + done(); + } else { + fail(done); + } + }, + { + maximumAge: 5 * 60 * 1000 // 5 minutes maximum age of cached position } - }, - { - maximumAge: (5 * 60 * 1000) // 5 minutes maximum age of cached position - }); + ); }, 25000); // first geolocation call can take several seconds on some devices }); - }); describe('watchPosition method', function () { - beforeEach(function (done) { // This timeout is set to lessen the load on platform's geolocation services // which were causing occasional test failures @@ -174,7 +166,6 @@ exports.defineAutoTests = function () { }); describe('error callback', function () { - var errorWatch = null; afterEach(function () { navigator.geolocation.clearWatch(errorWatch); @@ -192,7 +183,8 @@ exports.defineAutoTests = function () { { maximumAge: 0, timeout: 0 - }); + } + ); }); it('geolocation.spec.10 on failure should return PositionError object with error code constants', function (done) { @@ -217,13 +209,12 @@ exports.defineAutoTests = function () { { maximumAge: 0, timeout: 0 - }); + } + ); }); - }); describe('success callback', function () { - var successWatch = null; afterEach(function () { navigator.geolocation.clearWatch(successWatch); @@ -250,15 +241,13 @@ exports.defineAutoTests = function () { }, fail.bind(null, done, context, 'Unexpected fail callback'), { - maximumAge: (5 * 60 * 1000) // 5 minutes maximum age of cached position - }); + maximumAge: 5 * 60 * 1000 // 5 minutes maximum age of cached position + } + ); expect(successWatch).toBeDefined(); }); - }); - }); - }; /******************************************************************************/ @@ -275,7 +264,7 @@ exports.defineManualTests = function (contentEl, createActionButton) { document.getElementById('location_status').innerHTML = status; } function setLocationDetails (p) { - var date = (new Date(p.timestamp)); + var date = new Date(p.timestamp); document.getElementById('latitude').innerHTML = p.coords.latitude; document.getElementById('longitude').innerHTML = p.coords.longitude; document.getElementById('altitude').innerHTML = p.coords.altitude; @@ -357,90 +346,120 @@ exports.defineManualTests = function (contentEl, createActionButton) { // Get location geo.getCurrentPosition(success, fail, opts || { enableHighAccuracy: true }); //, {timeout: 10000}); - }; /******************************************************************************/ - var location_div = '
' + - 'Status: Stopped' + - ''; - var latitude = '' + - '' + - '' + - '' + - ''; - var longitude = '' + - '' + - '' + - '' + - ''; - var altitude = '' + - '' + - '' + - '' + - ''; - var accuracy = '' + - '' + - '' + - '' + - ''; - var heading = '' + - '' + - '' + - '' + - ''; - var speed = '' + - '' + - '' + - '' + - ''; - var altitude_accuracy = '' + - '' + - '' + - '' + - ''; - var time = '' + - '' + - '' + - '' + - '' + - '
Latitude: (decimal degrees) geographic coordinate [#ref]
Longitude: (decimal degrees) geographic coordinate [#ref]
Altitude: null if not supported;
' + - '(meters) height above the [WGS84] ellipsoid. [#ref]
Accuracy: (meters; non-negative; 95% confidence level) the accuracy level of the latitude and longitude coordinates. [#ref]
Heading: null if not supported;
' + - 'NaN if speed == 0;
' + - '(degrees; 0° ≤ heading < 360°) direction of travel of the hosting device- counting clockwise relative to the true north. [#ref]
Speed: null if not supported;
' + - '(meters per second; non-negative) magnitude of the horizontal component of the hosting device current velocity. [#ref]
Altitude Accuracy: null if not supported;
(meters; non-negative; 95% confidence level) the accuracy level of the altitude. [#ref]
Time: (DOMTimeStamp) when the position was acquired [#ref]
' + - '
'; + var location_div = '
' + 'Status: Stopped' + ''; + var latitude = + '' + + '' + + '' + + '' + + ''; + var longitude = + '' + + '' + + '' + + '' + + ''; + var altitude = + '' + + '' + + '' + + '' + + ''; + var accuracy = + '' + + '' + + '' + + '' + + ''; + var heading = + '' + + '' + + '' + + '' + + ''; + var speed = + '' + + '' + + '' + + '' + + ''; + var altitude_accuracy = + '' + + '' + + '' + + '' + + ''; + var time = + '' + + '' + + '' + + '' + + '' + + '
Latitude: (decimal degrees) geographic coordinate [#ref]
Longitude: (decimal degrees) geographic coordinate [#ref]
Altitude: null if not supported;
' + + '(meters) height above the [WGS84] ellipsoid. [#ref]
Accuracy: (meters; non-negative; 95% confidence level) the accuracy level of the latitude and longitude coordinates. [#ref]
Heading: null if not supported;
' + + 'NaN if speed == 0;
' + + '(degrees; 0° ≤ heading < 360°) direction of travel of the hosting device- counting clockwise relative to the true north. [#ref]
Speed: null if not supported;
' + + '(meters per second; non-negative) magnitude of the horizontal component of the hosting device current velocity. [#ref]
Altitude Accuracy: null if not supported;
(meters; non-negative; 95% confidence level) the accuracy level of the altitude. [#ref]
Time: (DOMTimeStamp) when the position was acquired [#ref]
' + + '
'; var actions = - '
' + - 'Expected result: Will update all applicable values in status box for current location. Status will read Retrieving Location (may not see this if location is retrieved immediately) then Done.' + - '

' + - 'Expected result: Will update all applicable values in status box for current location and update as location changes. Status will read Running.' + - '

' + - 'Expected result: Will stop watching the location so values will not be updated. Status will read Stopped.' + - '

' + - 'Expected result: Will update location values with a cached position that is up to 30 seconds old. Verify with time value. Status will read Done.'; - var values_info = - '

Details about each value are listed below in the status box

'; - var note = - '

Allow use of current location, if prompted

'; - - contentEl.innerHTML = values_info + location_div + latitude + longitude + altitude + accuracy + heading + speed + - altitude_accuracy + time + note + actions; - - createActionButton('Get Location', function () { - getLocation(); - }, 'cordova-getLocation'); - - createActionButton('Start Watching Location', function () { - watchLocation(); - }, 'cordova-watchLocation'); - - createActionButton('Stop Watching Location', function () { - stopLocation(); - }, 'cordova-stopLocation'); - - createActionButton('Get Location Up to 30 Sec Old', function () { - getLocation({ maximumAge: 30000 }); - }, 'cordova-getOld'); + '
' + + 'Expected result: Will update all applicable values in status box for current location. Status will read Retrieving Location (may not see this if location is retrieved immediately) then Done.' + + '

' + + 'Expected result: Will update all applicable values in status box for current location and update as location changes. Status will read Running.' + + '

' + + 'Expected result: Will stop watching the location so values will not be updated. Status will read Stopped.' + + '

' + + 'Expected result: Will update location values with a cached position that is up to 30 seconds old. Verify with time value. Status will read Done.'; + var values_info = '

Details about each value are listed below in the status box

'; + var note = '

Allow use of current location, if prompted

'; + + contentEl.innerHTML = + values_info + + location_div + + latitude + + longitude + + altitude + + accuracy + + heading + + speed + + altitude_accuracy + + time + + note + + actions; + + createActionButton( + 'Get Location', + function () { + getLocation(); + }, + 'cordova-getLocation' + ); + + createActionButton( + 'Start Watching Location', + function () { + watchLocation(); + }, + 'cordova-watchLocation' + ); + + createActionButton( + 'Stop Watching Location', + function () { + stopLocation(); + }, + 'cordova-stopLocation' + ); + + createActionButton( + 'Get Location Up to 30 Sec Old', + function () { + getLocation({ maximumAge: 30000 }); + }, + 'cordova-getOld' + ); }; diff --git a/www/Coordinates.js b/www/Coordinates.js index 1d7e8794..c98a0692 100644 --- a/www/Coordinates.js +++ b/www/Coordinates.js @@ -17,7 +17,7 @@ * specific language governing permissions and limitations * under the License. * -*/ + */ /** * This class contains position information. @@ -46,15 +46,15 @@ var Coordinates = function (lat, lng, alt, acc, head, vel, altacc) { /** * The altitude of the position. */ - this.altitude = (alt !== undefined ? alt : null); + this.altitude = alt !== undefined ? alt : null; /** * The direction the device is moving at the position. */ - this.heading = (head !== undefined ? head : null); + this.heading = head !== undefined ? head : null; /** * The velocity with which the device is moving at the position. */ - this.speed = (vel !== undefined ? vel : null); + this.speed = vel !== undefined ? vel : null; if (this.speed === 0 || this.speed === null) { this.heading = NaN; @@ -63,7 +63,7 @@ var Coordinates = function (lat, lng, alt, acc, head, vel, altacc) { /** * The altitude accuracy of the position. */ - this.altitudeAccuracy = (altacc !== undefined) ? altacc : null; + this.altitudeAccuracy = altacc !== undefined ? altacc : null; }; module.exports = Coordinates; diff --git a/www/Position.js b/www/Position.js index b4f20e07..2015f59b 100644 --- a/www/Position.js +++ b/www/Position.js @@ -17,17 +17,25 @@ * specific language governing permissions and limitations * under the License. * -*/ + */ var Coordinates = require('./Coordinates'); var Position = function (coords, timestamp) { if (coords) { - this.coords = new Coordinates(coords.latitude, coords.longitude, coords.altitude, coords.accuracy, coords.heading, coords.velocity, coords.altitudeAccuracy); + this.coords = new Coordinates( + coords.latitude, + coords.longitude, + coords.altitude, + coords.accuracy, + coords.heading, + coords.velocity, + coords.altitudeAccuracy + ); } else { this.coords = new Coordinates(); } - this.timestamp = (timestamp !== undefined) ? timestamp : new Date().getTime(); + this.timestamp = timestamp !== undefined ? timestamp : new Date().getTime(); }; module.exports = Position; diff --git a/www/PositionError.js b/www/PositionError.js index 476b322a..d7b70816 100644 --- a/www/PositionError.js +++ b/www/PositionError.js @@ -17,7 +17,7 @@ * specific language governing permissions and limitations * under the License. * -*/ + */ /** * Position error object diff --git a/www/android/geolocation.js b/www/android/geolocation.js index 54005545..c02940bb 100644 --- a/www/android/geolocation.js +++ b/www/android/geolocation.js @@ -17,7 +17,7 @@ * specific language governing permissions and limitations * under the License. * -*/ + */ var exec = cordova.require('cordova/exec'); // eslint-disable-line no-undef var utils = require('cordova/utils'); diff --git a/www/geolocation.js b/www/geolocation.js index c6c57884..ef4579c0 100644 --- a/www/geolocation.js +++ b/www/geolocation.js @@ -17,7 +17,7 @@ * specific language governing permissions and limitations * under the License. * -*/ + */ var argscheck = require('cordova/argscheck'); var utils = require('cordova/utils'); @@ -70,23 +70,23 @@ function createTimeout (errorCallback, timeout) { var geolocation = { lastPosition: null, // reference to last known (cached) position returned /** - * Asynchronously acquires the current position. - * - * @param {Function} successCallback The function to call when the position data is available - * @param {Function} errorCallback The function to call when there is an error getting the heading position. (OPTIONAL) - * @param {PositionOptions} options The options for getting the position data. (OPTIONAL) - */ + * Asynchronously acquires the current position. + * + * @param {Function} successCallback The function to call when the position data is available + * @param {Function} errorCallback The function to call when there is an error getting the heading position. (OPTIONAL) + * @param {PositionOptions} options The options for getting the position data. (OPTIONAL) + */ getCurrentPosition: function (successCallback, errorCallback, options) { argscheck.checkArgs('fFO', 'geolocation.getCurrentPosition', arguments); options = parseParameters(options); // Timer var that will fire an error callback if no position is retrieved from native // before the "timeout" param provided expires - var timeoutTimer = {timer: null}; + var timeoutTimer = { timer: null }; var win = function (p) { clearTimeout(timeoutTimer.timer); - if (!(timeoutTimer.timer)) { + if (!timeoutTimer.timer) { // Timeout already happened, or native fired error callback for // this geo request. // Don't continue with success callback. @@ -118,15 +118,20 @@ var geolocation = { // Check our cached position, if its timestamp difference with current time is less than the maximumAge, then just // fire the success callback with the cached position. - if (geolocation.lastPosition && options.maximumAge && (((new Date()).getTime() - geolocation.lastPosition.timestamp) <= options.maximumAge)) { + if ( + geolocation.lastPosition && + options.maximumAge && + new Date().getTime() - geolocation.lastPosition.timestamp <= options.maximumAge + ) { successCallback(geolocation.lastPosition); - // If the cached position check failed and the timeout was set to 0, error out with a TIMEOUT error object. + // If the cached position check failed and the timeout was set to 0, error out with a TIMEOUT error object. } else if (options.timeout === 0) { fail({ code: PositionError.TIMEOUT, - message: "timeout value in PositionOptions set to 0 and no cached Position object available, or cached Position object's age exceeds provided PositionOptions' maximumAge parameter." + message: + "timeout value in PositionOptions set to 0 and no cached Position object available, or cached Position object's age exceeds provided PositionOptions' maximumAge parameter." }); - // Otherwise we have to call into native to retrieve a position. + // Otherwise we have to call into native to retrieve a position. } else { if (options.timeout !== Infinity) { // If the timeout value was not set to Infinity (default), then