generated from obsidianmd/obsidian-sample-plugin
-
-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy patheslint.config.mjs
143 lines (126 loc) · 3.78 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
139
140
141
142
143
// @ts-check
import eslint from '@eslint/js';
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 * as plugin_import from 'eslint-plugin-import';
import eslintPluginSvelte from 'eslint-plugin-svelte';
import projectConfig from './automation/config.json' with { type: 'json' };
/** @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.`,
});
}
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 tseslint.config(
{
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: plugin_import,
},
rules: {
'@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,
},
],
},
},
...overrides,
);