Skip to content

Commit

Permalink
Enable eslint prefer-const rule
Browse files Browse the repository at this point in the history
Fixes were made manually.
  • Loading branch information
jfirebaugh committed Oct 17, 2016
1 parent a803520 commit 7e8cf5d
Show file tree
Hide file tree
Showing 45 changed files with 212 additions and 210 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"no-warning-comments": "error",
"object-curly-spacing": "off",
"prefer-arrow-callback": "error",
"prefer-const": "error",
"prefer-template": "error",
"quotes": "off",
"space-before-function-paren": "off",
Expand Down
10 changes: 5 additions & 5 deletions js/data/bucket/line_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ LineBucket.prototype.addLine = function(vertices, featureProperties, join, cap,

const sharpCornerOffset = SHARP_CORNER_OFFSET * (EXTENT / (512 * this.overscaling));

let firstVertex = vertices[0],
const firstVertex = vertices[0],
lastVertex = vertices[len - 1],
closed = firstVertex.equals(lastVertex);

Expand All @@ -135,10 +135,10 @@ LineBucket.prototype.addLine = function(vertices, featureProperties, join, cap,

this.distance = 0;

let beginCap = cap,
endCap = closed ? 'butt' : cap,
startOfLine = true,
currentVertex, prevVertex, nextVertex, prevNormal, nextNormal, offsetA, offsetB;
const beginCap = cap,
endCap = closed ? 'butt' : cap;
let startOfLine = true;
let currentVertex, prevVertex, nextVertex, prevNormal, nextNormal, offsetA, offsetB;

// the last three vertices added
this.e1 = this.e2 = this.e3 = -1;
Expand Down
26 changes: 13 additions & 13 deletions js/data/bucket/symbol_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ SymbolBucket.prototype.addFeature = function(lines, shapedText, shapedIcon, feat

const glyphSize = 24;

let fontScale = this.adjustedTextSize / glyphSize,
const fontScale = this.adjustedTextSize / glyphSize,
textMaxSize = this.adjustedTextMaxSize !== undefined ? this.adjustedTextMaxSize : this.adjustedTextSize,
textBoxScale = this.tilePixelRatio * fontScale,
textMaxBoxScale = this.tilePixelRatio * textMaxSize / glyphSize,
Expand Down Expand Up @@ -416,7 +416,7 @@ SymbolBucket.prototype.placeFeatures = function(collisionTile, showCollisionBoxe

const angle = collisionTile.angle;

let sin = Math.sin(angle),
const sin = Math.sin(angle),
cos = Math.cos(angle);

this.sortedSymbolInstances = symbolInstancesStructTypeArray.sort((a, b) => {
Expand All @@ -440,7 +440,7 @@ SymbolBucket.prototype.placeFeatures = function(collisionTile, showCollisionBoxe
const hasText = !(symbolInstance.textBoxStartIndex === symbolInstance.textBoxEndIndex);
const hasIcon = !(symbolInstance.iconBoxStartIndex === symbolInstance.iconBoxEndIndex);

let iconWithoutText = layout['text-optional'] || !hasText,
const iconWithoutText = layout['text-optional'] || !hasText,
textWithoutIcon = layout['icon-optional'] || !hasIcon;


Expand Down Expand Up @@ -507,15 +507,15 @@ SymbolBucket.prototype.addSymbols = function(programName, quadsStart, quadsEnd,
const a = (symbol.anchorAngle + placementAngle + Math.PI) % (Math.PI * 2);
if (keepUpright && alongLine && (a <= Math.PI / 2 || a > Math.PI * 3 / 2)) continue;

let tl = symbol.tl,
const tl = symbol.tl,
tr = symbol.tr,
bl = symbol.bl,
br = symbol.br,
tex = symbol.tex,
anchorPoint = symbol.anchorPoint,
anchorPoint = symbol.anchorPoint;

minZoom = Math.max(zoom + Math.log(symbol.minScale) / Math.LN2, placementZoom),
maxZoom = Math.min(zoom + Math.log(symbol.maxScale) / Math.LN2, 25);
let minZoom = Math.max(zoom + Math.log(symbol.minScale) / Math.LN2, placementZoom);
const maxZoom = Math.min(zoom + Math.log(symbol.maxScale) / Math.LN2, 25);

if (maxZoom <= minZoom) continue;

Expand Down Expand Up @@ -550,7 +550,7 @@ SymbolBucket.prototype.updateIcons = function(icons) {

SymbolBucket.prototype.updateFont = function(stacks) {
this.recalculateStyleLayers();
let fontName = this.layer.layout['text-font'],
const fontName = this.layer.layout['text-font'],
stack = stacks[fontName] = stacks[fontName] || {};

this.textFeatures = resolveText(this.features, this.layer.layout, stack);
Expand Down Expand Up @@ -600,19 +600,19 @@ SymbolBucket.prototype.addSymbolInstance = function(anchor, line, shapedText, sh
textBoxScale, textPadding, textAlongLine,
iconBoxScale, iconPadding, iconAlongLine, globalProperties, featureProperties) {

let glyphQuadStartIndex, glyphQuadEndIndex, iconQuadStartIndex, iconQuadEndIndex, textCollisionFeature, iconCollisionFeature, glyphQuads, iconQuads;
let textCollisionFeature, iconCollisionFeature, glyphQuads, iconQuads;
if (shapedText) {
glyphQuads = addToBuffers ? getGlyphQuads(anchor, shapedText, textBoxScale, line, layer, textAlongLine) : [];
textCollisionFeature = new CollisionFeature(collisionBoxArray, line, anchor, featureIndex, sourceLayerIndex, bucketIndex, shapedText, textBoxScale, textPadding, textAlongLine, false);
}

glyphQuadStartIndex = this.symbolQuadsArray.length;
const glyphQuadStartIndex = this.symbolQuadsArray.length;
if (glyphQuads && glyphQuads.length) {
for (let i = 0; i < glyphQuads.length; i++) {
this.addSymbolQuad(glyphQuads[i]);
}
}
glyphQuadEndIndex = this.symbolQuadsArray.length;
const glyphQuadEndIndex = this.symbolQuadsArray.length;

const textBoxStartIndex = textCollisionFeature ? textCollisionFeature.boxStartIndex : this.collisionBoxArray.length;
const textBoxEndIndex = textCollisionFeature ? textCollisionFeature.boxEndIndex : this.collisionBoxArray.length;
Expand All @@ -622,11 +622,11 @@ SymbolBucket.prototype.addSymbolInstance = function(anchor, line, shapedText, sh
iconCollisionFeature = new CollisionFeature(collisionBoxArray, line, anchor, featureIndex, sourceLayerIndex, bucketIndex, shapedIcon, iconBoxScale, iconPadding, iconAlongLine, true);
}

iconQuadStartIndex = this.symbolQuadsArray.length;
const iconQuadStartIndex = this.symbolQuadsArray.length;
if (iconQuads && iconQuads.length === 1) {
this.addSymbolQuad(iconQuads[0]);
}
iconQuadEndIndex = this.symbolQuadsArray.length;
const iconQuadEndIndex = this.symbolQuadsArray.length;

const iconBoxStartIndex = iconCollisionFeature ? iconCollisionFeature.boxStartIndex : this.collisionBoxArray.length;
const iconBoxEndIndex = iconCollisionFeature ? iconCollisionFeature.boxEndIndex : this.collisionBoxArray.length;
Expand Down
2 changes: 1 addition & 1 deletion js/data/feature_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ FeatureIndex.prototype.query = function(args, styleLayers) {

const result = {};

let params = args.params || {},
const params = args.params || {},
pixelsToTileUnits = EXTENT / args.tileSize / args.scale,
filter = featureFilter(params.filter);

Expand Down
6 changes: 3 additions & 3 deletions js/geo/lng_lat_bounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ LngLatBounds.prototype = {
* @returns {LngLatBounds} `this`
*/
extend: function(obj) {
let sw = this._sw,
ne = this._ne,
sw2, ne2;
const sw = this._sw,
ne = this._ne;
let sw2, ne2;

if (obj instanceof LngLat) {
sw2 = obj;
Expand Down
16 changes: 8 additions & 8 deletions js/geo/transform.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

let LngLat = require('./lng_lat'),
const LngLat = require('./lng_lat'),
Point = require('point-geometry'),
Coordinate = require('./coordinate'),
util = require('../util/util'),
Expand All @@ -9,7 +9,7 @@ let LngLat = require('./lng_lat'),
EXTENT = require('../data/bucket').EXTENT,
glmatrix = require('gl-matrix');

let vec4 = glmatrix.vec4,
const vec4 = glmatrix.vec4,
mat4 = glmatrix.mat4,
mat2 = glmatrix.mat2;

Expand Down Expand Up @@ -160,7 +160,7 @@ Transform.prototype = {
if (z < options.minzoom) return [];
if (z > options.maxzoom) z = options.maxzoom;

let tr = this,
const tr = this,
tileCenter = tr.locationCoordinate(tr.center)._zoomTo(z),
centerPoint = new Point(tileCenter.column - 0.5, tileCenter.row - 0.5);

Expand Down Expand Up @@ -278,7 +278,7 @@ Transform.prototype = {
* @private
*/
locationCoordinate: function(lnglat) {
let k = this.zoomScale(this.tileZoom) / this.worldSize,
const k = this.zoomScale(this.tileZoom) / this.worldSize,
ll = LngLat.convert(lnglat);

return new Coordinate(
Expand Down Expand Up @@ -377,8 +377,8 @@ Transform.prototype = {

this._constraining = true;

let minY, maxY, minX, maxX, sy, sx, x2, y2,
size = this.size,
let minY, maxY, minX, maxX, sy, sx, x2, y2;
const size = this.size,
unmodified = this._unmodified;

if (this.latRange) {
Expand Down Expand Up @@ -407,15 +407,15 @@ Transform.prototype = {
}

if (this.latRange) {
let y = this.y,
const y = this.y,
h2 = size.y / 2;

if (y - h2 < minY) y2 = minY + h2;
if (y + h2 > maxY) y2 = maxY - h2;
}

if (this.lngRange) {
let x = this.x,
const x = this.x,
w2 = size.x / 2;

if (x - w2 < minX) x2 = minX + w2;
Expand Down
4 changes: 2 additions & 2 deletions js/lib/debugtext.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ const simplexFont = {
module.exports = function textVertices(text, left, baseline, scale) {
scale = scale || 1;

let strokes = [],
i, len, j, len2, glyph, x, y, prev;
const strokes = [];
let i, len, j, len2, glyph, x, y, prev;

for (i = 0, len = text.length; i < len; i++) {
glyph = simplexFont[text[i]];
Expand Down
2 changes: 1 addition & 1 deletion js/render/draw_extrusion.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ function setLight(program, painter) {
const gl = painter.gl;
const light = painter.style.light;

let _lp = light.calculated.position,
const _lp = light.calculated.position,
lightPos = [_lp.x, _lp.y, _lp.z];
const lightMat = mat3.create();
if (light.calculated.anchor === 'viewport') mat3.fromRotation(lightMat, -painter.transform.angle);
Expand Down
2 changes: 1 addition & 1 deletion js/render/draw_raster.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function drawRasterTile(painter, sourceCache, layer, coord) {
gl.uniform1f(program.u_contrast_factor, contrastFactor(layer.paint['raster-contrast']));
gl.uniform3fv(program.u_spin_weights, spinWeights(layer.paint['raster-hue-rotate']));

let parentTile = tile.sourceCache && tile.sourceCache.findLoadedParent(coord, 0, {}),
const parentTile = tile.sourceCache && tile.sourceCache.findLoadedParent(coord, 0, {}),
opacities = getOpacities(tile, parentTile, layer, painter.transform);

let parentScaleBy, parentTL;
Expand Down
2 changes: 1 addition & 1 deletion js/source/geojson_worker_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ GeoJSONWorkerSource.prototype = util.inherit(VectorTileWorkerSource, /** @lends
* See {@link VectorTileWorkerSource#loadTile}.
*/
loadVectorData: function (params, callback) {
let source = params.source,
const source = params.source,
coord = params.coord;

if (!this._geoJSONIndexes[source]) {
Expand Down
6 changes: 3 additions & 3 deletions js/source/geojson_wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ FeatureWrapper.prototype.loadGeometry = function() {
this.geometry = [];

for (let i = 0; i < rings.length; i++) {
let ring = rings[i],
const ring = rings[i],
newRing = [];
for (let j = 0; j < ring.length; j++) {
newRing.push(new Point(ring[j][0], ring[j][1]));
Expand All @@ -49,8 +49,8 @@ FeatureWrapper.prototype.loadGeometry = function() {
FeatureWrapper.prototype.bbox = function() {
if (!this.geometry) this.loadGeometry();

let rings = this.geometry,
x1 = Infinity,
const rings = this.geometry;
let x1 = Infinity,
x2 = -Infinity,
y1 = Infinity,
y2 = -Infinity;
Expand Down
4 changes: 2 additions & 2 deletions js/source/tile_coord.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ TileCoord.prototype.toCoordinate = function(sourceMaxZoom) {

// Parse a packed integer id into a TileCoord object
TileCoord.fromID = function(id) {
let z = id % 32, dim = 1 << z;
const z = id % 32, dim = 1 << z;
const xy = ((id - z) / 32);
let x = xy % dim, y = ((xy - x) / dim) % dim;
const x = xy % dim, y = ((xy - x) / dim) % dim;
let w = Math.floor(xy / (dim * dim));
if (w % 2 !== 0) w = w * -1 - 1;
w /= 2;
Expand Down
10 changes: 5 additions & 5 deletions js/source/vector_tile_worker_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ VectorTileWorkerSource.prototype = {
* @param {boolean} params.showCollisionBoxes
*/
loadTile: function(params, callback) {
let source = params.source,
const source = params.source,
uid = params.uid;

if (!this.loading[source])
Expand Down Expand Up @@ -81,7 +81,7 @@ VectorTileWorkerSource.prototype = {
* @param {string} params.uid The UID for this tile.
*/
reloadTile: function(params, callback) {
let loaded = this.loaded[params.source],
const loaded = this.loaded[params.source],
uid = params.uid;
if (loaded && loaded[uid]) {
const workerTile = loaded[uid];
Expand All @@ -97,7 +97,7 @@ VectorTileWorkerSource.prototype = {
* @param {string} params.uid The UID for this tile.
*/
abortTile: function(params) {
let loading = this.loading[params.source],
const loading = this.loading[params.source],
uid = params.uid;
if (loading && loading[uid] && loading[uid].abort) {
loading[uid].abort();
Expand All @@ -113,7 +113,7 @@ VectorTileWorkerSource.prototype = {
* @param {string} params.uid The UID for this tile.
*/
removeTile: function(params) {
let loaded = this.loaded[params.source],
const loaded = this.loaded[params.source],
uid = params.uid;
if (loaded && loaded[uid]) {
delete loaded[uid];
Expand Down Expand Up @@ -157,7 +157,7 @@ VectorTileWorkerSource.prototype = {
},

redoPlacement: function(params, callback) {
let loaded = this.loaded[params.source],
const loaded = this.loaded[params.source],
loading = this.loading[params.source],
uid = params.uid;

Expand Down
2 changes: 1 addition & 1 deletion js/source/worker_tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ WorkerTile.prototype.parse = function(data, layerFamilies, actor, callback) {
}
}

let buckets = [],
const buckets = [],
symbolBuckets = this.symbolBuckets = [],
otherBuckets = [];

Expand Down
2 changes: 1 addition & 1 deletion js/style/light.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Light.prototype = util.inherit(Evented, {

getLightValue: function(property, globalProperties) {
if (property === 'position') {
let calculated = this._transitions[property].calculate(globalProperties),
const calculated = this._transitions[property].calculate(globalProperties),
cartesian = util.sphericalToCartesian(calculated);
return {
x: cartesian[0],
Expand Down
6 changes: 3 additions & 3 deletions js/style/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -765,9 +765,9 @@ Style.prototype = util.inherit(Evented, {
},

'get glyphs': function(mapId, params, callback) {
let stacks = params.stacks,
remaining = Object.keys(stacks).length,
allGlyphs = {};
const stacks = params.stacks;
let remaining = Object.keys(stacks).length;
const allGlyphs = {};

for (const fontName in stacks) {
this.glyphSource.getSimpleGlyphs(fontName, stacks[fontName], params.uid, done);
Expand Down
2 changes: 1 addition & 1 deletion js/symbol/collision_tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function CollisionTile(angle, pitch, collisionBoxArray) {
this.angle = angle;
this.pitch = pitch;

let sin = Math.sin(angle),
const sin = Math.sin(angle),
cos = Math.cos(angle);
this.rotationMatrix = [cos, -sin, sin, cos];
this.reverseRotationMatrix = [cos, sin, -sin, cos];
Expand Down
6 changes: 3 additions & 3 deletions js/symbol/get_anchors.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ function resample(line, offset, spacing, angleWindowSize, maxAngle, labelLength,

for (let i = 0; i < line.length - 1; i++) {

let a = line[i],
const a = line[i],
b = line[i + 1];

let segmentDist = a.dist(b),
const segmentDist = a.dist(b),
angle = b.angleTo(a);

while (markedDistance + spacing < distance + segmentDist) {
markedDistance += spacing;

let t = (markedDistance - distance) / segmentDist,
const t = (markedDistance - distance) / segmentDist,
x = interpolate(a.x, b.x, t),
y = interpolate(a.y, b.y, t);

Expand Down
Loading

0 comments on commit 7e8cf5d

Please sign in to comment.