@eslint-react/shared 2.14.0-next.0 → 3.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -104,6 +104,7 @@ interface CompatibleConfig {
104
104
  /** Shared settings. */
105
105
  settings?: SettingsConfig;
106
106
  }
107
+ type CompilationMode = "off" | "infer" | "annotation" | "syntax" | "all";
107
108
  //#endregion
108
109
  //#region src/config-adapters.d.ts
109
110
  /**
@@ -211,6 +212,14 @@ declare const RE_COMPONENT_NAME_LOOSE: RegExp;
211
212
  * Regular expression for matching a React Hook name.
212
213
  */
213
214
  declare const RE_HOOK_NAME: RegExp;
215
+ /**
216
+ * Known impure functions
217
+ */
218
+ declare const IMPURE_FUNCTIONS: ReadonlyMap<string, ReadonlySet<string>>;
219
+ /**
220
+ * Known impure global constructors used with `new`
221
+ */
222
+ declare const IMPURE_CONSTRUCTORS: ReadonlySet<string>;
214
223
  //#endregion
215
224
  //#region src/define-rule-listener.d.ts
216
225
  /**
@@ -276,6 +285,13 @@ declare function report(context: RuleContext): (descriptor?: null | ReportDescri
276
285
  */
277
286
  declare const ESLintReactSettingsSchema: z.ZodObject<{
278
287
  importSource: z.ZodOptional<z.ZodString>;
288
+ compilationMode: z.ZodOptional<z.ZodEnum<{
289
+ off: "off";
290
+ infer: "infer";
291
+ annotation: "annotation";
292
+ syntax: "syntax";
293
+ all: "all";
294
+ }>>;
279
295
  polymorphicPropName: z.ZodOptional<z.ZodString>;
280
296
  version: z.ZodOptional<z.ZodString>;
281
297
  additionalStateHooks: z.ZodOptional<z.ZodString>;
@@ -299,10 +315,12 @@ type ESLintReactSettings = z.infer<typeof ESLintReactSettingsSchema>;
299
315
  * Normalized ESLint React settings with processed values
300
316
  */
301
317
  interface ESLintReactSettingsNormalized {
302
- additionalStateHooks: RegExpLike;
318
+ version: string;
303
319
  importSource: string;
320
+ compilationMode: CompilationMode;
321
+ isCompilerEnabled: boolean;
304
322
  polymorphicPropName: string | unit;
305
- version: string;
323
+ additionalStateHooks: RegExpLike;
306
324
  }
307
325
  /**
308
326
  * Default ESLint React settings
@@ -310,6 +328,7 @@ interface ESLintReactSettingsNormalized {
310
328
  declare const DEFAULT_ESLINT_REACT_SETTINGS: {
311
329
  readonly version: "detect";
312
330
  readonly importSource: "react";
331
+ readonly compilationMode: "annotation";
313
332
  readonly polymorphicPropName: "as";
314
333
  };
315
334
  /**
@@ -319,6 +338,7 @@ declare const DEFAULT_ESLINT_SETTINGS: {
319
338
  readonly "react-x": {
320
339
  readonly version: "detect";
321
340
  readonly importSource: "react";
341
+ readonly compilationMode: "annotation";
322
342
  readonly polymorphicPropName: "as";
323
343
  };
324
344
  };
@@ -358,12 +378,15 @@ declare const decodeSettings: (settings: unknown) => ESLintReactSettings;
358
378
  */
359
379
  declare const normalizeSettings: ({
360
380
  importSource,
381
+ compilationMode,
361
382
  polymorphicPropName,
362
383
  version,
363
384
  additionalStateHooks,
364
385
  ...rest
365
386
  }: ESLintReactSettings) => {
366
387
  readonly importSource: string;
388
+ readonly compilationMode: "off" | "infer" | "annotation" | "syntax" | "all";
389
+ readonly isCompilerEnabled: boolean;
367
390
  readonly polymorphicPropName: string;
368
391
  readonly version: string;
369
392
  readonly additionalStateHooks: RegExpLike;
@@ -385,4 +408,4 @@ declare module "@typescript-eslint/utils/ts-eslint" {
385
408
  }
386
409
  }
387
410
  //#endregion
388
- export { CompatibleConfig, CompatiblePlugin, CompatibleRule, DEFAULT_ESLINT_REACT_SETTINGS, DEFAULT_ESLINT_SETTINGS, ESLintReactSettings, ESLintReactSettingsNormalized, ESLintReactSettingsSchema, ESLintSettings, ESLintSettingsSchema, GITHUB_URL, IdGenerator, NPM_SCOPE, RE_ANNOTATION_JSX, RE_ANNOTATION_JSX_FRAG, RE_ANNOTATION_JSX_IMPORT_SOURCE, RE_ANNOTATION_JSX_RUNTIME, RE_CAMEL_CASE, RE_COMPONENT_NAME, RE_COMPONENT_NAME_LOOSE, RE_CONSTANT_CASE, RE_HOOK_NAME, RE_HTML_TAG, RE_JAVASCRIPT_PROTOCOL, RE_JS_EXT, RE_JS_IDENTIFIER, RE_KEBAB_CASE, RE_PASCAL_CASE, RE_REGEXP_STR, RE_SNAKE_CASE, RE_TS_EXT, RegExpLike, RuleConfig, RuleContext, RuleFeature, RulePolicy, RuleSuggest, SettingsConfig, Severity, SeverityLevel, SeverityName, WEBSITE_URL, coerceESLintSettings, coerceSettings, decodeESLintSettings, decodeSettings, defineRuleListener, defineSettings, getConfigAdapters, getReactVersion, getSettingsFromContext, isESLintReactSettings, isESLintSettings, isRegExp, normalizeSettings, report, toRegExp };
411
+ export { CompatibleConfig, CompatiblePlugin, CompatibleRule, CompilationMode, DEFAULT_ESLINT_REACT_SETTINGS, DEFAULT_ESLINT_SETTINGS, ESLintReactSettings, ESLintReactSettingsNormalized, ESLintReactSettingsSchema, ESLintSettings, ESLintSettingsSchema, GITHUB_URL, IMPURE_CONSTRUCTORS, IMPURE_FUNCTIONS, IdGenerator, NPM_SCOPE, RE_ANNOTATION_JSX, RE_ANNOTATION_JSX_FRAG, RE_ANNOTATION_JSX_IMPORT_SOURCE, RE_ANNOTATION_JSX_RUNTIME, RE_CAMEL_CASE, RE_COMPONENT_NAME, RE_COMPONENT_NAME_LOOSE, RE_CONSTANT_CASE, RE_HOOK_NAME, RE_HTML_TAG, RE_JAVASCRIPT_PROTOCOL, RE_JS_EXT, RE_JS_IDENTIFIER, RE_KEBAB_CASE, RE_PASCAL_CASE, RE_REGEXP_STR, RE_SNAKE_CASE, RE_TS_EXT, RegExpLike, RuleConfig, RuleContext, RuleFeature, RulePolicy, RuleSuggest, SettingsConfig, Severity, SeverityLevel, SeverityName, WEBSITE_URL, coerceESLintSettings, coerceSettings, decodeESLintSettings, decodeSettings, defineRuleListener, defineSettings, getConfigAdapters, getReactVersion, getSettingsFromContext, isESLintReactSettings, isESLintSettings, isRegExp, normalizeSettings, report, toRegExp };
package/dist/index.js CHANGED
@@ -138,6 +138,273 @@ const RE_COMPONENT_NAME_LOOSE = /^_?[A-Z]/u;
138
138
  * Regular expression for matching a React Hook name.
139
139
  */
140
140
  const RE_HOOK_NAME = /^use/u;
141
+ /**
142
+ * Known impure functions
143
+ */
144
+ const IMPURE_FUNCTIONS = new Map([
145
+ ["Atomics", new Set([
146
+ "add",
147
+ "and",
148
+ "compareExchange",
149
+ "exchange",
150
+ "load",
151
+ "notify",
152
+ "or",
153
+ "store",
154
+ "sub",
155
+ "wait",
156
+ "waitAsync",
157
+ "xor"
158
+ ])],
159
+ ["caches", new Set([
160
+ "delete",
161
+ "has",
162
+ "keys",
163
+ "match",
164
+ "open"
165
+ ])],
166
+ ["clipboard", new Set([
167
+ "read",
168
+ "readText",
169
+ "write",
170
+ "writeText"
171
+ ])],
172
+ ["console", new Set([
173
+ "assert",
174
+ "clear",
175
+ "count",
176
+ "countReset",
177
+ "debug",
178
+ "dir",
179
+ "dirxml",
180
+ "error",
181
+ "group",
182
+ "groupCollapsed",
183
+ "groupEnd",
184
+ "info",
185
+ "log",
186
+ "profile",
187
+ "profileEnd",
188
+ "table",
189
+ "time",
190
+ "timeEnd",
191
+ "timeLog",
192
+ "timeStamp",
193
+ "trace",
194
+ "warn"
195
+ ])],
196
+ ["cookieStore", new Set([
197
+ "delete",
198
+ "get",
199
+ "getAll",
200
+ "set"
201
+ ])],
202
+ ["crypto", new Set(["getRandomValues", "randomUUID"])],
203
+ ["Date", new Set(["now"])],
204
+ ["document", new Set([
205
+ "adoptNode",
206
+ "append",
207
+ "close",
208
+ "createAttribute",
209
+ "createAttributeNS",
210
+ "createCDATASection",
211
+ "createComment",
212
+ "createDocumentFragment",
213
+ "createDocumentType",
214
+ "createElement",
215
+ "createElementNS",
216
+ "createEvent",
217
+ "createNodeIterator",
218
+ "createProcessingInstruction",
219
+ "createRange",
220
+ "createTextNode",
221
+ "createTreeWalker",
222
+ "elementFromPoint",
223
+ "elementsFromPoint",
224
+ "execCommand",
225
+ "exitFullscreen",
226
+ "exitPictureInPicture",
227
+ "exitPointerLock",
228
+ "getAnimations",
229
+ "getElementById",
230
+ "getElementsByClassName",
231
+ "getElementsByName",
232
+ "getElementsByTagName",
233
+ "getElementsByTagNameNS",
234
+ "getSelection",
235
+ "hasFocus",
236
+ "importNode",
237
+ "open",
238
+ "prepend",
239
+ "querySelector",
240
+ "querySelectorAll",
241
+ "replaceChildren",
242
+ "requestStorageAccess",
243
+ "startViewTransition",
244
+ "write",
245
+ "writeln"
246
+ ])],
247
+ ["history", new Set([
248
+ "back",
249
+ "forward",
250
+ "go",
251
+ "pushState",
252
+ "replaceState"
253
+ ])],
254
+ ["indexedDB", new Set([
255
+ "databases",
256
+ "deleteDatabase",
257
+ "open"
258
+ ])],
259
+ ["localStorage", new Set([
260
+ "clear",
261
+ "getItem",
262
+ "key",
263
+ "removeItem",
264
+ "setItem"
265
+ ])],
266
+ ["location", new Set([
267
+ "assign",
268
+ "reload",
269
+ "replace"
270
+ ])],
271
+ ["Math", new Set(["random"])],
272
+ ["navigation", new Set([
273
+ "back",
274
+ "forward",
275
+ "navigate",
276
+ "reload",
277
+ "traverseTo",
278
+ "updateCurrentEntry"
279
+ ])],
280
+ ["navigator", new Set([
281
+ "canShare",
282
+ "getBattery",
283
+ "getGamepads",
284
+ "getUserMedia",
285
+ "javaEnabled",
286
+ "registerProtocolHandler",
287
+ "requestMediaKeySystemAccess",
288
+ "requestMIDIAccess",
289
+ "sendBeacon",
290
+ "share",
291
+ "vibrate"
292
+ ])],
293
+ ["Notification", new Set(["requestPermission"])],
294
+ ["Object", new Set([
295
+ "assign",
296
+ "defineProperties",
297
+ "defineProperty",
298
+ "freeze",
299
+ "preventExtensions",
300
+ "seal",
301
+ "setPrototypeOf"
302
+ ])],
303
+ ["performance", new Set([
304
+ "clearMarks",
305
+ "clearMeasures",
306
+ "getEntries",
307
+ "getEntriesByName",
308
+ "getEntriesByType",
309
+ "mark",
310
+ "measure",
311
+ "now"
312
+ ])],
313
+ ["process", new Set([
314
+ "abort",
315
+ "chdir",
316
+ "cpuUsage",
317
+ "emitWarning",
318
+ "exit",
319
+ "hrtime",
320
+ "kill",
321
+ "memoryUsage",
322
+ "nextTick",
323
+ "send",
324
+ "stderr",
325
+ "stdout"
326
+ ])],
327
+ ["Reflect", new Set([
328
+ "defineProperty",
329
+ "deleteProperty",
330
+ "preventExtensions",
331
+ "set",
332
+ "setPrototypeOf"
333
+ ])],
334
+ ["scheduler", new Set(["postTask", "yield"])],
335
+ ["sessionStorage", new Set([
336
+ "clear",
337
+ "getItem",
338
+ "key",
339
+ "removeItem",
340
+ "setItem"
341
+ ])],
342
+ ["URL", new Set(["createObjectURL", "revokeObjectURL"])],
343
+ ["window", new Set([
344
+ "addEventListener",
345
+ "alert",
346
+ "blur",
347
+ "cancelAnimationFrame",
348
+ "cancelIdleCallback",
349
+ "clearInterval",
350
+ "clearTimeout",
351
+ "close",
352
+ "confirm",
353
+ "dispatchEvent",
354
+ "fetch",
355
+ "focus",
356
+ "getComputedStyle",
357
+ "getSelection",
358
+ "matchMedia",
359
+ "moveBy",
360
+ "moveTo",
361
+ "open",
362
+ "postMessage",
363
+ "print",
364
+ "prompt",
365
+ "queueMicrotask",
366
+ "removeEventListener",
367
+ "requestAnimationFrame",
368
+ "requestIdleCallback",
369
+ "resizeBy",
370
+ "resizeTo",
371
+ "scroll",
372
+ "scrollBy",
373
+ "scrollTo",
374
+ "setInterval",
375
+ "setTimeout",
376
+ "stop"
377
+ ])]
378
+ ]);
379
+ /**
380
+ * Known impure global constructors used with `new`
381
+ */
382
+ const IMPURE_CONSTRUCTORS = new Set([
383
+ "AbortController",
384
+ "Audio",
385
+ "AudioContext",
386
+ "BroadcastChannel",
387
+ "Date",
388
+ "EventSource",
389
+ "FileReader",
390
+ "Image",
391
+ "IntersectionObserver",
392
+ "MediaRecorder",
393
+ "MediaSource",
394
+ "MediaStream",
395
+ "MessageChannel",
396
+ "MutationObserver",
397
+ "Notification",
398
+ "OfflineAudioContext",
399
+ "PerformanceObserver",
400
+ "ReportingObserver",
401
+ "ResizeObserver",
402
+ "RTCPeerConnection",
403
+ "SharedWorker",
404
+ "WebSocket",
405
+ "Worker",
406
+ "XMLHttpRequest"
407
+ ]);
141
408
 
142
409
  //#endregion
143
410
  //#region src/define-rule-listener.ts
@@ -230,6 +497,13 @@ function report(context) {
230
497
  */
231
498
  const ESLintReactSettingsSchema = z.object({
232
499
  importSource: z.optional(z.string()),
500
+ compilationMode: z.optional(z.enum([
501
+ "off",
502
+ "infer",
503
+ "annotation",
504
+ "syntax",
505
+ "all"
506
+ ])),
233
507
  polymorphicPropName: z.optional(z.string()),
234
508
  version: z.optional(z.string()),
235
509
  additionalStateHooks: z.optional(z.string())
@@ -245,6 +519,7 @@ const ESLintSettingsSchema = z.optional(z.object({ "react-x": z.optional(z.unkno
245
519
  const DEFAULT_ESLINT_REACT_SETTINGS = {
246
520
  version: "detect",
247
521
  importSource: "react",
522
+ compilationMode: "annotation",
248
523
  polymorphicPropName: "as"
249
524
  };
250
525
  /**
@@ -299,10 +574,12 @@ const decodeSettings = (settings) => {
299
574
  * Normalizes ESLint React settings to a consistent internal format
300
575
  * Transforms component definitions and resolves version information
301
576
  */
302
- const normalizeSettings = ({ importSource = "react", polymorphicPropName = "as", version, additionalStateHooks, ...rest }) => {
577
+ const normalizeSettings = ({ importSource = "react", compilationMode = "annotation", polymorphicPropName = "as", version, additionalStateHooks, ...rest }) => {
303
578
  return {
304
579
  ...rest,
305
580
  importSource,
581
+ compilationMode,
582
+ isCompilerEnabled: compilationMode !== "off",
306
583
  polymorphicPropName,
307
584
  version: match(version).with(P.union(P.nullish, "", "detect"), () => getReactVersion("19.2.0")).otherwise(identity),
308
585
  additionalStateHooks: toRegExp(additionalStateHooks)
@@ -325,4 +602,4 @@ function getSettingsFromContext(context) {
325
602
  const defineSettings = identity;
326
603
 
327
604
  //#endregion
328
- export { DEFAULT_ESLINT_REACT_SETTINGS, DEFAULT_ESLINT_SETTINGS, ESLintReactSettingsSchema, ESLintSettingsSchema, GITHUB_URL, IdGenerator, NPM_SCOPE, RE_ANNOTATION_JSX, RE_ANNOTATION_JSX_FRAG, RE_ANNOTATION_JSX_IMPORT_SOURCE, RE_ANNOTATION_JSX_RUNTIME, RE_CAMEL_CASE, RE_COMPONENT_NAME, RE_COMPONENT_NAME_LOOSE, RE_CONSTANT_CASE, RE_HOOK_NAME, RE_HTML_TAG, RE_JAVASCRIPT_PROTOCOL, RE_JS_EXT, RE_JS_IDENTIFIER, RE_KEBAB_CASE, RE_PASCAL_CASE, RE_REGEXP_STR, RE_SNAKE_CASE, RE_TS_EXT, WEBSITE_URL, coerceESLintSettings, coerceSettings, decodeESLintSettings, decodeSettings, defineRuleListener, defineSettings, getConfigAdapters, getReactVersion, getSettingsFromContext, isESLintReactSettings, isESLintSettings, isRegExp, normalizeSettings, report, toRegExp };
605
+ export { DEFAULT_ESLINT_REACT_SETTINGS, DEFAULT_ESLINT_SETTINGS, ESLintReactSettingsSchema, ESLintSettingsSchema, GITHUB_URL, IMPURE_CONSTRUCTORS, IMPURE_FUNCTIONS, IdGenerator, NPM_SCOPE, RE_ANNOTATION_JSX, RE_ANNOTATION_JSX_FRAG, RE_ANNOTATION_JSX_IMPORT_SOURCE, RE_ANNOTATION_JSX_RUNTIME, RE_CAMEL_CASE, RE_COMPONENT_NAME, RE_COMPONENT_NAME_LOOSE, RE_CONSTANT_CASE, RE_HOOK_NAME, RE_HTML_TAG, RE_JAVASCRIPT_PROTOCOL, RE_JS_EXT, RE_JS_IDENTIFIER, RE_KEBAB_CASE, RE_PASCAL_CASE, RE_REGEXP_STR, RE_SNAKE_CASE, RE_TS_EXT, WEBSITE_URL, coerceESLintSettings, coerceSettings, decodeESLintSettings, decodeSettings, defineRuleListener, defineSettings, getConfigAdapters, getReactVersion, getSettingsFromContext, isESLintReactSettings, isESLintSettings, isRegExp, normalizeSettings, report, toRegExp };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/shared",
3
- "version": "2.14.0-next.0",
3
+ "version": "3.0.0-beta.1",
4
4
  "description": "ESLint React's Shared constants and functions.",
5
5
  "homepage": "https://github.com/Rel1cx/eslint-react",
6
6
  "bugs": {
@@ -30,10 +30,10 @@
30
30
  "./package.json"
31
31
  ],
32
32
  "dependencies": {
33
- "@typescript-eslint/utils": "^8.55.0",
33
+ "@typescript-eslint/utils": "^8.56.0",
34
34
  "ts-pattern": "^5.9.0",
35
35
  "zod": "^3.25.0 || ^4.0.0",
36
- "@eslint-react/eff": "2.14.0-next.0"
36
+ "@eslint-react/eff": "3.0.0-beta.1"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@tsconfig/node24": "^24.0.4",
@@ -46,7 +46,7 @@
46
46
  "typescript": ">=4.8.4 <6.0.0"
47
47
  },
48
48
  "engines": {
49
- "node": ">=20.19.0"
49
+ "node": ">=22.0.0"
50
50
  },
51
51
  "scripts": {
52
52
  "build": "tsdown --dts-resolve",