-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patheslint.config.mts
More file actions
134 lines (132 loc) · 3.87 KB
/
eslint.config.mts
File metadata and controls
134 lines (132 loc) · 3.87 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
// Synced from obsidian-boiler-template/tooling/shared/eslint.config.mts. Do not edit this file directly.
import tseslint from 'typescript-eslint';
import obsidianmd from 'eslint-plugin-obsidianmd';
import globals from 'globals';
import { globalIgnores } from 'eslint/config';
let vitestPlugin = null;
try {
const imported = await import('eslint-plugin-vitest');
vitestPlugin = imported.default ?? imported;
} catch {
vitestPlugin = null;
}
export default tseslint.config(
{
languageOptions: {
globals: { ...globals.browser, ...globals.nodeBuiltin },
parserOptions: {
projectService: {
allowDefaultProject: ['eslint.config.js', 'vitest.config.ts', 'manifest.json'],
},
tsconfigRootDir: import.meta.dirname,
extraFileExtensions: ['.json'],
},
},
},
...obsidianmd.configs.recommended,
// Disable depend/ban-dependencies -- too aggressive for the plugin ecosystem
// (flags legitimate devDeps like lint-staged, builtin-modules).
{
rules: {
'depend/ban-dependencies': 'off',
},
},
// Ban common async/type hazards in non-test TypeScript code.
{
files: ['**/*.ts', '**/*.mts'],
ignores: [
'test/**/*.ts',
'__tests__/**/*.ts',
'**/*.d.ts',
'*.config.ts',
'*.config.mts',
'*.config.js',
'*.config.mjs',
'**/*.config.ts',
'**/*.config.mts',
'**/*.config.js',
'**/*.config.mjs',
],
plugins: { '@typescript-eslint': tseslint.plugin },
rules: {
'@typescript-eslint/no-misused-promises': ['error', {
checksConditionals: true,
checksSpreads: true,
checksVoidReturn: {
arguments: true,
attributes: true,
properties: true,
returns: false,
variables: true,
},
}],
'@typescript-eslint/no-redundant-type-constituents': 'error',
'@typescript-eslint/require-await': 'error',
},
},
// Layer enforcement: domain/, types/, utils/ must not import from obsidian.
{
files: ['src/domain/**/*.ts', 'src/types/**/*.ts', 'src/utils/**/*.ts'],
ignores: ['**/*.d.ts'],
rules: {
'no-restricted-imports': ['error', {
patterns: [{
group: ['obsidian', 'obsidian/*'],
message: 'domain/, types/, and utils/ layers must not import from obsidian. Move this code to ui/ or inject the dependency.',
}],
}],
},
},
// Worker files: run in Web Worker / Node-like context, need node globals (Buffer, process).
{
files: ['worker/**/*.ts'],
languageOptions: {
globals: { ...globals.node },
},
},
// Config files: legitimately import Node.js built-in modules.
{
files: ['*.config.ts', '*.config.mts', '*.config.js', '*.config.mjs'],
rules: {
'import/no-nodejs-modules': 'off',
},
},
// Script files (.mjs): run in Node.js, need node globals.
{
files: ['scripts/**/*.mjs', 'tooling/**/*.mjs', '*.mjs'],
languageOptions: {
globals: { ...globals.node },
},
rules: {
'import/no-nodejs-modules': 'off',
},
},
// Test files: relax rules that don't apply to test code.
{
files: ['test/**/*.ts', '__tests__/**/*.ts'],
plugins: vitestPlugin ? { vitest: vitestPlugin } : {},
languageOptions: {
globals: { ...globals.node },
},
rules: {
...(vitestPlugin ? {
'vitest/expect-expect': 'error',
'vitest/no-disabled-tests': 'warn',
'vitest/no-conditional-tests': 'error',
} : {}),
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-misused-promises': 'off',
'@typescript-eslint/no-redundant-type-constituents': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/unbound-method': 'off',
'obsidianmd/hardcoded-config-path': 'off',
'import/no-nodejs-modules': 'off',
},
},
globalIgnores(['**/main.js', 'dist/', 'node_modules/', 'coverage/']),
);