-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy patheslint.config.mjs
More file actions
166 lines (154 loc) · 5.81 KB
/
eslint.config.mjs
File metadata and controls
166 lines (154 loc) · 5.81 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
160
161
162
163
164
165
166
import js from '@eslint/js';
import globals from 'globals';
import tseslint from '@typescript-eslint/eslint-plugin';
import tsparser from '@typescript-eslint/parser';
import obsidianmd from 'eslint-plugin-obsidianmd';
export default [
js.configs.recommended,
{
files: ['**/*.ts', '**/*.tsx'],
languageOptions: {
parser: tsparser,
parserOptions: {
sourceType: 'module',
project: './tsconfig.json'
},
globals: globals.browser
},
plugins: {
'@typescript-eslint': tseslint,
'obsidianmd': obsidianmd
},
rules: {
...tseslint.configs.recommended.rules,
// ==================== TypeScript Official Rules ====================
// 禁止未使用的变量,但允许未使用的参数
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['error', { args: 'none' }],
// 允许使用 @ts-ignore 等注释
'@typescript-eslint/ban-ts-comment': 'off',
// 允许直接使用原型方法
'no-prototype-builtins': 'off',
// 允许空函数
'@typescript-eslint/no-empty-function': 'off',
// 允许使用 any 类型
'@typescript-eslint/no-explicit-any': 'off',
// ==================== Custom Rules ====================
// 允许显式声明可推断的类型
'@typescript-eslint/no-inferrable-types': 'off',
// 允许混合使用空格和制表符
'no-mixed-spaces-and-tabs': 'off',
'sort-imports': [ // 强制导入语句排序
'error',
{
ignoreCase: true, // 忽略大小写
ignoreDeclarationSort: true, // 忽略声明排序
ignoreMemberSort: false, // 不忽略成员排序
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'] // 成员语法排序顺序
}
],
// ==================== Obsidianmd Rules ====================
// ====== 命令相关规则 ======
// 禁止在命令 ID 中使用 'command' 单词
'obsidianmd/commands/no-command-in-command-id': 'error',
// 禁止在命令名称中使用 'command' 单词
'obsidianmd/commands/no-command-in-command-name': 'error',
// 不建议为命令提供默认热键
'obsidianmd/commands/no-default-hotkeys': 'warn',
// 禁止在命令 ID 中包含插件 ID
'obsidianmd/commands/no-plugin-id-in-command-id': 'error',
// 禁止在命令名称中包含插件名称
'obsidianmd/commands/no-plugin-name-in-command-name': 'error',
// ====== 内存泄漏防护规则 ======
// 在 onunload 中不要分离叶子节点
'obsidianmd/detach-leaves': 'error',
// 禁止将插件作为组件传递给 MarkdownRenderer.render
'obsidianmd/no-plugin-as-component': 'error',
// 禁止在插件中直接存储自定义视图的引用
'obsidianmd/no-view-references-in-plugin': 'error',
// ====== 代码质量规则 ======
// 禁止使用模板中的示例代码
'obsidianmd/no-sample-code': 'error',
// 禁止直接在 DOM 元素上设置样式,建议使用 CSS 类
'obsidianmd/no-static-styles-assignment': 'error',
// 禁止类型转换为 TFile 或 TFolder,建议使用 instanceof 检查
'obsidianmd/no-tfile-tfolder-cast': 'error',
// 禁止在 Obsidian 插件中向 DOM 附加禁止的元素
'obsidianmd/no-forbidden-elements': 'error',
// ====== API 使用最佳实践 ======
// 优先使用 FileManager.trashFile() 而不是 Vault.trash() 或 Vault.delete()
'obsidianmd/prefer-file-manager-trash-file': 'error',
// 建议使用内置的 AbstractInputSuggest 而不是常见的 TextInputSuggest 实现
'obsidianmd/prefer-abstract-input-suggest': 'warn',
// 避免遍历所有文件来按路径查找文件
'obsidianmd/vault/iterate': 'warn',
// ====== 平台兼容性规则 ======
// 禁止使用 navigator API 进行操作系统检测
'obsidianmd/platform': 'error',
// 禁止在正则表达式中使用后行断言(某些 iOS 版本不支持)
'obsidianmd/regex-lookbehind': 'error',
// ====== 其他规则 ======
// 不建议使用带有两个参数的 Object.assign
'obsidianmd/object-assign': 'warn',
// 重命名示例插件类名
'obsidianmd/sample-names': 'error',
// 验证 LICENSE 文件中版权声明的结构
'obsidianmd/validate-license': 'error',
// 验证 manifest.json 的结构
'obsidianmd/validate-manifest': 'error',
// ====== 设置页面规则 ======
// 禁止在设置页面中使用手动创建的 HTML 标题元素
'obsidianmd/settings-tab/no-manual-html-headings': 'error',
// 避免设置标题中的反模式
'obsidianmd/settings-tab/no-problematic-settings-headings': 'error',
// ====== UI 文本规范 ======
'obsidianmd/ui/sentence-case': ['warn', { // 强制 UI 字符串使用句子大小写
brands: [], // 品牌名称例外列表
acronyms: ['API', 'UI', 'URL', 'HTML', 'CSS', 'JS', 'TS', 'SVG', 'PDF', 'JPG'], // 首字母缩写词例外列表
enforceCamelCaseLower: true // 强制 CamelCase 转换为小写
}]
}
},
{
files: ['test/**/*.ts'],
languageOptions: {
parser: tsparser,
parserOptions: {
sourceType: 'module',
project: './tsconfig.json'
},
globals: {
...globals.browser,
...globals.jest
}
},
plugins: {
'@typescript-eslint': tseslint
},
rules: {
...tseslint.configs.recommended.rules,
// official rules
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['error', { args: 'none' }],
'@typescript-eslint/ban-ts-comment': 'off',
'no-prototype-builtins': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-explicit-any': 'off',
// custom rules
'@typescript-eslint/no-inferrable-types': 'off',
'no-mixed-spaces-and-tabs': 'off',
'sort-imports': [
'error',
{
ignoreCase: true,
ignoreDeclarationSort: true,
ignoreMemberSort: false,
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single']
}
]
}
},
{
ignores: ['node_modules/**', 'main.js', 'scripts/**', '*.js']
}
];