diff --git a/.eslintrc.json b/.eslintrc.json index 5559ce5b6e87..2e121a0888e4 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,6 +1,7 @@ { "extends": "./Tools/eslint-config-cesium/browser.js", "rules": { + "no-else-return": "error", "no-unused-vars": ["error", {"vars": "all", "args": "none"}] } } diff --git a/Apps/Sandcastle/Sandcastle-client.js b/Apps/Sandcastle/Sandcastle-client.js index 326d7f816e3c..72a97b627919 100644 --- a/Apps/Sandcastle/Sandcastle-client.js +++ b/Apps/Sandcastle/Sandcastle-client.js @@ -13,9 +13,8 @@ return 'null'; } else if (defined(value)) { return value.toString(); - } else { - return 'undefined'; } + return 'undefined'; } console.originalLog = console.log; diff --git a/Source/Core/CesiumTerrainProvider.js b/Source/Core/CesiumTerrainProvider.js index 11fb68504de8..8a54460e8b81 100644 --- a/Source/Core/CesiumTerrainProvider.js +++ b/Source/Core/CesiumTerrainProvider.js @@ -304,12 +304,11 @@ define([ return { Accept : 'application/vnd.quantized-mesh,application/octet-stream;q=0.9,*/*;q=0.01' }; - } else { - var extensions = extensionsList.join('-'); - return { - Accept : 'application/vnd.quantized-mesh;extensions=' + extensions + ',application/octet-stream;q=0.9,*/*;q=0.01' - }; } + var extensions = extensionsList.join('-'); + return { + Accept : 'application/vnd.quantized-mesh;extensions=' + extensions + ',application/octet-stream;q=0.9,*/*;q=0.01' + }; } function createHeightmapTerrainData(provider, buffer, level, x, y, tmsY) { @@ -552,9 +551,8 @@ define([ return when(promise, function(buffer) { if (defined(that._heightmapStructure)) { return createHeightmapTerrainData(that, buffer, level, x, y, tmsY); - } else { - return createQuantizedMeshTerrainData(that, buffer, level, x, y, tmsY); } + return createQuantizedMeshTerrainData(that, buffer, level, x, y, tmsY); }); }; diff --git a/Source/Core/IntersectionTests.js b/Source/Core/IntersectionTests.js index 3bde8428fed3..495dd1bcb7b8 100644 --- a/Source/Core/IntersectionTests.js +++ b/Source/Core/IntersectionTests.js @@ -449,11 +449,10 @@ define([ start : root1, stop : root0 }; - } else { - // qw2 == product. Repeated roots (2 intersections). - var root = Math.sqrt(difference / w2); - return new Interval(root, root); } + // qw2 == product. Repeated roots (2 intersections). + var root = Math.sqrt(difference / w2); + return new Interval(root, root); } else if (q2 < 1.0) { // Inside ellipsoid (2 intersections). difference = q2 - 1.0; // Negatively valued. @@ -463,17 +462,16 @@ define([ discriminant = qw * qw - product; temp = -qw + Math.sqrt(discriminant); // Positively valued. return new Interval(0.0, temp / w2); - } else { - // q2 == 1.0. On ellipsoid. - if (qw < 0.0) { - // Looking inward. - w2 = Cartesian3.magnitudeSquared(w); - return new Interval(0.0, -qw / w2); - } - - // qw >= 0.0. Looking outward or tangent. - return undefined; } + // q2 == 1.0. On ellipsoid. + if (qw < 0.0) { + // Looking inward. + w2 = Cartesian3.magnitudeSquared(w); + return new Interval(0.0, -qw / w2); + } + + // qw >= 0.0. Looking outward or tangent. + return undefined; }; function addWithCancellationCheck(left, right, tolerance) { diff --git a/Source/Core/Intersections2D.js b/Source/Core/Intersections2D.js index 8da31a274455..1ad68bd56f8e 100644 --- a/Source/Core/Intersections2D.js +++ b/Source/Core/Intersections2D.js @@ -275,9 +275,8 @@ define([ result.y = l2; result.z = l3; return result; - } else { - return new Cartesian3(l1, l2, l3); } + return new Cartesian3(l1, l2, l3); }; return Intersections2D; diff --git a/Source/Core/Plane.js b/Source/Core/Plane.js index bd0137ea3a49..1b659c7118b0 100644 --- a/Source/Core/Plane.js +++ b/Source/Core/Plane.js @@ -137,11 +137,10 @@ define([ if (!defined(result)) { return new Plane(normal, distance); - } else { - Cartesian3.clone(normal, result.normal); - result.distance = distance; - return result; } + Cartesian3.clone(normal, result.normal); + result.distance = distance; + return result; }; /** diff --git a/Source/Core/QuantizedMeshTerrainData.js b/Source/Core/QuantizedMeshTerrainData.js index 814375cf595f..8459fe4e6776 100644 --- a/Source/Core/QuantizedMeshTerrainData.js +++ b/Source/Core/QuantizedMeshTerrainData.js @@ -239,9 +239,8 @@ define([ if (needsSort) { arrayScratch.sort(sortFunction); return IndexDatatype.createTypedArray(vertexCount, arrayScratch); - } else { - return indices; } + return indices; } var createMeshTaskProcessor = new TaskProcessor('createVerticesFromQuantizedTerrainMesh'); diff --git a/Source/Core/QuarticRealPolynomial.js b/Source/Core/QuarticRealPolynomial.js index 145d6856016f..704207eca111 100644 --- a/Source/Core/QuarticRealPolynomial.js +++ b/Source/Core/QuarticRealPolynomial.js @@ -231,9 +231,8 @@ define([ return [roots1[0], roots2[0], roots2[1], roots1[1]]; } else if (roots1[0] > roots2[0] && roots1[0] < roots2[1]) { return [roots2[0], roots1[0], roots2[1], roots1[1]]; - } else { - return [roots1[0], roots2[0], roots1[1], roots2[1]]; } + return [roots1[0], roots2[0], roots1[1], roots2[1]]; } return roots1; } diff --git a/Source/Core/Simon1994PlanetaryPositions.js b/Source/Core/Simon1994PlanetaryPositions.js index 1a824012333e..3962010540c2 100644 --- a/Source/Core/Simon1994PlanetaryPositions.js +++ b/Source/Core/Simon1994PlanetaryPositions.js @@ -135,9 +135,8 @@ define([ return 'Elliptical'; } else if (eccentricity <= 1.0 + tolerance) { return 'Parabolic'; - } else { - return 'Hyperbolic'; } + return 'Hyperbolic'; } // Calculates the true anomaly given the mean anomaly and the eccentricity. diff --git a/Source/Core/TerrainEncoding.js b/Source/Core/TerrainEncoding.js index 9b91b0f1c9e9..744ba8fdad65 100644 --- a/Source/Core/TerrainEncoding.js +++ b/Source/Core/TerrainEncoding.js @@ -354,22 +354,20 @@ define([ offsetInBytes : numCompressed0 * sizeInBytes, strideInBytes : stride }]; - } else { - return [{ - index : attributes.compressed0, - vertexBuffer : buffer, - componentDatatype : datatype, - componentsPerAttribute : numCompressed0 - }]; } + return [{ + index : attributes.compressed0, + vertexBuffer : buffer, + componentDatatype : datatype, + componentsPerAttribute : numCompressed0 + }]; }; TerrainEncoding.prototype.getAttributeLocations = function() { if (this.quantization === TerrainQuantization.NONE) { return attributesNone; - } else { - return attributes; } + return attributes; }; TerrainEncoding.clone = function(encoding, result) { diff --git a/Source/DataSources/CzmlDataSource.js b/Source/DataSources/CzmlDataSource.js index b112d58c780a..022c16967fd8 100644 --- a/Source/DataSources/CzmlDataSource.js +++ b/Source/DataSources/CzmlDataSource.js @@ -265,21 +265,21 @@ define([ scratchSpherical.cone = unitSpherical[1]; Cartesian3.fromSpherical(scratchSpherical, scratchCartesian); return [scratchCartesian.x, scratchCartesian.y, scratchCartesian.z]; - } else { - var result = new Array(length / 3 * 4); - for (var i = 0, j = 0; i < length; i += 3, j += 4) { - result[j] = unitSpherical[i]; + } - scratchSpherical.clock = unitSpherical[i + 1]; - scratchSpherical.cone = unitSpherical[i + 2]; - Cartesian3.fromSpherical(scratchSpherical, scratchCartesian); + var result = new Array(length / 3 * 4); + for (var i = 0, j = 0; i < length; i += 3, j += 4) { + result[j] = unitSpherical[i]; - result[j + 1] = scratchCartesian.x; - result[j + 2] = scratchCartesian.y; - result[j + 3] = scratchCartesian.z; - } - return result; + scratchSpherical.clock = unitSpherical[i + 1]; + scratchSpherical.cone = unitSpherical[i + 2]; + Cartesian3.fromSpherical(scratchSpherical, scratchCartesian); + + result[j + 1] = scratchCartesian.x; + result[j + 2] = scratchCartesian.y; + result[j + 3] = scratchCartesian.z; } + return result; } function convertSphericalToCartesian(spherical) { @@ -290,22 +290,22 @@ define([ scratchSpherical.magnitude = spherical[2]; Cartesian3.fromSpherical(scratchSpherical, scratchCartesian); return [scratchCartesian.x, scratchCartesian.y, scratchCartesian.z]; - } else { - var result = new Array(length); - for (var i = 0; i < length; i += 4) { - result[i] = spherical[i]; - - scratchSpherical.clock = spherical[i + 1]; - scratchSpherical.cone = spherical[i + 2]; - scratchSpherical.magnitude = spherical[i + 3]; - Cartesian3.fromSpherical(scratchSpherical, scratchCartesian); - - result[i + 1] = scratchCartesian.x; - result[i + 2] = scratchCartesian.y; - result[i + 3] = scratchCartesian.z; - } - return result; } + + var result = new Array(length); + for (var i = 0; i < length; i += 4) { + result[i] = spherical[i]; + + scratchSpherical.clock = spherical[i + 1]; + scratchSpherical.cone = spherical[i + 2]; + scratchSpherical.magnitude = spherical[i + 3]; + Cartesian3.fromSpherical(scratchSpherical, scratchCartesian); + + result[i + 1] = scratchCartesian.x; + result[i + 2] = scratchCartesian.y; + result[i + 3] = scratchCartesian.z; + } + return result; } function convertCartographicRadiansToCartesian(cartographicRadians) { @@ -316,22 +316,22 @@ define([ scratchCartographic.height = cartographicRadians[2]; Ellipsoid.WGS84.cartographicToCartesian(scratchCartographic, scratchCartesian); return [scratchCartesian.x, scratchCartesian.y, scratchCartesian.z]; - } else { - var result = new Array(length); - for (var i = 0; i < length; i += 4) { - result[i] = cartographicRadians[i]; - - scratchCartographic.longitude = cartographicRadians[i + 1]; - scratchCartographic.latitude = cartographicRadians[i + 2]; - scratchCartographic.height = cartographicRadians[i + 3]; - Ellipsoid.WGS84.cartographicToCartesian(scratchCartographic, scratchCartesian); - - result[i + 1] = scratchCartesian.x; - result[i + 2] = scratchCartesian.y; - result[i + 3] = scratchCartesian.z; - } - return result; } + + var result = new Array(length); + for (var i = 0; i < length; i += 4) { + result[i] = cartographicRadians[i]; + + scratchCartographic.longitude = cartographicRadians[i + 1]; + scratchCartographic.latitude = cartographicRadians[i + 2]; + scratchCartographic.height = cartographicRadians[i + 3]; + Ellipsoid.WGS84.cartographicToCartesian(scratchCartographic, scratchCartesian); + + result[i + 1] = scratchCartesian.x; + result[i + 2] = scratchCartesian.y; + result[i + 3] = scratchCartesian.z; + } + return result; } function convertCartographicDegreesToCartesian(cartographicDegrees) { @@ -342,22 +342,22 @@ define([ scratchCartographic.height = cartographicDegrees[2]; Ellipsoid.WGS84.cartographicToCartesian(scratchCartographic, scratchCartesian); return [scratchCartesian.x, scratchCartesian.y, scratchCartesian.z]; - } else { - var result = new Array(length); - for (var i = 0; i < length; i += 4) { - result[i] = cartographicDegrees[i]; - - scratchCartographic.longitude = CesiumMath.toRadians(cartographicDegrees[i + 1]); - scratchCartographic.latitude = CesiumMath.toRadians(cartographicDegrees[i + 2]); - scratchCartographic.height = cartographicDegrees[i + 3]; - Ellipsoid.WGS84.cartographicToCartesian(scratchCartographic, scratchCartesian); - - result[i + 1] = scratchCartesian.x; - result[i + 2] = scratchCartesian.y; - result[i + 3] = scratchCartesian.z; - } - return result; } + + var result = new Array(length); + for (var i = 0; i < length; i += 4) { + result[i] = cartographicDegrees[i]; + + scratchCartographic.longitude = CesiumMath.toRadians(cartographicDegrees[i + 1]); + scratchCartographic.latitude = CesiumMath.toRadians(cartographicDegrees[i + 2]); + scratchCartographic.height = cartographicDegrees[i + 3]; + Ellipsoid.WGS84.cartographicToCartesian(scratchCartographic, scratchCartesian); + + result[i + 1] = scratchCartesian.x; + result[i + 2] = scratchCartesian.y; + result[i + 3] = scratchCartesian.z; + } + return result; } function unwrapCartesianInterval(czmlInterval) { @@ -496,10 +496,9 @@ define([ return Uri; } else if (czmlInterval.hasOwnProperty('verticalOrigin')) { return VerticalOrigin; - } else { - // fallback case - return Object; } + // fallback case + return Object; } function unwrapInterval(type, czmlInterval, sourceUri, query) { diff --git a/Source/DataSources/KmlDataSource.js b/Source/DataSources/KmlDataSource.js index 766674a9e4e0..51d8158c4b04 100644 --- a/Source/DataSources/KmlDataSource.js +++ b/Source/DataSources/KmlDataSource.js @@ -2239,9 +2239,8 @@ define([ return loadKml(dataSource, entityCollection, kml, sourceUri, uriResolver, context, query); }); }); - } else { - return loadKml(dataSource, entityCollection, dataToLoad, sourceUri, uriResolver, context, query); } + return loadKml(dataSource, entityCollection, dataToLoad, sourceUri, uriResolver, context, query); }) .otherwise(function(error) { dataSource._error.raiseEvent(dataSource, error); diff --git a/Source/DataSources/VelocityVectorProperty.js b/Source/DataSources/VelocityVectorProperty.js index 9b88f8856517..456e2651a308 100644 --- a/Source/DataSources/VelocityVectorProperty.js +++ b/Source/DataSources/VelocityVectorProperty.js @@ -190,9 +190,9 @@ define([ var velocity = Cartesian3.subtract(position2, position1, velocityResult); if (this._normalize) { return Cartesian3.normalize(velocity, velocityResult); - } else { - return Cartesian3.divideByScalar(velocity, step, velocityResult); } + + return Cartesian3.divideByScalar(velocity, step, velocityResult); }; /** diff --git a/Source/Scene/GoogleEarthEnterpriseImageryProvider.js b/Source/Scene/GoogleEarthEnterpriseImageryProvider.js index 3dfb87bbcf20..de89b45a60ed 100644 --- a/Source/Scene/GoogleEarthEnterpriseImageryProvider.js +++ b/Source/Scene/GoogleEarthEnterpriseImageryProvider.js @@ -461,9 +461,8 @@ define([ }); metadata.populateSubtree(x, y, level, metadataRequest); return undefined; // No metadata so return undefined so we can be loaded later - } else { - return invalidImage; // Image doesn't exist } + return invalidImage; // Image doesn't exist } if (!info.hasImagery()) { diff --git a/Source/Scene/ScreenSpaceCameraController.js b/Source/Scene/ScreenSpaceCameraController.js index 4ca74be1eef8..ef5001e79d15 100644 --- a/Source/Scene/ScreenSpaceCameraController.js +++ b/Source/Scene/ScreenSpaceCameraController.js @@ -1334,11 +1334,10 @@ define([ pan3D(controller, startPosition, movement, ellipsoid); } return; - } else { - controller._looking = false; - controller._rotating = false; - controller._strafing = false; } + controller._looking = false; + controller._rotating = false; + controller._strafing = false; if (defined(globe) && height < controller._minimumPickingTerrainHeight) { if (defined(mousePos)) { diff --git a/Source/Scene/ShadowMode.js b/Source/Scene/ShadowMode.js index 68983ad7febd..d2a837485af9 100644 --- a/Source/Scene/ShadowMode.js +++ b/Source/Scene/ShadowMode.js @@ -74,9 +74,8 @@ define([ return ShadowMode.CAST_ONLY; } else if (receiveShadows) { return ShadowMode.RECEIVE_ONLY; - } else { - return ShadowMode.DISABLED; } + return ShadowMode.DISABLED; }; return freezeObject(ShadowMode); diff --git a/Source/Scene/TileImagery.js b/Source/Scene/TileImagery.js index d3ffdd839df3..256dadb9f7c8 100644 --- a/Source/Scene/TileImagery.js +++ b/Source/Scene/TileImagery.js @@ -94,10 +94,9 @@ define([ // we don't do it here. closestAncestorThatNeedsLoading.processStateMachine(frameState, !this.useWebMercatorT, tile._priorityFunction); return false; // not done loading - } else { - // This imagery tile is failed or invalid, and we have the "best available" substitute. - return true; // done loading } + // This imagery tile is failed or invalid, and we have the "best available" substitute. + return true; // done loading } return false; // not done loading diff --git a/Source/Scene/UrlTemplateImageryProvider.js b/Source/Scene/UrlTemplateImageryProvider.js index 6d1edf87cca8..7d88f60cdd90 100644 --- a/Source/Scene/UrlTemplateImageryProvider.js +++ b/Source/Scene/UrlTemplateImageryProvider.js @@ -667,12 +667,11 @@ define([ return loadXML(url).then(format.callback).otherwise(doRequest); } else if (format.type === 'text' || format.type === 'html') { return loadText(url).then(format.callback).otherwise(doRequest); - } else { - return loadWithXhr({ - url : url, - responseType : format.format - }).then(handleResponse.bind(undefined, format)).otherwise(doRequest); } + return loadWithXhr({ + url : url, + responseType : format.format + }).then(handleResponse.bind(undefined, format)).otherwise(doRequest); } return doRequest(); diff --git a/Specs/Core/OrientedBoundingBoxSpec.js b/Specs/Core/OrientedBoundingBoxSpec.js index 38f1a6855cb5..936939723b3e 100644 --- a/Specs/Core/OrientedBoundingBoxSpec.js +++ b/Specs/Core/OrientedBoundingBoxSpec.js @@ -343,9 +343,8 @@ defineSuite([ var d = -Cartesian3.dot(p0, n); if (Math.abs(d) > 0.0001 && Cartesian3.magnitudeSquared(n) > 0.0001) { return new Plane(n, d); - } else { - return undefined; } + return undefined; }; var pl; diff --git a/Specs/Scene/GlobeSurfaceTileSpec.js b/Specs/Scene/GlobeSurfaceTileSpec.js index 4268b3f602e2..6a9c75861187 100644 --- a/Specs/Scene/GlobeSurfaceTileSpec.js +++ b/Specs/Scene/GlobeSurfaceTileSpec.js @@ -444,10 +444,9 @@ defineSuite([ if (rootTile.state !== QuadtreeTileLoadState.DONE) { GlobeSurfaceTile.processStateMachine(rootTile, scene.frameState, allWaterTerrainProvider, imageryLayerCollection, []); return false; - } else { - GlobeSurfaceTile.processStateMachine(childTile, scene.frameState, allWaterTerrainProvider, imageryLayerCollection, []); - return childTile.state === QuadtreeTileLoadState.DONE; } + GlobeSurfaceTile.processStateMachine(childTile, scene.frameState, allWaterTerrainProvider, imageryLayerCollection, []); + return childTile.state === QuadtreeTileLoadState.DONE; }).then(function() { expect(childTile.data.waterMaskTexture).toBeDefined(); expect(childTile.data.waterMaskTexture).toBe(rootTile.data.waterMaskTexture); @@ -482,10 +481,9 @@ defineSuite([ if (rootTile.state !== QuadtreeTileLoadState.DONE) { GlobeSurfaceTile.processStateMachine(rootTile, scene.frameState, allLandTerrainProvider, imageryLayerCollection, []); return false; - } else { - GlobeSurfaceTile.processStateMachine(childTile, scene.frameState, allLandTerrainProvider, imageryLayerCollection, []); - return childTile.state === QuadtreeTileLoadState.DONE; } + GlobeSurfaceTile.processStateMachine(childTile, scene.frameState, allLandTerrainProvider, imageryLayerCollection, []); + return childTile.state === QuadtreeTileLoadState.DONE; }).then(function() { expect(childTile.data.waterMaskTexture).toBeUndefined(); }); diff --git a/Specs/Scene/ImageryLayerCollectionSpec.js b/Specs/Scene/ImageryLayerCollectionSpec.js index 7749c1f490ff..d3118a0d3d1e 100644 --- a/Specs/Scene/ImageryLayerCollectionSpec.js +++ b/Specs/Scene/ImageryLayerCollectionSpec.js @@ -544,9 +544,8 @@ defineSuite([ // At level 1, only the northwest quadrant has a valid tile. if (level !== 1 || (x === 0 && y === 0)) { return ImageryProvider.loadImage(this, 'Data/Images/Blue.png'); - } else { - return when.reject(); } + return when.reject(); } }; diff --git a/gulpfile.js b/gulpfile.js index 8bc4eb7ec651..83ecd5532079 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -774,9 +774,8 @@ gulp.task('sortRequires', function() { return -1; } else if (aName > bName) { return 1; - } else { - return 0; } + return 0; }); if (preserveFirst) { @@ -1149,9 +1148,8 @@ function createGalleryList() { return -1; } else if (a.name > b.name) { return 1; - } else { - return 0; } + return 0; }); var helloWorldIndex = Math.max(demoObjects.indexOf(helloWorld), 0);