-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy patheslint.config.js
More file actions
220 lines (189 loc) · 6.99 KB
/
Copy patheslint.config.js
File metadata and controls
220 lines (189 loc) · 6.99 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
/**
* ESLint Configuration for djust
*
* This configuration focuses on security-related linting rules
* to catch potential vulnerabilities in JavaScript code.
*/
import security from "eslint-plugin-security";
export default [
// Global ignores — applies to all configs. Must be in its own config
// block (no `files` key) to be a true global ignore in v9+ flat config.
{
ignores: [
"node_modules/**",
"dist/**",
"build/**",
"target/**",
".venv/**",
"**/*.min.js",
"**/*.min.js.map",
],
},
{
// Apply to all JavaScript files
files: ["**/*.js"],
plugins: {
security,
},
languageOptions: {
ecmaVersion: 2022,
sourceType: "module",
globals: {
// Browser globals
window: "readonly",
document: "readonly",
console: "readonly",
setTimeout: "readonly",
clearTimeout: "readonly",
setInterval: "readonly",
clearInterval: "readonly",
fetch: "readonly",
WebSocket: "readonly",
DOMParser: "readonly",
HTMLElement: "readonly",
MutationObserver: "readonly",
FormData: "readonly",
URLSearchParams: "readonly",
CustomEvent: "readonly",
// djust globals
globalThis: "readonly",
},
},
rules: {
// =======================================================================
// Security Rules (eslint-plugin-security)
// =======================================================================
// Detect eval() usage
"security/detect-eval-with-expression": "error",
// Detect non-literal require() (potential code injection)
"security/detect-non-literal-require": "warn",
// Detect non-literal RegExp (potential ReDoS)
"security/detect-non-literal-regexp": "warn",
// Detect non-literal fs methods (path traversal)
"security/detect-non-literal-fs-filename": "warn",
// Detect child_process usage
"security/detect-child-process": "warn",
// Detect object injection (prototype pollution)
"security/detect-object-injection": "warn",
// Detect possible timing attacks
"security/detect-possible-timing-attacks": "warn",
// Detect pseudoRandomBytes (use crypto.randomBytes)
"security/detect-pseudoRandomBytes": "warn",
// Detect buffer() with noAssert
"security/detect-buffer-noassert": "error",
// Detect unsafe regex
"security/detect-unsafe-regex": "warn",
// =======================================================================
// General Best Practices
// =======================================================================
// Disallow use of eval()
"no-eval": "error",
// Disallow use of implied eval()
"no-implied-eval": "error",
// Disallow new Function()
"no-new-func": "error",
// Disallow script URLs
"no-script-url": "error",
// Disallow with statements
"no-with": "error",
// Require strict mode
"strict": ["error", "global"],
// Disallow unused variables (helps catch mistakes).
// `caughtErrors` covers `catch (_e) { ... }` parameters; without
// an explicit `caughtErrorsIgnorePattern` the rule ignores the
// top-level patterns for catch bindings.
"no-unused-vars": ["warn", {
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"caughtErrors": "all",
"caughtErrorsIgnorePattern": "^_",
}],
// Require const for variables that aren't reassigned
"prefer-const": "warn",
// Disallow var
"no-var": "warn",
// =======================================================================
// djust-Specific Rules
// =======================================================================
// Console logs are OK in djust (debug mode uses them)
"no-console": "off",
},
},
// Top-level scripts loaded as <script src="…"> by Django templates
// (NOT ES modules). These wrap their bodies in IIFEs and use
// `'use strict'` directives — turn off the strict rule here so the
// IIFE-internal directive isn't flagged as redundant. Includes the
// built bundles (client.js, debug-panel.js) plus stand-alone helpers
// (client-dev.js, security.js, etc.).
//
// `reportUnusedDisableDirectives: off` for the BUNDLES — the source
// modules carry `// eslint-disable-next-line prefer-const` for the
// few cross-file reassigned globals (e.g. `liveViewWS`). In the
// concatenated bundle ESLint sees the cross-file reassign and the
// disable becomes "unused" (the rule doesn't fire). Without this
// override the bundle would re-trip on every build (#1351).
{
files: [
"python/djust/static/djust/client.js",
"python/djust/static/djust/client-dev.js",
"python/djust/static/djust/debug-panel.js",
"python/djust/static/djust/react-client.js",
"python/djust/static/djust/service-worker.js",
],
languageOptions: {
sourceType: "script",
},
linterOptions: {
reportUnusedDisableDirectives: "off",
},
rules: {
"strict": "off",
},
},
// Concatenation fragments — these files are NOT standalone modules.
//
// For client.js:
// 00-namespace.js opens an `if/else { ... }` double-load guard block;
// 21-guard-close.js closes it. All other modules execute inside the
// block.
//
// For debug-panel.js (src/debug/*.js):
// The whole debug panel is a single class `DjustDebugPanel` declared
// in 00-panel-core.js (after a feature-detect early-return). All
// subsequent files contribute methods to that class body and the
// class closes at the end of the concat. Each file individually is
// a syntactic fragment.
//
// Skip lint on the fragments themselves — they're audited as part of
// the bundle (client.js / debug-panel.js).
{
ignores: [
"python/djust/static/djust/src/00-namespace.js",
"python/djust/static/djust/src/21-guard-close.js",
"python/djust/static/djust/src/debug/**/*.js",
],
},
// src/*.js source modules are concatenated into client.js (#1351). A
// function or const declared in 01-dom-helpers-turbo.js is "used" only
// by 09-event-binding.js after concat, but ESLint parses each src
// file independently and can't see the cross-file reference. Disable
// `no-unused-vars` for source modules — the bundled client.js (which
// IS what the pre-commit hook checks) still enforces the rule with
// full cross-file visibility. Catch-error / arg patterns still
// benefit from the global rule because the bundle config is what
// catches them in concat'd output.
{
files: ["python/djust/static/djust/src/**/*.js"],
rules: {
"no-unused-vars": "off",
},
},
// Test files can have relaxed rules
{
files: ["**/*.test.js", "**/*.spec.js", "tests/**/*.js"],
rules: {
"security/detect-object-injection": "off",
"security/detect-non-literal-regexp": "off",
},
},
];