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 f8a0ab6d3c
commit a6a92a263c
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",
"bin": "src/main.js",
"type": "module",
"repository": {
"type": "git",
"url": "git+https://github.com/maptiler/tileserver-gl.git"
},
"license": "BSD-2-Clause",
"engines": {
"node": ">=14.15.0 <17"
},
"scripts": {
"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 .)"
},
"dependencies": {
@ -44,6 +45,24 @@
"devDependencies": {
"chai": "4.3.6",
"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) {
var HAS_HASHCHANGE = (function () {
var doc_mode = window.documentMode;
return ('onhashchange' in window) &&
(doc_mode === undefined || doc_mode > 7);
return 'onhashchange' in window && (doc_mode === undefined || doc_mode > 7);
})();
L.Hash = function (map) {
@ -17,7 +16,7 @@
if (hash.indexOf('#') === 0) {
hash = hash.substr(1);
}
var args = hash.split("/");
var args = hash.split('/');
if (args.length == 3) {
var zoom = parseInt(args[0], 10),
lat = parseFloat(args[1]),
@ -27,7 +26,7 @@
} else {
return {
center: new L.LatLng(lat, lon),
zoom: zoom
zoom: zoom,
};
}
} else {
@ -35,18 +34,19 @@
}
};
L.Hash.formatHash = function(map) {
(L.Hash.formatHash = function (map) {
var center = map.getCenter(),
zoom = map.getZoom(),
precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
return "#" + [zoom,
center.lat.toFixed(precision),
center.lng.toFixed(precision)
].join("/");
},
L.Hash.prototype = {
return (
'#' +
[zoom, center.lat.toFixed(precision), center.lng.toFixed(precision)].join(
'/',
)
);
}),
(L.Hash.prototype = {
map: null,
lastHash: null,
@ -128,10 +128,10 @@
isListening: false,
hashChangeInterval: null,
startListening: function () {
this.map.on("moveend", this.onMapMove, this);
this.map.on('moveend', this.onMapMove, this);
if (HAS_HASHCHANGE) {
L.DomEvent.addListener(window, "hashchange", this.onHashChange);
L.DomEvent.addListener(window, 'hashchange', this.onHashChange);
} else {
clearInterval(this.hashChangeInterval);
this.hashChangeInterval = setInterval(this.onHashChange, 50);
@ -140,16 +140,16 @@
},
stopListening: function () {
this.map.off("moveend", this.onMapMove, this);
this.map.off('moveend', this.onMapMove, this);
if (HAS_HASHCHANGE) {
L.DomEvent.removeListener(window, "hashchange", this.onHashChange);
L.DomEvent.removeListener(window, 'hashchange', this.onHashChange);
} else {
clearInterval(this.hashChangeInterval);
}
this.isListening = false;
}
};
},
});
L.hash = function (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'))
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['@maplibre/maplibre-gl-native'];
delete packageJson.dependencies['sharp'];

View file

@ -35,7 +35,9 @@ export const serve_data = {
}
if (z < item.tileJSON.minzoom || 0 || x < 0 || y < 0 ||
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');
}
item.source.getTile(z, x, y, (err, data, headers) => {
@ -46,6 +48,9 @@ export const serve_data = {
} else {
return res.status(500).send(err.message);
}
} else {
return res.status(500).send(err.message);
}
} else {
if (data == null) {
return res.status(404).send('Not found');
@ -58,13 +63,6 @@ export const serve_data = {
data = zlib.unzipSync(data);
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) {
data = zlib.unzipSync(data);
@ -84,7 +82,6 @@ export const serve_data = {
featureGeoJSON.properties.layer = layerName;
geojson.features.push(featureGeoJSON);
}
}
data = JSON.stringify(geojson);
}
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) => {
const item = repo[req.params.id];
@ -120,7 +118,7 @@ export const serve_data = {
add: (options, repo, params, id, publicUrl) => {
const mbtilesFile = path.resolve(options.paths.mbtiles, params.mbtiles);
let tileJSON = {
'tiles': params.domains || options.domains
tiles: params.domains || options.domains,
};
const mbtilesFileStats = fs.statSync(mbtilesFile);
@ -167,5 +165,5 @@ export const serve_data = {
source
};
});
}
},
};