style: fix lint issues in code 🕺

Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com>
This commit is contained in:
Vinayak Kulkarni 2022-08-08 18:41:02 +05:30
parent 50201f0a99
commit f61e333b29
No known key found for this signature in database
GPG key ID: 0FE8ABF8260A1552
9 changed files with 9977 additions and 184 deletions

View file

@ -5,16 +5,17 @@
"main": "src/main.js", "main": "src/main.js",
"bin": "src/main.js", "bin": "src/main.js",
"type": "module", "type": "module",
"repository": {
"type": "git",
"url": "git+https://github.com/maptiler/tileserver-gl.git"
},
"license": "BSD-2-Clause", "license": "BSD-2-Clause",
"engines": { "engines": {
"node": ">=14.15.0 <17" "node": ">=14.15.0 <17"
}, },
"scripts": { "scripts": {
"test": "mocha test/**.js --timeout 10000", "test": "mocha test/**.js --timeout 10000",
"lint:yml": "yamllint --schema=CORE_SCHEMA *.{yml,yaml}",
"lint:prettier": "prettier --check \"{,!(node_modules|dist|static)/**/}*.{js,ts,cjs,mjs,json}\" --ignore-path .gitignore",
"lint:prettier:fix": "prettier --write \"{,!(node_modules|dist|static)/**/}*.{js,ts,cjs,mjs,json}\" --ignore-path .gitignore",
"lint": "npm run lint:prettier",
"lintfix": "npm run lint:prettier:fix",
"docker": "docker build -f Dockerfile . && docker run --rm -i -p 8080:80 $(docker build -q .)" "docker": "docker build -f Dockerfile . && docker run --rm -i -p 8080:80 $(docker build -q .)"
}, },
"dependencies": { "dependencies": {
@ -45,6 +46,24 @@
"devDependencies": { "devDependencies": {
"chai": "4.3.6", "chai": "4.3.6",
"mocha": "^10.0.0", "mocha": "^10.0.0",
"supertest": "^6.2.4" "prettier": "^2.7.1",
"should": "^13.2.3",
"supertest": "^6.2.4",
"yaml-lint": "^1.7.0"
},
"repository": {
"url": "git+https://github.com/maptiler/tileserver-gl.git",
"type": "git"
},
"contributors": [
{
"name": "Vinayak Kulkarni",
"email": "inbox.vinayak@gmail.com",
"url": "https://vinayakkulkarni.dev"
} }
],
"bugs": {
"url": "https://github.com/maptiler/tileserver-gl/issues"
},
"homepage": "https://github.com/maptiler/tileserver-gl#readme"
} }

13
prettier.config.cjs Normal file
View file

@ -0,0 +1,13 @@
module.exports = {
$schema: 'http://json.schemastore.org/prettierrc',
semi: true,
arrowParens: 'always',
singleQuote: true,
trailingComma: 'all',
bracketSpacing: true,
htmlWhitespaceSensitivity: 'css',
insertPragma: false,
tabWidth: 2,
useTabs: false,
endOfLine: 'lf',
};

View file

@ -1,8 +1,7 @@
(function (window) { (function (window) {
var HAS_HASHCHANGE = (function () { var HAS_HASHCHANGE = (function () {
var doc_mode = window.documentMode; var doc_mode = window.documentMode;
return ('onhashchange' in window) && return 'onhashchange' in window && (doc_mode === undefined || doc_mode > 7);
(doc_mode === undefined || doc_mode > 7);
})(); })();
L.Hash = function (map) { L.Hash = function (map) {
@ -17,7 +16,7 @@
if (hash.indexOf('#') === 0) { if (hash.indexOf('#') === 0) {
hash = hash.substr(1); hash = hash.substr(1);
} }
var args = hash.split("/"); var args = hash.split('/');
if (args.length == 3) { if (args.length == 3) {
var zoom = parseInt(args[0], 10), var zoom = parseInt(args[0], 10),
lat = parseFloat(args[1]), lat = parseFloat(args[1]),
@ -27,7 +26,7 @@
} else { } else {
return { return {
center: new L.LatLng(lat, lon), center: new L.LatLng(lat, lon),
zoom: zoom zoom: zoom,
}; };
} }
} else { } else {
@ -35,18 +34,19 @@
} }
}; };
L.Hash.formatHash = function(map) { (L.Hash.formatHash = function (map) {
var center = map.getCenter(), var center = map.getCenter(),
zoom = map.getZoom(), zoom = map.getZoom(),
precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2)); precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
return "#" + [zoom, return (
center.lat.toFixed(precision), '#' +
center.lng.toFixed(precision) [zoom, center.lat.toFixed(precision), center.lng.toFixed(precision)].join(
].join("/"); '/',
}, )
);
L.Hash.prototype = { }),
(L.Hash.prototype = {
map: null, map: null,
lastHash: null, lastHash: null,
@ -128,10 +128,10 @@
isListening: false, isListening: false,
hashChangeInterval: null, hashChangeInterval: null,
startListening: function () { startListening: function () {
this.map.on("moveend", this.onMapMove, this); this.map.on('moveend', this.onMapMove, this);
if (HAS_HASHCHANGE) { if (HAS_HASHCHANGE) {
L.DomEvent.addListener(window, "hashchange", this.onHashChange); L.DomEvent.addListener(window, 'hashchange', this.onHashChange);
} else { } else {
clearInterval(this.hashChangeInterval); clearInterval(this.hashChangeInterval);
this.hashChangeInterval = setInterval(this.onHashChange, 50); this.hashChangeInterval = setInterval(this.onHashChange, 50);
@ -140,16 +140,16 @@
}, },
stopListening: function () { stopListening: function () {
this.map.off("moveend", this.onMapMove, this); this.map.off('moveend', this.onMapMove, this);
if (HAS_HASHCHANGE) { if (HAS_HASHCHANGE) {
L.DomEvent.removeListener(window, "hashchange", this.onHashChange); L.DomEvent.removeListener(window, 'hashchange', this.onHashChange);
} else { } else {
clearInterval(this.hashChangeInterval); clearInterval(this.hashChangeInterval);
} }
this.isListening = false; this.isListening = false;
} },
}; });
L.hash = function (map) { L.hash = function (map) {
return new L.Hash(map); return new L.Hash(map);
}; };

File diff suppressed because one or more lines are too long

View file

@ -26,7 +26,8 @@ const __dirname = path.dirname(__filename);
const packageJson = JSON.parse(fs.readFileSync(__dirname + '/package.json', 'utf8')) const packageJson = JSON.parse(fs.readFileSync(__dirname + '/package.json', 'utf8'))
packageJson.name += '-light'; packageJson.name += '-light';
packageJson.description = 'Map tile server for JSON GL styles - serving vector tiles'; packageJson.description =
'Map tile server for JSON GL styles - serving vector tiles';
delete packageJson.dependencies['canvas']; delete packageJson.dependencies['canvas'];
delete packageJson.dependencies['@maplibre/maplibre-gl-native']; delete packageJson.dependencies['@maplibre/maplibre-gl-native'];
delete packageJson.dependencies['sharp']; delete packageJson.dependencies['sharp'];

View file

@ -35,7 +35,9 @@ export const serve_data = {
} }
if (z < item.tileJSON.minzoom || 0 || x < 0 || y < 0 || if (z < item.tileJSON.minzoom || 0 || x < 0 || y < 0 ||
z > item.tileJSON.maxzoom || z > item.tileJSON.maxzoom ||
x >= Math.pow(2, z) || y >= Math.pow(2, z)) { x >= Math.pow(2, z) ||
y >= Math.pow(2, z)
) {
return res.status(404).send('Out of bounds'); return res.status(404).send('Out of bounds');
} }
item.source.getTile(z, x, y, (err, data, headers) => { item.source.getTile(z, x, y, (err, data, headers) => {
@ -46,6 +48,9 @@ export const serve_data = {
} else { } else {
return res.status(500).send(err.message); return res.status(500).send(err.message);
} }
} else {
return res.status(500).send(err.message);
}
} else { } else {
if (data == null) { if (data == null) {
return res.status(404).send('Not found'); return res.status(404).send('Not found');
@ -58,13 +63,6 @@ export const serve_data = {
data = zlib.unzipSync(data); data = zlib.unzipSync(data);
isGzipped = false; isGzipped = false;
} }
data = options.dataDecoratorFunc(id, 'data', data, z, x, y);
}
}
if (format === 'pbf') {
headers['Content-Type'] = 'application/x-protobuf';
} else if (format === 'geojson') {
headers['Content-Type'] = 'application/json';
if (isGzipped) { if (isGzipped) {
data = zlib.unzipSync(data); data = zlib.unzipSync(data);
@ -84,7 +82,6 @@ export const serve_data = {
featureGeoJSON.properties.layer = layerName; featureGeoJSON.properties.layer = layerName;
geojson.features.push(featureGeoJSON); geojson.features.push(featureGeoJSON);
} }
}
data = JSON.stringify(geojson); data = JSON.stringify(geojson);
} }
delete headers['ETag']; // do not trust the tile ETag -- regenerate delete headers['ETag']; // do not trust the tile ETag -- regenerate
@ -100,7 +97,8 @@ export const serve_data = {
} }
} }
}); });
}); },
);
app.get('/:id.json', (req, res, next) => { app.get('/:id.json', (req, res, next) => {
const item = repo[req.params.id]; const item = repo[req.params.id];
@ -120,7 +118,7 @@ export const serve_data = {
add: (options, repo, params, id, publicUrl) => { add: (options, repo, params, id, publicUrl) => {
const mbtilesFile = path.resolve(options.paths.mbtiles, params.mbtiles); const mbtilesFile = path.resolve(options.paths.mbtiles, params.mbtiles);
let tileJSON = { let tileJSON = {
'tiles': params.domains || options.domains tiles: params.domains || options.domains,
}; };
const mbtilesFileStats = fs.statSync(mbtilesFile); const mbtilesFileStats = fs.statSync(mbtilesFile);
@ -167,5 +165,5 @@ export const serve_data = {
source source
}; };
}); });
} },
}; };