diff --git a/demos/eslint.config.mjs b/demos/eslint.config.ts similarity index 81% rename from demos/eslint.config.mjs rename to demos/eslint.config.ts index a197c221..99e91eaf 100644 --- a/demos/eslint.config.mjs +++ b/demos/eslint.config.ts @@ -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: { diff --git a/demos/src/03-sky-night.ts b/demos/src/03-sky-night.ts index 6ac42b6d..edac1572 100644 --- a/demos/src/03-sky-night.ts +++ b/demos/src/03-sky-night.ts @@ -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, diff --git a/eslint.config.mjs b/eslint.config.ts similarity index 89% rename from eslint.config.mjs rename to eslint.config.ts index 556dd8ef..c8da13f5 100644 --- a/eslint.config.mjs +++ b/eslint.config.ts @@ -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, @@ -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] || { "^/(.*)": { @@ -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; @@ -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, }); diff --git a/package-lock.json b/package-lock.json index 8191f4f5..5952ed9e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -30,6 +30,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", @@ -3489,6 +3490,16 @@ "dev": true, "license": "ISC" }, + "node_modules/jiti": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/jiti/-/jiti-2.4.2.tgz", + "integrity": "sha512-rg9zJN+G4n2nfJl5MW3BMygZX56zKPNVEYYqq7adpmMh4Jn2QNEwhvQlFy6jPVdcod7txZtKHWnyZiA3a0zP7A==", + "dev": true, + "license": "MIT", + "bin": { + "jiti": "lib/jiti-cli.mjs" + } + }, "node_modules/jju": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/jju/-/jju-1.4.0.tgz", diff --git a/package.json b/package.json index 6c8d98da..200676f8 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/src/Map.ts b/src/Map.ts index 241a7d84..e7ea4f36 100644 --- a/src/Map.ts +++ b/src/Map.ts @@ -471,7 +471,7 @@ export class Map extends maplibregl.Map { const tileJsonRes = await fetch(styleUrl.href); tileJsonContent = await tileJsonRes.json(); - } catch (e) { + } catch (_e) { // No tiles.json found (should not happen on maintained styles) } diff --git a/src/converters/xml.ts b/src/converters/xml.ts index e3421c52..3d1cf13c 100644 --- a/src/converters/xml.ts +++ b/src/converters/xml.ts @@ -622,7 +622,7 @@ 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; } @@ -630,14 +630,14 @@ export function gpxOrKml(doc: string | Document): GeoJSON.FeatureCollection | nu 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 } diff --git a/src/mapstyle.ts b/src/mapstyle.ts index 8c2197cc..035ad9bf 100644 --- a/src/mapstyle.ts +++ b/src/mapstyle.ts @@ -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 } @@ -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, diff --git a/src/tools.ts b/src/tools.ts index 4ea0069e..580040cf 100644 --- a/src/tools.ts +++ b/src/tools.ts @@ -18,7 +18,7 @@ export function enableRTL() { if (status === "unavailable" || status === "requested") { try { maplibregl.setRTLTextPlugin(defaults.rtlPluginURL, true); - } catch (e) { + } catch (_e) { // nothing } } @@ -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, }; @@ -111,7 +111,7 @@ export function isUUID(s: string): boolean { export function jsonParseNoThrow(doc: string): T | null { try { return JSON.parse(doc); - } catch (e) { + } catch (_e) { // pass } @@ -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 { - const regex = /\{name(?:\:(?\S+))?\}/g; + const regex = /\{name(?::(?\S+))?\}/g; const languageUsed = [] as Array; while (true) {