Skip to content

Commit 8e1687b

Browse files
lesbaaLes Moffat
and
Les Moffat
authored
Rd 864 unified linting config (#201)
* RD-864 Update lint config and migrate eslint config to typescript * RD-864 Remove unused config file * RD-864 - Add vite plugin to copy lint config across - add additional files to .npmignore - convert lint config to .mjs * RD-864 - Convert demos eslint config to mjs - re-add- demos to tsconfig * RD-924 Rename eslint.config.ts to mjs again (overridden by merge changes) * RD 924 Fix linting and ts build errors --------- Co-authored-by: Les Moffat <les.moffat@maptiler.com>
1 parent 94d1f3a commit 8e1687b

File tree

6 files changed

+40
-24
lines changed

6 files changed

+40
-24
lines changed

.npmignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
docs
22
docsmd
33
images
4+
demos
45
scripts
56
test
67
demos
@@ -11,4 +12,6 @@ src
1112
*.tgz
1213
.github
1314
.vscode
14-
build
15+
build
16+
vite.config-*
17+
vite-setup-tests.ts

demos/eslint.config.ts renamed to demos/eslint.config.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
// @ts-nocheck
2+
13
import tseslint from "typescript-eslint";
2-
import baseConfig from "../eslint.config";
4+
import baseConfig from "../eslint.config.mjs";
35

46
export default tseslint.config(baseConfig, {
57
rules: {

eslint.config.ts renamed to eslint.config.mjs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,8 @@
1-
// @ts-check
1+
// @ts-nocheck
22

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-
186
export default tseslint.config(
197
// https://typescript-eslint.io/getting-started/typed-linting/
208
tseslint.configs.strictTypeChecked,
@@ -39,7 +27,7 @@ export default tseslint.config(
3927
},
4028
],
4129
},
42-
create: function (context: RuleContext<"bannedImport", Node[]>) {
30+
create: function (context) {
4331
const filePath = context.getFilename();
4432
const options = context.options[0] || {
4533
"^/(.*)": {
@@ -48,8 +36,8 @@ export default tseslint.config(
4836
};
4937

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

5543
if (config.ignoreTypeImports && node.importKind === "type") return;

tsconfig.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,19 @@
2424
"allowSyntheticDefaultImports": true,
2525
"allowJs": true,
2626
},
27+
"exclude": [
28+
"vite.config-*.ts",
29+
"vitest-setup-tests.ts",
30+
"dist"
31+
],
2732
"include": [
28-
"demos",
33+
"vite.config-dev.ts",
34+
"vite.config-es.ts",
35+
"vite.config-umd.ts",
36+
"vite.config-test.ts",
37+
"vitest-setup-tests.ts",
2938
"src",
30-
"test",
31-
"./vite.config-test.ts",
32-
"./vitest-setup-tests.ts"
39+
"demos",
40+
"test"
3341
],
3442
}

vite.config-es.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,25 @@ import { resolve } from 'path';
22
import { defineConfig } from 'vite';
33
import dts from 'vite-plugin-dts';
44
import packagejson from "./package.json";
5+
import { copyFileSync } from 'fs';
56

67
const isProduction = process.env.NODE_ENV === "production";
78

9+
function copyLinterConfig() {
10+
return {
11+
name: 'copy-linter-config',
12+
writeBundle() {
13+
const sourcePath = resolve(import.meta.dirname, 'eslint.config.mjs');
14+
const destPath = resolve(import.meta.dirname, 'dist/eslint.mjs');
15+
console.log(`Copying ${sourcePath} to ${destPath}`);
16+
copyFileSync(sourcePath, destPath);
17+
}
18+
}
19+
}
20+
821
const plugins = [
922
dts({insertTypesEntry: true}),
23+
copyLinterConfig(),
1024
];
1125

1226
export default defineConfig({
@@ -17,11 +31,12 @@ export default defineConfig({
1731
outDir: "dist",
1832
sourcemap: true,
1933
lib: {
34+
2035
// Could also be a dictionary or array of multiple entry points
2136
entry: resolve(__dirname, 'src/index.ts'),
2237
name: 'maptilersdk',
2338
// the proper extensions will be added
24-
fileName: (format, entryName) => "maptiler-sdk.mjs",
39+
fileName: (_, __) => "maptiler-sdk.mjs",
2540
formats: ['es'],
2641
},
2742

vite.config-umd.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default defineConfig({
1414
lib: {
1515
entry: resolve(__dirname, 'src/index.ts'),
1616
name: 'maptilersdk',
17-
fileName: (format, entryName) => "maptiler-sdk.umd.min.js",
17+
fileName: (_, __) => "maptiler-sdk.umd.min.js",
1818
formats: ['umd'],
1919
}
2020
},

0 commit comments

Comments
 (0)