Skip to content
This repository was archived by the owner on Aug 27, 2025. It is now read-only.

Commit 17bccfa

Browse files
committed
Update eslint and all the things it now complains about
1 parent b9a0871 commit 17bccfa

File tree

14 files changed

+740
-535
lines changed

14 files changed

+740
-535
lines changed

.eslintrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
var validate = require('./lib/validate');
2-
var Step = require('step');
1+
'use strict';
2+
3+
const validate = require('./lib/validate');
4+
const Step = require('step');
35

46
module.exports = function(filepath, callback) {
5-
var results = {};
7+
const results = {};
68

79
function fail(err) {
810
err = err || new Error('Any unspecified error was encountered');
@@ -32,7 +34,7 @@ module.exports = function(filepath, callback) {
3234
results.source = source;
3335
validate[results.protocol.slice(0,-1)](results, this);
3436
},
35-
function(err) {
37+
(err) => {
3638
if (err) return fail(err);
3739
callback(null, true);
3840
}

lib/invalid.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
var os = require('os');
2-
var path = require('path');
3-
var util = require('util');
1+
/* jshint esversion: 6 */
2+
'use strict';
3+
4+
const os = require('os');
5+
const path = require('path');
6+
const util = require('util');
47

58
module.exports = function invalid(err) {
6-
var msg = typeof err === 'string' ?
9+
let msg = typeof err === 'string' ?
710
util.format.apply(this, arguments) : err.message;
811

912
msg = msg
1013
.replace(new RegExp(path.join(os.tmpdir(),'[0-9a-z]+-'), 'g'), '');
1114

12-
var error = new Error(msg);
15+
const error = new Error(msg);
1316
error.code = 'EINVALID';
1417

1518
if (err.stack) error.stack = err.stack;

lib/tilelive-mapbox.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
var TileJSON = require('@mapbox/tilejson');
2-
var url = require('url');
1+
/* jshint esversion: 6 */
2+
'use strict';
3+
4+
const TileJSON = require('@mapbox/tilejson');
5+
const url = require('url');
36

47
module.exports = Mapbox;
58

lib/tilelive-serialtiles.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1-
var url = require('url');
2-
var fs = require('fs');
3-
var split = require('split');
4-
var zlib = require('zlib');
1+
/* jshint esversion: 6 */
2+
'use strict';
3+
4+
const url = require('url');
5+
const fs = require('fs');
6+
const split = require('split');
7+
const zlib = require('zlib');
58

69
module.exports = Serialtiles;
710

811
function Serialtiles(uri, callback) {
9-
var filepath = url.parse(uri).pathname;
10-
var serialtiles = this;
12+
const filepath = url.parse(uri).pathname;
13+
const serialtiles = this;
1114

12-
fs.stat(filepath, function(err, stats) {
15+
fs.stat(filepath, (err, stats) => {
1316
if (err) return callback(err);
1417
serialtiles.filestats = stats;
1518
serialtiles.filepath = filepath;
@@ -18,27 +21,27 @@ function Serialtiles(uri, callback) {
1821
}
1922

2023
Serialtiles.prototype.getInfo = function(callback) {
21-
var gotInfo = false;
22-
var read = fs.createReadStream(this.filepath).pipe(zlib.createGunzip());
24+
let gotInfo = false;
25+
const read = fs.createReadStream(this.filepath).pipe(zlib.createGunzip());
2326

2427
read.pipe(split())
25-
.on('data', function(item) {
26-
var isInfo = item !== 'JSONBREAKFASTTIME' && item.indexOf('{"z":') !== 0 && item.length;
28+
.on('data', (item) => {
29+
const isInfo = item !== 'JSONBREAKFASTTIME' && item.indexOf('{"z":') !== 0 && item.length;
2730
if (isInfo && !gotInfo) {
2831
gotInfo = true;
2932

3033
try {
3134
item = JSON.parse(item);
3235
callback(null, item);
3336
}
34-
catch(err) {
37+
catch (err) {
3538
callback(err);
3639
}
3740

3841
read.unpipe(split);
3942
}
4043
})
41-
.on('end', function() {
44+
.on('end', () => {
4245
if (!gotInfo) callback(new Error('Missing Info object'));
4346
});
4447
};

lib/validate.js

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
var sniffer = require('@mapbox/mapbox-file-sniff');
2-
var path = require('path');
3-
4-
var tilelive = require('@mapbox/tilelive');
5-
var Vector = require('@mapbox/tilelive-vector');
6-
var MBTiles = require('@mapbox/mbtiles');
7-
var Omnivore = require('@mapbox/tilelive-omnivore');
8-
var TileJSON = require('@mapbox/tilejson');
9-
var Serialtiles = require('../lib/tilelive-serialtiles');
10-
var Mapbox = require('../lib/tilelive-mapbox');
11-
var invalid = require('./invalid');
12-
var kmlValidator = require('./validators/kml.js');
13-
var log = require('fastlog')('mapbox-upload-validate', process.env.FASTLOG_LEVEL || 'info');
14-
var prettyBytes = require('pretty-bytes');
1+
/* jshint esversion: 6 */
2+
'use strict';
3+
4+
const sniffer = require('@mapbox/mapbox-file-sniff');
5+
const path = require('path');
6+
7+
const tilelive = require('@mapbox/tilelive');
8+
const Vector = require('@mapbox/tilelive-vector');
9+
const MBTiles = require('@mapbox/mbtiles');
10+
const Omnivore = require('@mapbox/tilelive-omnivore');
11+
const TileJSON = require('@mapbox/tilejson');
12+
const Serialtiles = require('../lib/tilelive-serialtiles');
13+
const Mapbox = require('../lib/tilelive-mapbox');
14+
const invalid = require('./invalid');
15+
const kmlValidator = require('./validators/kml.js');
16+
const log = require('fastlog')('mapbox-upload-validate', process.env.FASTLOG_LEVEL || 'info');
17+
const prettyBytes = require('pretty-bytes');
1518

1619
Vector.registerProtocols(tilelive);
1720
MBTiles.registerProtocols(tilelive);
@@ -26,18 +29,18 @@ if (process.env.MapboxUploadValidateFonts)
2629
Vector.mapnik.register_fonts(process.env.MapboxUploadValidateFonts, { recurse: true });
2730

2831
module.exports.limits = function loadLimits() {
29-
var limits = {
32+
const limits = {
3033
max_metadata: 60 * 1024
3134
};
3235
// copy to defaults:
3336
limits._defaults = JSON.parse(JSON.stringify(limits));
3437

3538
// allow env overrides
36-
for(var limit in limits) {
37-
var env = 'LIMITS_' + limit.toUpperCase();
38-
var val = process.env[env];
39-
if(val) {
40-
if(val.length === 0 || isNaN(val)) {
39+
for (const limit in limits) {
40+
const env = 'LIMITS_' + limit.toUpperCase();
41+
const val = process.env[env];
42+
if (val) {
43+
if (val.length === 0 || isNaN(val)) {
4144
log.warn('Environment variable specified ' + env + ', but value is invalid: ' + val + '. The default (' + limits._defaults[limit] + ') will be used.');
4245
} else {
4346
log.info('Environment variable ' + env + ' overrides default ' + limits._defaults[limit] + ' => ' + val);
@@ -52,7 +55,7 @@ module.exports.limits = function loadLimits() {
5255
module.exports.filepath = function validateFilepath(filepath, callback) {
5356
filepath = path.resolve(filepath);
5457

55-
sniffer.fromFile(filepath, function(err, info) {
58+
sniffer.fromFile(filepath, (err, info) => {
5659
if (err) return callback(invalid(err));
5760
return callback(null, {
5861
protocol: info.protocol,
@@ -70,13 +73,13 @@ module.exports.info = function validateInfo(info, limits, callback) {
7073
// Lightweight KML validation before gdal/mapnik KML drivers
7174
// which never finish if KMLs have too many layers
7275
if (info.filetype === 'kml') {
73-
var kmlValid = kmlValidator(info.filepath);
76+
const kmlValid = kmlValidator(info.filepath);
7477
if (kmlValid !== true) {
7578
return callback(invalid(kmlValid));
7679
}
7780
}
7881

79-
tilelive.info(info.uri, function(err, info) {
82+
tilelive.info(info.uri, (err, info) => {
8083
if (err) return callback(invalid(err));
8184
if (info.prepare) return callback(invalid('Source cannot contain prepare key'));
8285

@@ -86,7 +89,7 @@ module.exports.info = function validateInfo(info, limits, callback) {
8689
// don't count pre-generated tilestats objects from mbtiles
8790
if (info.tilestats) delete info.tilestats;
8891

89-
var metadataLength = JSON.stringify(info).length;
92+
const metadataLength = JSON.stringify(info).length;
9093
if (metadataLength > limits.max_metadata)
9194
return callback(invalid('Metadata ' + prettyBytes(metadataLength) + ' exceeds limit of ' + prettyBytes(limits.max_metadata) + '.'));
9295

@@ -95,7 +98,7 @@ module.exports.info = function validateInfo(info, limits, callback) {
9598
};
9699

97100
module.exports.source = function validateSource(uri, callback) {
98-
tilelive.load(uri, function(err, source) {
101+
tilelive.load(uri, (err, source) => {
99102
if (err) return callback(invalid(err));
100103
callback(null, source);
101104
});

lib/validators/kml.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
var gdal = require('gdal');
1+
/* jshint esversion: 6 */
2+
'use strict';
3+
4+
const gdal = require('gdal');
25

36
module.exports = kmlLayers;
47

58
function kmlLayers(infile) {
69

7-
var ds_kml = {};
8-
var lyr_cnt = 0;
9-
var msg = [];
10+
let ds_kml = {};
11+
let lyr_cnt = 0;
12+
let msg = [];
1013

1114
function layername_count(ds) {
12-
var lyr_name_cnt = {};
13-
var dupes = {};
14-
ds.layers.forEach(function(lyr) {
15-
var lyr_name = lyr.name;
15+
const lyr_name_cnt = {};
16+
const dupes = {};
17+
ds.layers.forEach((lyr) => {
18+
const lyr_name = lyr.name;
1619
if (lyr_name in lyr_name_cnt) {
1720
lyr_name_cnt[lyr_name]++;
1821
dupes[lyr_name] = lyr_name_cnt[lyr_name];
@@ -40,10 +43,10 @@ function kmlLayers(infile) {
4043
return lyr_cnt + ' layers found. Maximum of ' + module.exports.max_layer_count + ' layers allowed.';
4144
}
4245

43-
var duplicate_lyr_msg = layername_count(ds_kml);
46+
const duplicate_lyr_msg = layername_count(ds_kml);
4447
if (Object.keys(duplicate_lyr_msg).length > 0) {
4548
ds_kml.close();
46-
for(var key in duplicate_lyr_msg) {
49+
for (const key in duplicate_lyr_msg) {
4750
msg += ' ' + key + ' (' + duplicate_lyr_msg[key] + ')';
4851
}
4952
return 'Duplicate layer names:' + msg;

0 commit comments

Comments
 (0)