-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy patheslint.config.js
More file actions
135 lines (130 loc) · 5.24 KB
/
eslint.config.js
File metadata and controls
135 lines (130 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";
import { defineConfig, globalIgnores } from "eslint/config";
import tseslint from "typescript-eslint";
export default defineConfig(
globalIgnores(["dist/", "vite.config*.ts", "**/eslint.config.js", "tmp/"]),
// https://typescript-eslint.io/getting-started/typed-linting/
tseslint.configs.strictTypeChecked,
tseslint.configs.stylisticTypeChecked,
tseslint.configs.recommendedTypeChecked,
{
// forked from https://www.npmjs.com/package/eslint-plugin-restrict-imports
plugins: {
import: {
rules: {
"default-imports-only": {
meta: {
type: "suggestion",
docs: {},
schema: [
{
bannedImport: {
locations: ["filePaths"],
message: "string",
fixedLocation: "string",
},
},
],
},
create: function (context) {
const filePath = context.filename;
const options = context.options[0] ?? {
"^/(.*)": {
locations: ["(.*)"],
},
};
return {
ImportDeclaration: (node) => {
Object.entries(options).forEach(([bannedImport, config]) => {
const importLocationRegex = new RegExp(bannedImport);
if (config.ignoreTypeImports && node.importKind === "type") return;
if (importLocationRegex.test(node.source.value)) {
config.locations.forEach((fp) => {
const bannedLocationRegex = new RegExp(fp);
if (bannedLocationRegex.test(filePath)) {
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,
});
}
});
}
});
}
});
},
};
},
},
},
},
},
rules: {
"@typescript-eslint/no-namespace": "off",
"import/default-imports-only": [
"error",
{
"maplibre-gl$": {
locations: ["^(?!.*\.d\.ts$).*\.((ts|js))$"],
message: `Maplibre-gl uses CJS modules, only default imports are supported, named imports may fail on some setups.`,
ignoreTypeImports: true,
},
},
],
},
},
{
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
allowDefaultProject: [],
},
},
},
// https://github.com/prettier/eslint-plugin-prettier
eslintPluginPrettierRecommended,
//
{
rules: {
"@typescript-eslint/array-type": "off",
"@typescript-eslint/consistent-indexed-object-style": "warn",
"@typescript-eslint/consistent-type-definitions": "off",
"@typescript-eslint/no-base-to-string": "warn",
"@typescript-eslint/no-confusing-void-expression": "warn",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-empty-function": "warn", // this is to satisfy maplibre-gl custom layer interface
"@typescript-eslint/no-floating-promises": "warn",
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-misused-promises": "warn",
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "off",
"@typescript-eslint/no-unnecessary-condition": "warn",
"@typescript-eslint/no-unnecessary-type-arguments": "off",
"@typescript-eslint/no-unnecessary-type-assertion": "off",
"@typescript-eslint/no-unnecessary-type-parameters": "off",
"@typescript-eslint/no-unused-vars": "warn",
"@typescript-eslint/no-unsafe-argument": "warn",
"@typescript-eslint/no-unsafe-assignment": "warn",
"@typescript-eslint/no-unsafe-call": "warn",
"@typescript-eslint/no-unsafe-enum-comparison": "off",
"@typescript-eslint/no-unsafe-member-access": "warn",
"@typescript-eslint/no-unsafe-return": "warn",
"@typescript-eslint/no-non-null-assertion": "warn",
"@typescript-eslint/non-nullable-type-assertion-style": "warn",
"@typescript-eslint/prefer-for-of": "off",
"@typescript-eslint/prefer-nullish-coalescing": "warn",
"@typescript-eslint/prefer-optional-chain": "off",
"@typescript-eslint/prefer-return-this-type": "off",
"@typescript-eslint/prefer-string-starts-ends-with": "warn",
"@typescript-eslint/restrict-plus-operands": "warn",
"@typescript-eslint/restrict-template-expressions": "warn",
"@typescript-eslint/related-getter-setter-pairs": "off",
"@typescript-eslint/unbound-method": "warn",
"@typescript-eslint/use-unknown-in-catch-callback-variable": "warn",
},
},
//
);