-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy patheslint.config.mjs
More file actions
159 lines (140 loc) · 4.26 KB
/
eslint.config.mjs
File metadata and controls
159 lines (140 loc) · 4.26 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// @ts-check
import eslint from '@eslint/js';
import { defineConfig } from 'eslint/config';
import tseslint from 'typescript-eslint';
import only_warn from 'eslint-plugin-only-warn';
import no_relative_import_paths from 'eslint-plugin-no-relative-import-paths';
import { importX } from 'eslint-plugin-import-x';
import eslintPluginSvelte from 'eslint-plugin-svelte';
import obsidianmd from 'eslint-plugin-obsidianmd';
const projectConfig = {
corePackages: ['core'],
packages: ['obsidian', 'publish'],
};
/** @type {{files: string[], rules: Record<string, [string, {patterns: {group: string[], message: string }[]}]>}[]} */
const overrides = [];
for (const corePackage of projectConfig.corePackages) {
const patterns = [];
for (const nonCorePackage of projectConfig.packages) {
patterns.push({
group: [`packages/${nonCorePackage}/*`],
message: `Core package "${corePackage}" should not import from the non core "${nonCorePackage}" package.`,
});
}
patterns.push({
group: [`obsidian`],
message: `Core package "${corePackage}" should not import from the "obsidian" package.`,
});
overrides.push({
files: [`packages/${corePackage}/src/**/*.ts`],
rules: {
'no-restricted-imports': [
'error',
{
patterns: patterns,
},
],
},
});
}
for (const nonCorePackage of projectConfig.packages) {
const patterns = [];
for (const otherNonCorePackage of projectConfig.packages) {
if (otherNonCorePackage === nonCorePackage) {
continue;
}
patterns.push({
group: [`packages/${otherNonCorePackage}/*`],
message: `Non core package "${nonCorePackage}" should not import from the non core "${otherNonCorePackage}" package.`,
});
}
overrides.push({
files: [`packages/${nonCorePackage}/src/**/*.ts`],
rules: {
'no-restricted-imports': [
'error',
{
patterns: patterns,
},
],
},
});
}
const flatOverrides = overrides.map(o => ({
files: o.files,
restrictedImports: o.rules['no-restricted-imports'][1].patterns.map(p => p.group).flat(),
}));
console.log('Import restrictions:');
console.log(flatOverrides);
export default defineConfig(
{
ignores: ['npm/', 'node_modules/', 'exampleVault/', 'automation/', 'main.js', '**/*.svelte', '**/*.d.ts'],
},
...eslintPluginSvelte.configs['flat/recommended'],
...eslintPluginSvelte.configs['flat/prettier'],
{
files: ['packages/**/*.ts'],
extends: [
eslint.configs.recommended,
...tseslint.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.stylisticTypeChecked,
],
languageOptions: {
parser: tseslint.parser,
parserOptions: {
project: true,
},
},
plugins: {
// @ts-ignore
'only-warn': only_warn,
'no-relative-import-paths': no_relative_import_paths,
import: importX,
obsidianmd: obsidianmd,
},
rules: {
'no-duplicate-imports': ['warn', { allowSeparateTypeImports: true }],
'@typescript-eslint/no-explicit-any': ['warn'],
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
destructuredArrayIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
'@typescript-eslint/consistent-type-imports': [
'error',
{ prefer: 'type-imports', fixStyle: 'separate-type-imports' },
],
'import/consistent-type-specifier-style': ['error', 'prefer-top-level'],
'import/order': [
'error',
{
'newlines-between': 'never',
alphabetize: { order: 'asc', orderImportKind: 'asc', caseInsensitive: true },
},
],
'@typescript-eslint/no-confusing-void-expression': ['error', { ignoreArrowShorthand: true }],
'@typescript-eslint/restrict-template-expressions': 'off',
'no-relative-import-paths/no-relative-import-paths': ['warn', { allowSameFolder: false }],
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-inferrable-types': 'off',
'@typescript-eslint/explicit-function-return-type': ['warn'],
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/no-unused-expressions': [
'warn',
{
allowShortCircuit: true,
},
],
// ...Object.keys(obsidianmd.rules).map(ruleName => ({
// [`obsidianmd/${ruleName}`]: ['warn'],
// })).reduce((acc, cur) => ({ ...acc, ...cur }), {}),
},
},
...overrides,
);