Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion demos/eslint.config.mjs → demos/eslint.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import tseslint from "typescript-eslint";
import baseConfig from "../eslint.config.mjs";
import baseConfig from "../eslint.config";

export default tseslint.config(baseConfig, {
rules: {
Expand Down
3 changes: 2 additions & 1 deletion demos/src/03-sky-night.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Map, config, MapStyle } from "@maptiler/sdk";
import { Map, config, MapStyle } from "../../src";
import { addPerformanceStats, setupMapTilerApiKey } from "./demo-utils";

addPerformanceStats();
setupMapTilerApiKey({ config });

const container = document.getElementById("map-container")!;
const map = new Map({
container,
Expand Down
19 changes: 16 additions & 3 deletions eslint.config.mjs → eslint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
import tseslint from "typescript-eslint";
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";

import { TSESTree } from "@typescript-eslint/utils";
import { RuleContext } from "@typescript-eslint/utils/dist/ts-eslint";

type Node = TSESTree.ImportDeclaration;

type CustomRuleOptions = {
locations: string[];
message?: string;
fixedLocation?: string;
ignoreTypeImports?: boolean;
};

export default tseslint.config(
// https://typescript-eslint.io/getting-started/typed-linting/
tseslint.configs.strictTypeChecked,
Expand All @@ -27,7 +39,7 @@ export default tseslint.config(
},
],
},
create: function (context) {
create: function (context: RuleContext<"bannedImport", Node[]>) {
const filePath = context.getFilename();
const options = context.options[0] || {
"^/(.*)": {
Expand All @@ -36,8 +48,8 @@ export default tseslint.config(
};

return {
ImportDeclaration: (node) => {
Object.entries(options).forEach(([bannedImport, config]) => {
ImportDeclaration: (node: Node) => {
Object.entries(options).forEach(([bannedImport, config]: [string, CustomRuleOptions]) => {
const importLocationRegex = new RegExp(bannedImport);

if (config.ignoreTypeImports && node.importKind === "type") return;
Expand All @@ -50,6 +62,7 @@ export default tseslint.config(
node.specifiers.forEach((specifier) => {
if (specifier.type !== "ImportDefaultSpecifier") {
context.report({
// @ts-expect-error `message` seems to work with this...
message: config.message ?? `Importing from '${bannedImport}' is banned in '${fp}'`,
node,
});
Expand Down
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
"prepare": "husky",
"doc": "rm -rf docs/* && typedoc --out docs && cp -r images docs/",
"ncu": "npx npm-check-updates",
"lint": "eslint src",
"lint:fix": "eslint src --fix",
"lint": "tsc --noEmit && eslint src",
"lint:fix": "tsc --noEmit && eslint src --fix",
"test:watch": "vitest watch -c vite.config-test.ts --dom",
"test": "vitest run -c vite.config-test.ts --dom",
"install:clean": "rm -rf build/ dist/ node_modules/ && npm ci",
Expand Down Expand Up @@ -68,6 +68,7 @@
"eslint-plugin-prettier": "^5.2.3",
"happy-dom": "^17.4.4",
"husky": "^8.0.0",
"jiti": "^2.4.2",
"lint-staged": "^15.4.3",
"prettier": "3.5.2",
"stats.js": "^0.17.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
let warning = "The distant style could not be loaded.";
// Loading a new style failed. If a style is not already in place,
// the default one is loaded instead + warning in console
if (!this.getStyle()) {

Check warning on line 279 in src/Map.ts

View workflow job for this annotation

GitHub Actions / format-and-lint

Unnecessary conditional, value is always falsy
this.setStyle(MapStyle.STREETS);
warning += `Loading default MapTiler Cloud style "${MapStyle.STREETS.getDefaultVariant().getId()}" as a fallback.`;
} else {
Expand All @@ -301,7 +301,7 @@
// If the URL is present in the list of monitored style URL,
// that means this AJAXError was about a style, and we want to fallback to
// the default style
if (this.monitoredStyleUrls && this.monitoredStyleUrls.has(clearnUrlStr)) {

Check warning on line 304 in src/Map.ts

View workflow job for this annotation

GitHub Actions / format-and-lint

Unnecessary conditional, value is always truthy
this.monitoredStyleUrls.delete(clearnUrlStr);
applyFallbackStyle();
}
Expand Down Expand Up @@ -471,7 +471,7 @@

const tileJsonRes = await fetch(styleUrl.href);
tileJsonContent = await tileJsonRes.json();
} catch (e) {
} catch (_e) {
// No tiles.json found (should not happen on maintained styles)
}

Expand Down
6 changes: 3 additions & 3 deletions src/converters/xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,22 +622,22 @@ export function gpxOrKml(doc: string | Document): GeoJSON.FeatureCollection | nu
try {
// Converting only once rather than in each converter
if (typeof actualDoc === "string") actualDoc = str2xml(actualDoc);
} catch (e) {
} catch (_e) {
// The doc is a string but not valid XML
return null;
}

try {
const result = gpx(actualDoc);
return result;
} catch (e) {
} catch (_e) {
// The doc is valid XML but not valid GPX
}

try {
const result = kml(actualDoc);
return result;
} catch (e) {
} catch (_e) {
// The doc is valid XML but not valid KML
}

Expand Down
4 changes: 2 additions & 2 deletions src/mapstyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function urlToAbsoluteUrl(url: string): string {
try {
const u = new URL(url);
return u.href;
} catch (e) {
} catch (_e) {
// nothing to raise
}

Expand All @@ -130,7 +130,7 @@ export function convertToStyleSpecificationString(str: string): StyleValidationR
isValidStyle: styleErrs.length === 0,
styleObject: styleErrs.length === 0 ? (styleObj as maplibregl.StyleSpecification) : null,
};
} catch (e) {
} catch (_e) {
return {
isValidJSON: false,
isValidStyle: false,
Expand Down
8 changes: 4 additions & 4 deletions src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function enableRTL() {
if (status === "unavailable" || status === "requested") {
try {
maplibregl.setRTLTextPlugin(defaults.rtlPluginURL, true);
} catch (e) {
} catch (_e) {
// nothing
}
}
Expand Down Expand Up @@ -46,7 +46,7 @@ export function maptilerCloudTransformRequest(url: string, resourceType?: Resour
// Yet, if it's local we just return it without assuming a 'base' url (in the URL constructor)
// and we let the URL be locally resolved with a potential base path.
reqUrl = new URL(url);
} catch (e) {
} catch (_e) {
return {
url,
};
Expand Down Expand Up @@ -111,7 +111,7 @@ export function isUUID(s: string): boolean {
export function jsonParseNoThrow<T>(doc: string): T | null {
try {
return JSON.parse(doc);
} catch (e) {
} catch (_e) {
// pass
}

Expand Down Expand Up @@ -268,7 +268,7 @@ export function replaceLanguage(origLang: string, newLang: maplibregl.Expression
* can also contain null that stand for the use of {name}
*/
export function findLanguageStr(str: string): Array<string | null> {
const regex = /\{name(?:\:(?<language>\S+))?\}/g;
const regex = /\{name(?::(?<language>\S+))?\}/g;
const languageUsed = [] as Array<string | null>;

while (true) {
Expand Down
Loading