-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy patheslint.config.mjs
More file actions
227 lines (226 loc) · 8.15 KB
/
eslint.config.mjs
File metadata and controls
227 lines (226 loc) · 8.15 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
import js from '@eslint/js';
import tseslint from 'typescript-eslint';
import prettier from 'eslint-plugin-prettier/recommended';
import importPlugin from 'eslint-plugin-import';
import simpleImportSort from 'eslint-plugin-simple-import-sort';
import react from 'eslint-plugin-react';
import reactHooks from 'eslint-plugin-react-hooks';
import jsxA11y from 'eslint-plugin-jsx-a11y';
import security from 'eslint-plugin-security';
import noSecrets from 'eslint-plugin-no-secrets';
import electron from 'eslint-plugin-electron';
export default tseslint.config(
{
ignores: [
'**/dist/**',
'**/build/**',
'**/out/**',
'**/node_modules/**',
'eslint.config.mjs',
'**/*.d.ts',
'eslint.config.*',
'vitest.config.ts',
'vite.config.ts',
'*.config.{ts,js,mjs,cjs}',
'dist-electron/**',
],
},
js.configs.recommended,
...tseslint.configs.recommendedTypeChecked,
...tseslint.configs.stylisticTypeChecked,
...tseslint.configs.strictTypeChecked,
{
files: ['**/*.{ts,tsx,mts,cts}'],
languageOptions: {
parserOptions: {
project: ['./tsconfig.json', './tsconfig.main.json'],
tsconfigRootDir: import.meta.dirname,
},
},
},
prettier,
{
plugins: {
'simple-import-sort': simpleImportSort,
import: importPlugin,
},
rules: {
// Disallow dangerous child_process patterns project-wide
'no-restricted-imports': [
'error',
{
name: 'child_process',
importNames: ['exec', 'execSync'],
message: 'Use safer project helpers or spawn-style APIs instead of these functions.',
},
],
'no-restricted-syntax': [
'error',
{
selector:
"CallExpression[callee.type='MemberExpression'][callee.object.name='child_process'][callee.property.name=/^exec(Sync)?$/]",
message: 'Avoid using child_process methods that execute shell commands directly.',
},
{
selector:
"CallExpression[callee.type='MemberExpression'][callee.object.name='child_process'][callee.property.name=/^(spawn|spawnSync|execFile|execFileSync)$/] > ObjectExpression > Property[key.name='shell'] > Literal[value=true]",
message: 'Avoid shell: true; use direct process execution with argument arrays instead.',
},
],
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
'import/first': 'off',
'import/newline-after-import': 'error',
'import/no-duplicates': 'error',
'@typescript-eslint/no-unused-vars': ['error', { caughtErrors: 'all' }],
'@typescript-eslint/consistent-type-imports': 'error',
'prefer-const': 'error',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/no-unsafe-enum-comparison': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/unbound-method': 'off',
// React event handlers often return Promise<void>; void-return check is too strict for JSX attrs.
'@typescript-eslint/no-misused-promises': [
'error',
{ checksVoidReturn: { attributes: false } },
],
// strictTypeChecked enables this, but it flags many defensive DOM/runtime patterns where
// types are narrower than reality; keep other strict rules without churning the whole UI.
'@typescript-eslint/no-unnecessary-condition': 'off',
// Autofix removes generics that TypeScript still needs for inference (tsc errors after
// eslint --fix). Prefer explicit types at those call sites over a blanket autofix.
'@typescript-eslint/no-unnecessary-type-arguments': 'off',
'@typescript-eslint/prefer-nullish-coalescing': [
'error',
{
ignorePrimitives: { string: true, number: true, boolean: true },
ignoreMixedLogicalExpressions: true,
},
],
'no-empty': ['error', { allowEmptyCatch: true }],
'@typescript-eslint/no-empty-function': ['error', { allow: ['arrowFunctions'] }],
},
},
// Node scripts: no TS program — disable type-checked rules; keep security + Node globals
{
files: ['scripts/**/*.{js,cjs,mjs}'],
languageOptions: {
...tseslint.configs.disableTypeChecked.languageOptions,
ecmaVersion: 'latest',
sourceType: 'script',
globals: {
require: 'readonly',
module: 'readonly',
process: 'readonly',
console: 'readonly',
setTimeout: 'readonly',
},
},
rules: {
...tseslint.configs.disableTypeChecked.rules,
'@typescript-eslint/no-require-imports': 'off',
'no-undef': 'off',
'prettier/prettier': 'off',
'simple-import-sort/imports': 'off',
'no-redeclare': 'off',
},
},
// Renderer: React (jsx-runtime) + eslint-plugin-react-hooks flat recommended + jsxA11y
{
files: ['src/renderer/**/*.{ts,tsx}'],
plugins: {
...react.configs.flat['jsx-runtime'].plugins,
...jsxA11y.flatConfigs.recommended.plugins,
...reactHooks.configs.flat.recommended.plugins,
},
languageOptions: {
...react.configs.flat['jsx-runtime'].languageOptions,
...jsxA11y.flatConfigs.recommended.languageOptions,
parserOptions: {
...jsxA11y.flatConfigs.recommended.languageOptions.parserOptions,
project: ['./tsconfig.json', './tsconfig.main.json'],
tsconfigRootDir: import.meta.dirname,
},
},
settings: {
react: { version: 'detect' },
},
rules: {
...react.configs.flat['jsx-runtime'].rules,
...jsxA11y.flatConfigs.recommended.rules,
...reactHooks.configs.flat.recommended.rules,
'react-hooks/exhaustive-deps': 'error',
// Strictness from eslint-plugin-react-hooks v7 flat preset: keep as warn until each
// callsite matches App.tsx-style fixes (effects for ref mirrors, queueMicrotask for
// setState-in-effect, purity for impure render helpers).
'react-hooks/refs': 'warn',
'react-hooks/set-state-in-effect': 'warn',
'react-hooks/purity': 'warn',
},
},
// Security plugin: Node.js security patterns
{
plugins: {
security,
},
rules: {
...security.configs.recommended.rules,
// Disable rules with high false positive rate in this codebase
'security/detect-object-injection': 'off', // Common pattern for data structures
'security/detect-non-literal-fs-filename': 'off', // Scripts use variable paths intentionally
'security/detect-non-literal-regexp': 'off', // Dynamic regex patterns are expected
'security/detect-unsafe-regex': 'off', // Too many false positives for safe patterns
},
},
// No-secrets: detect hardcoded secrets/API keys
{
plugins: {
'no-secrets': noSecrets,
},
rules: {
'no-secrets/no-secrets': [
'error',
{
// Increase tolerance to reduce false positives on function names
tolerance: 4.5,
// Ignore common patterns that are not secrets
ignoreIdentifiers: ['MESHTASTIC_SKIP_ELECTRON_REBUILD'],
ignoreContent: [
// Environment variable names
'^[A-Z_]+$',
],
ignoreModules: true,
ignoreCase: false,
},
],
},
},
// Electron: main/preload process security
{
files: ['src/main/**/*.ts', 'src/preload/**/*.ts'],
plugins: {
electron,
},
rules: {
'electron/no-callbacks': 'error',
'electron/no-deprecated-apis': 'error',
'electron/no-deprecated-props': 'error',
'electron/no-deprecated-arguments': 'off',
'electron/default-value-changed': 'warn',
},
},
// Last: strictTypeChecked enables preserve-caught-error; ESLint may surface it under both names.
{
files: ['**/*.{ts,tsx,mts,cts}'],
rules: {
'preserve-caught-error': 'off',
'@typescript-eslint/preserve-caught-error': 'off',
},
},
);