Skip to content

Commit a64584d

Browse files
lesbaaLes Moffat
andauthored
Rd 864 unified linting config (#198)
* RD-864 Update lint config and migrate eslint config to typescript * RD-864 Remove unused config file --------- Co-authored-by: Les Moffat <[email protected]>
1 parent 476892b commit a64584d

File tree

9 files changed

+43
-17
lines changed

9 files changed

+43
-17
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import tseslint from "typescript-eslint";
2-
import baseConfig from "../eslint.config.mjs";
2+
import baseConfig from "../eslint.config";
33

44
export default tseslint.config(baseConfig, {
55
rules: {

demos/src/03-sky-night.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { Map, config, MapStyle } from "@maptiler/sdk";
1+
import { Map, config, MapStyle } from "../../src";
22
import { addPerformanceStats, setupMapTilerApiKey } from "./demo-utils";
33

44
addPerformanceStats();
55
setupMapTilerApiKey({ config });
6+
67
const container = document.getElementById("map-container")!;
78
const map = new Map({
89
container,
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@
33
import tseslint from "typescript-eslint";
44
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";
55

6+
import { TSESTree } from "@typescript-eslint/utils";
7+
import { RuleContext } from "@typescript-eslint/utils/dist/ts-eslint";
8+
9+
type Node = TSESTree.ImportDeclaration;
10+
11+
type CustomRuleOptions = {
12+
locations: string[];
13+
message?: string;
14+
fixedLocation?: string;
15+
ignoreTypeImports?: boolean;
16+
};
17+
618
export default tseslint.config(
719
// https://typescript-eslint.io/getting-started/typed-linting/
820
tseslint.configs.strictTypeChecked,
@@ -27,7 +39,7 @@ export default tseslint.config(
2739
},
2840
],
2941
},
30-
create: function (context) {
42+
create: function (context: RuleContext<"bannedImport", Node[]>) {
3143
const filePath = context.getFilename();
3244
const options = context.options[0] || {
3345
"^/(.*)": {
@@ -36,8 +48,8 @@ export default tseslint.config(
3648
};
3749

3850
return {
39-
ImportDeclaration: (node) => {
40-
Object.entries(options).forEach(([bannedImport, config]) => {
51+
ImportDeclaration: (node: Node) => {
52+
Object.entries(options).forEach(([bannedImport, config]: [string, CustomRuleOptions]) => {
4153
const importLocationRegex = new RegExp(bannedImport);
4254

4355
if (config.ignoreTypeImports && node.importKind === "type") return;
@@ -50,6 +62,7 @@ export default tseslint.config(
5062
node.specifiers.forEach((specifier) => {
5163
if (specifier.type !== "ImportDefaultSpecifier") {
5264
context.report({
65+
// @ts-expect-error `message` seems to work with this...
5366
message: config.message ?? `Importing from '${bannedImport}' is banned in '${fp}'`,
5467
node,
5568
});

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
"prepare": "husky",
3939
"doc": "rm -rf docs/* && typedoc --out docs && cp -r images docs/",
4040
"ncu": "npx npm-check-updates",
41-
"lint": "eslint src",
42-
"lint:fix": "eslint src --fix",
41+
"lint": "tsc --noEmit && eslint src",
42+
"lint:fix": "tsc --noEmit && eslint src --fix",
4343
"test:watch": "vitest watch -c vite.config-test.ts --dom",
4444
"test": "vitest run -c vite.config-test.ts --dom",
4545
"install:clean": "rm -rf build/ dist/ node_modules/ && npm ci",
@@ -68,6 +68,7 @@
6868
"eslint-plugin-prettier": "^5.2.3",
6969
"happy-dom": "^17.4.4",
7070
"husky": "^8.0.0",
71+
"jiti": "^2.4.2",
7172
"lint-staged": "^15.4.3",
7273
"prettier": "3.5.2",
7374
"stats.js": "^0.17.0",

src/Map.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ export class Map extends maplibregl.Map {
471471

472472
const tileJsonRes = await fetch(styleUrl.href);
473473
tileJsonContent = await tileJsonRes.json();
474-
} catch (e) {
474+
} catch (_e) {
475475
// No tiles.json found (should not happen on maintained styles)
476476
}
477477

src/converters/xml.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -622,22 +622,22 @@ export function gpxOrKml(doc: string | Document): GeoJSON.FeatureCollection | nu
622622
try {
623623
// Converting only once rather than in each converter
624624
if (typeof actualDoc === "string") actualDoc = str2xml(actualDoc);
625-
} catch (e) {
625+
} catch (_e) {
626626
// The doc is a string but not valid XML
627627
return null;
628628
}
629629

630630
try {
631631
const result = gpx(actualDoc);
632632
return result;
633-
} catch (e) {
633+
} catch (_e) {
634634
// The doc is valid XML but not valid GPX
635635
}
636636

637637
try {
638638
const result = kml(actualDoc);
639639
return result;
640-
} catch (e) {
640+
} catch (_e) {
641641
// The doc is valid XML but not valid KML
642642
}
643643

src/mapstyle.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export function urlToAbsoluteUrl(url: string): string {
105105
try {
106106
const u = new URL(url);
107107
return u.href;
108-
} catch (e) {
108+
} catch (_e) {
109109
// nothing to raise
110110
}
111111

@@ -130,7 +130,7 @@ export function convertToStyleSpecificationString(str: string): StyleValidationR
130130
isValidStyle: styleErrs.length === 0,
131131
styleObject: styleErrs.length === 0 ? (styleObj as maplibregl.StyleSpecification) : null,
132132
};
133-
} catch (e) {
133+
} catch (_e) {
134134
return {
135135
isValidJSON: false,
136136
isValidStyle: false,

src/tools.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function enableRTL() {
1818
if (status === "unavailable" || status === "requested") {
1919
try {
2020
maplibregl.setRTLTextPlugin(defaults.rtlPluginURL, true);
21-
} catch (e) {
21+
} catch (_e) {
2222
// nothing
2323
}
2424
}
@@ -46,7 +46,7 @@ export function maptilerCloudTransformRequest(url: string, resourceType?: Resour
4646
// Yet, if it's local we just return it without assuming a 'base' url (in the URL constructor)
4747
// and we let the URL be locally resolved with a potential base path.
4848
reqUrl = new URL(url);
49-
} catch (e) {
49+
} catch (_e) {
5050
return {
5151
url,
5252
};
@@ -111,7 +111,7 @@ export function isUUID(s: string): boolean {
111111
export function jsonParseNoThrow<T>(doc: string): T | null {
112112
try {
113113
return JSON.parse(doc);
114-
} catch (e) {
114+
} catch (_e) {
115115
// pass
116116
}
117117

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

274274
while (true) {

0 commit comments

Comments
 (0)