-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy patheslint.config.mjs
138 lines (125 loc) · 3.38 KB
/
eslint.config.mjs
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
136
137
138
// @ts-check
import path from 'node:path'
import { fileURLToPath } from 'url'
import tseslint from 'typescript-eslint'
import eslintConfig3YD from '@3yourmind/eslint-config'
import kottiUIPackageJSON from './packages/kotti-ui/package.json' assert { type: 'json' }
import vueUseTippyPackageJSON from './packages/vue-use-tippy/package.json' assert { type: 'json' }
import yocoPackageJSON from './packages/yoco/package.json' assert { type: 'json' }
const trustedDependencies = new Set([
'@metatypes/typography',
'@metatypes/units',
'@tanstack/table-core',
'filesize',
'nanoid',
'zod',
])
const notYetESMCompatible = Object.keys({
...kottiUIPackageJSON.dependencies,
...vueUseTippyPackageJSON.dependencies,
...yocoPackageJSON.dependencies,
})
.filter((dep) => !dep.startsWith('@3yourmind'))
.filter((dep) => !trustedDependencies.has(dep))
/**
* Find the project root in a way that is compatible with most javascript engines (e.g. node, vscode's node, bun)
*/
const root = (() => {
const cause = []
try {
const result = __dirname
if (result) return result
} catch (error) {
cause.push(error)
}
try {
const result = import.meta.dirname
if (result) return result
} catch (error) {
cause.push(error)
}
try {
const result = path.dirname(fileURLToPath(import.meta.url))
if (result) return result
} catch (error) {
cause.push(error)
}
throw new Error('could not determine project root', { cause })
})()
const config = tseslint.config(
/**
* DO NOT ADD ANY OTHER KEYS TO THIS FIRST OBJECT
*
* @see {@link https://eslint.org/docs/latest/use/configure/ignore#ignoring-files}
*/
{
ignores: [
'**/dist/**',
'**/.nuxt/**',
'**/.turbo/**',
'**/*.js',
'**/vite.config.ts.timestamp-*', // used by vite to interpret vite.config.ts
],
},
...eslintConfig3YD.configs.global,
{
languageOptions: {
ecmaVersion: 2022,
parserOptions: {
projectService: {
allowDefaultProject: ['*.mjs'],
defaultProject: 'tsconfig.json',
},
tsconfigRootDir: root,
},
sourceType: 'module',
},
},
...eslintConfig3YD.configs.default.map((config) => ({
...config,
files: ['packages/**/*.ts', 'packages/**/*.tsx'],
})),
...eslintConfig3YD.configs.untyped,
...eslintConfig3YD.configs.json,
...eslintConfig3YD.configs.tests.map((config) => ({
...config,
files: [...config.files, 'packages/kotti-ui/source/test-utils/**/*.ts'],
})),
{
extends: eslintConfig3YD.configs.vue,
rules: {
'vue/no-deprecated-dollar-listeners-api': 'error',
},
},
{
rules: {
'@typescript-eslint/no-restricted-imports': [
'error',
{
paths: [
{
message:
"Avoid direct imports from lodash; e.g. import foo from 'lodash/foo.js' instead of import { foo } from 'lodash'",
name: 'lodash',
},
...notYetESMCompatible.map((name) => ({
allowImportNames: ['default'],
allowTypeImports: true,
message:
'The default import is the only export guaranteed to resolve in packages without explicit cjs/esm import declarations. Named imports, inferred through heuristics, may fail in various environments. Therefore, it is advisable to always use the default import.',
name,
})),
],
},
],
'@typescript-eslint/prefer-namespace-keyword': 'off',
},
},
{
files: ['packages/kotti-ui/source/*/index.ts'],
rules: {
'@typescript-eslint/naming-convention': 'off',
},
},
)
export default config