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 = '
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] | ' + - '
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] | ' + + '