-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.mjs
More file actions
225 lines (200 loc) · 6.95 KB
/
eslint.config.mjs
File metadata and controls
225 lines (200 loc) · 6.95 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
import js from '@eslint/js';
import globals from 'globals';
import prettierPlugin from 'eslint-plugin-prettier';
import prettierConfig from 'eslint-config-prettier';
export default [
// Ignore patterns
{
ignores: [
'web/**/*', // Frontend has its own ESLint config
'node_modules/**/*', // Dependencies
'dist/**/*', // Build output
'build/**/*', // Build output
'coverage/**/*', // Test coverage
'*.min.js', // Minified files
'packaging/**/*', // Packaging files
'docs/**/*', // Documentation
'logs/**/*', // Log files
'**/*.log', // Log files
],
},
// JavaScript files configuration - Comprehensive Node.js Backend Rules
{
files: ['**/*.{js,mjs,cjs}'],
languageOptions: {
ecmaVersion: 2024, // Latest ECMAScript version
sourceType: 'module',
globals: {
...globals.node,
...globals.es2021,
},
},
plugins: {
prettier: prettierPlugin,
},
rules: {
// Base JavaScript rules (recommended + enhanced)
...js.configs.recommended.rules,
...prettierConfig.rules,
'prettier/prettier': 'error',
// === VARIABLES & DECLARATIONS ===
'prefer-const': 'error',
'no-var': 'error',
'no-undef': 'error',
'no-unused-vars': [
'error',
{
vars: 'all',
args: 'all',
caughtErrors: 'all',
ignoreRestSiblings: false,
reportUsedIgnorePattern: false,
},
],
'no-use-before-define': ['error', { functions: false, classes: true, variables: true }],
'no-shadow': 'error',
'no-shadow-restricted-names': 'error',
'no-redeclare': 'error',
// === FUNCTIONS ===
'func-style': ['error', 'expression', { allowArrowFunctions: true }],
'prefer-arrow-callback': 'error',
'arrow-body-style': ['error', 'as-needed'],
'no-loop-func': 'error',
'no-new-func': 'error',
'default-param-last': 'error',
'no-param-reassign': ['error', { props: false }],
// === OBJECTS & ARRAYS ===
'object-shorthand': ['error', 'always'],
'prefer-destructuring': ['error', { array: true, object: true }],
'no-array-constructor': 'error',
'array-callback-return': ['error', { allowImplicit: true }],
'prefer-spread': 'error',
'prefer-rest-params': 'error',
// === STRINGS & TEMPLATES ===
'prefer-template': 'error',
'no-useless-escape': 'error',
'no-useless-concat': 'error',
// === COMPARISON & CONDITIONALS ===
eqeqeq: ['error', 'always'],
'no-nested-ternary': 'warn',
'no-unneeded-ternary': 'error',
'no-else-return': 'error',
'consistent-return': 'error',
// === ERROR HANDLING ===
'no-throw-literal': 'error',
'prefer-promise-reject-errors': 'error',
'no-return-await': 'error',
// === ASYNC/AWAIT & PROMISES ===
'require-await': 'error',
'no-await-in-loop': 'warn',
'no-async-promise-executor': 'error',
'no-promise-executor-return': 'error',
// === MODULES ===
'no-duplicate-imports': 'error',
'no-useless-rename': 'error',
// === SECURITY & BEST PRACTICES ===
'no-eval': 'error',
'no-implied-eval': 'error',
'no-script-url': 'error',
'no-caller': 'error',
'no-iterator': 'error',
'no-proto': 'error',
'no-extend-native': 'error',
'no-global-assign': 'error',
// === NODE.JS SPECIFIC ===
'no-process-exit': 'error',
'no-process-env': 'off', // Allow process.env in config files
'no-console': 'off', // Allow console in backend (now using Winston)
// === CODE QUALITY ===
complexity: ['warn', 30], // Warn on high cyclomatic complexity
'max-depth': ['warn', 6], // Warn on deeply nested code
'max-params': ['warn', 8], // Warn on functions with many parameters
// === NAMING CONVENTIONS ===
camelcase: 'off', // Allow snake_case for system/API code
'new-cap': ['error', { newIsCap: true, capIsNew: false }],
// === PERFORMANCE ===
'no-lonely-if': 'error',
'no-useless-call': 'error',
'no-useless-return': 'error',
'no-useless-constructor': 'error',
// === MODERN JAVASCRIPT ===
'prefer-object-spread': 'error',
'prefer-exponentiation-operator': 'error',
'prefer-numeric-literals': 'error',
'prefer-object-has-own': 'error',
// === DOCUMENTATION ===
'valid-jsdoc': 'off', // Deprecated in favor of JSDoc tools
'require-jsdoc': 'off', // Optional, let developers decide
// === STYLE (handled by Prettier, but keep logical ones) ===
curly: ['error', 'all'], // Always use braces
'dot-notation': 'error',
'no-multi-assign': 'error',
'one-var': ['error', 'never'], // One variable declaration per statement
// === REGEX ===
'prefer-named-capture-group': 'warn',
'prefer-regex-literals': 'error',
'no-useless-backreference': 'error',
// === IMPORT/EXPORT ===
'no-restricted-imports': [
'error',
{
patterns: ['../**/node_modules/**'], // Prevent reaching into node_modules
},
],
// === DEBUGGING ===
'no-debugger': 'warn', // Allow in development but warn
'no-alert': 'error', // No alerts in Node.js
// === UNICODE & SPECIAL CHARACTERS ===
'unicode-bom': ['error', 'never'],
'no-irregular-whitespace': 'error',
},
},
// Test files configuration
{
files: ['**/*.test.js', '**/*.spec.js', '**/test/**/*.js', '**/tests/**/*.js'],
languageOptions: {
globals: {
...globals.jest,
...globals.mocha,
...globals.node,
},
},
rules: {
// Relax rules for test files
'no-console': 'off',
'no-unused-expressions': 'off',
'max-lines': 'off',
'max-lines-per-function': 'off',
'no-magic-numbers': 'off',
'prefer-arrow-callback': 'off', // Mocha doesn't play well with arrow functions
'func-style': 'off',
},
},
// Configuration files
{
files: ['**/config/**/*.js', '**/*.config.js', '**/*.config.mjs'],
rules: {
'no-process-env': 'off', // Allow process.env in config files
'no-magic-numbers': 'off', // Allow magic numbers in configs
},
},
// Browser JavaScript files - provide necessary globals
{
files: ['web/public/**/*.js'],
languageOptions: {
ecmaVersion: 2024,
sourceType: 'script',
globals: {
...globals.browser,
SwaggerUIBundle: 'readonly',
bootstrap: 'readonly',
MutationObserver: 'readonly',
InputEvent: 'readonly',
EventSource: 'readonly',
},
},
rules: {
'no-console': 'off', // Allow console in browser for debugging
},
},
];