eslint-plugin-react-debug 3.0.0-next.8 → 3.0.0-next.81

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +5 -16
  2. package/dist/index.js +205 -62
  3. package/package.json +11 -10
package/dist/index.d.ts CHANGED
@@ -1,20 +1,9 @@
1
- import * as _eslint_react_shared0 from "@eslint-react/shared";
1
+ import { ESLint, Linter } from "eslint";
2
2
 
3
3
  //#region src/index.d.ts
4
- declare const _default: {
5
- configs: {
6
- all: {
7
- plugins: {};
8
- name?: string;
9
- rules?: Record<string, _eslint_react_shared0.RuleConfig>;
10
- settings?: _eslint_react_shared0.SettingsConfig;
11
- };
12
- };
13
- meta: {
14
- name: string;
15
- version: string;
16
- };
17
- rules: Record<string, _eslint_react_shared0.CompatibleRule>;
4
+ type ConfigName = "all";
5
+ declare const finalPlugin: ESLint.Plugin & {
6
+ configs: Record<ConfigName, Linter.Config>;
18
7
  };
19
8
  //#endregion
20
- export { _default as default };
9
+ export { finalPlugin as default };
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { DEFAULT_ESLINT_REACT_SETTINGS, WEBSITE_URL, defineRuleListener, getConfigAdapters, getSettingsFromContext, report } from "@eslint-react/shared";
1
+ import { DEFAULT_ESLINT_REACT_SETTINGS, WEBSITE_URL, defineRuleListener, getSettingsFromContext, report } from "@eslint-react/shared";
2
2
  import * as core from "@eslint-react/core";
3
+ import { JsxEmit, JsxInspector } from "@eslint-react/core";
3
4
  import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
4
- import { flow } from "@eslint-react/eff";
5
5
  import { AST_NODE_TYPES as AST_NODE_TYPES$1 } from "@typescript-eslint/types";
6
6
  import { P, match } from "ts-pattern";
7
7
 
@@ -21,28 +21,10 @@ var __exportAll = (all, no_symbols) => {
21
21
  return target;
22
22
  };
23
23
 
24
- //#endregion
25
- //#region src/configs/all.ts
26
- var all_exports = /* @__PURE__ */ __exportAll({
27
- name: () => name$1,
28
- rules: () => rules,
29
- settings: () => settings
30
- });
31
- const name$1 = "react-debug/all";
32
- const rules = {
33
- "react-debug/class-component": "warn",
34
- "react-debug/function-component": "warn",
35
- "react-debug/hook": "warn",
36
- "react-debug/is-from-react": "warn",
37
- "react-debug/is-from-ref": "warn",
38
- "react-debug/jsx": "warn"
39
- };
40
- const settings = { "react-x": DEFAULT_ESLINT_REACT_SETTINGS };
41
-
42
24
  //#endregion
43
25
  //#region package.json
44
- var name = "eslint-plugin-react-debug";
45
- var version = "3.0.0-next.8";
26
+ var name$1 = "eslint-plugin-react-debug";
27
+ var version = "3.0.0-next.81";
46
28
 
47
29
  //#endregion
48
30
  //#region src/utils/create-rule.ts
@@ -58,7 +40,7 @@ function stringify(value) {
58
40
  }
59
41
 
60
42
  //#endregion
61
- //#region src/rules/class-component.ts
43
+ //#region src/rules/class-component/class-component.ts
62
44
  const RULE_NAME$5 = "class-component";
63
45
  var class_component_default = createRule({
64
46
  meta: {
@@ -75,15 +57,15 @@ function create$5(context) {
75
57
  const { ctx, visitor } = core.useComponentCollectorLegacy(context);
76
58
  return defineRuleListener(visitor, { "Program:exit"(program) {
77
59
  for (const { name = "anonymous", node: component } of ctx.getAllComponents(program)) context.report({
60
+ data: { json: stringify({ name }) },
78
61
  messageId: "default",
79
- node: component,
80
- data: { json: stringify({ name }) }
62
+ node: component
81
63
  });
82
64
  } });
83
65
  }
84
66
 
85
67
  //#endregion
86
- //#region src/rules/function-component.ts
68
+ //#region src/rules/function-component/function-component.ts
87
69
  const RULE_NAME$4 = "function-component";
88
70
  var function_component_default = createRule({
89
71
  meta: {
@@ -102,22 +84,22 @@ function create$4(context) {
102
84
  hint: core.DEFAULT_COMPONENT_DETECTION_HINT
103
85
  });
104
86
  return defineRuleListener(visitor, { "Program:exit"(program) {
105
- for (const { name = "anonymous", node, displayName, flag, hookCalls } of ctx.getAllComponents(program)) context.report({
106
- messageId: "default",
107
- node,
87
+ for (const { name, displayName, flag, hookCalls, node } of ctx.getAllComponents(program)) context.report({
108
88
  data: { json: stringify({
109
- name,
89
+ name: name ?? "anonymous",
110
90
  displayName: displayName == null ? "none" : context.sourceCode.getText(displayName),
111
91
  forwardRef: (flag & core.ComponentFlag.ForwardRef) > 0n,
112
92
  hookCalls: hookCalls.length,
113
93
  memo: (flag & core.ComponentFlag.Memo) > 0n
114
- }) }
94
+ }) },
95
+ messageId: "default",
96
+ node
115
97
  });
116
98
  } });
117
99
  }
118
100
 
119
101
  //#endregion
120
- //#region src/rules/hook.ts
102
+ //#region src/rules/hook/hook.ts
121
103
  const RULE_NAME$3 = "hook";
122
104
  var hook_default = createRule({
123
105
  meta: {
@@ -133,19 +115,19 @@ var hook_default = createRule({
133
115
  function create$3(context) {
134
116
  const { ctx, visitor } = core.useHookCollector(context);
135
117
  return defineRuleListener(visitor, { "Program:exit"(program) {
136
- for (const { name, node, hookCalls } of ctx.getAllHooks(program)) context.report({
137
- messageId: "default",
138
- node,
118
+ for (const { name, hookCalls, node } of ctx.getAllHooks(program)) context.report({
139
119
  data: { json: stringify({
140
120
  name,
141
121
  hookCalls: hookCalls.length
142
- }) }
122
+ }) },
123
+ messageId: "default",
124
+ node
143
125
  });
144
126
  } });
145
127
  }
146
128
 
147
129
  //#endregion
148
- //#region src/rules/is-from-react.ts
130
+ //#region src/rules/is-from-react/is-from-react.ts
149
131
  const RULE_NAME$2 = "is-from-react";
150
132
  var is_from_react_default = createRule({
151
133
  meta: {
@@ -165,12 +147,12 @@ function create$2(context) {
165
147
  const name = node.name;
166
148
  if (!isFromReact(node, context.sourceCode.getScope(node), importSource)) return;
167
149
  context.report({
168
- messageId: "default",
169
- node,
170
150
  data: { json: stringify({
171
151
  name,
172
152
  importSource
173
- }) }
153
+ }) },
154
+ messageId: "default",
155
+ node
174
156
  });
175
157
  }
176
158
  return defineRuleListener({
@@ -195,7 +177,7 @@ function isFromReact(node, initialScope, importSource = "react") {
195
177
  }
196
178
 
197
179
  //#endregion
198
- //#region src/rules/is-from-ref.ts
180
+ //#region src/rules/is-from-ref/is-from-ref.ts
199
181
  const RULE_NAME$1 = "is-from-ref";
200
182
  var is_from_ref_default = createRule({
201
183
  meta: {
@@ -217,9 +199,9 @@ function create$1(context) {
217
199
  init: context.sourceCode.getText(refInit)
218
200
  });
219
201
  context.report({
202
+ data: { json },
220
203
  messageId: "default",
221
- node,
222
- data: { json }
204
+ node
223
205
  });
224
206
  }
225
207
  }
@@ -238,8 +220,154 @@ function getRefInitNode(node, initialScope) {
238
220
  }
239
221
 
240
222
  //#endregion
241
- //#region src/rules/jsx.ts
242
- const { JsxEmit } = core;
223
+ //#region ../../../.pkgs/eff/dist/index.js
224
+ /**
225
+ * Creates a function that can be used in a data-last (aka `pipe`able) or
226
+ * data-first style.
227
+ *
228
+ * The first parameter to `dual` is either the arity of the uncurried function
229
+ * or a predicate that determines if the function is being used in a data-first
230
+ * or data-last style.
231
+ *
232
+ * Using the arity is the most common use case, but there are some cases where
233
+ * you may want to use a predicate. For example, if you have a function that
234
+ * takes an optional argument, you can use a predicate to determine if the
235
+ * function is being used in a data-first or data-last style.
236
+ *
237
+ * You can pass either the arity of the uncurried function or a predicate
238
+ * which determines if the function is being used in a data-first or
239
+ * data-last style.
240
+ *
241
+ * **Example** (Using arity to determine data-first or data-last style)
242
+ *
243
+ * ```ts
244
+ * import { dual, pipe } from "effect/Function"
245
+ *
246
+ * const sum = dual<
247
+ * (that: number) => (self: number) => number,
248
+ * (self: number, that: number) => number
249
+ * >(2, (self, that) => self + that)
250
+ *
251
+ * console.log(sum(2, 3)) // 5
252
+ * console.log(pipe(2, sum(3))) // 5
253
+ * ```
254
+ *
255
+ * **Example** (Using call signatures to define the overloads)
256
+ *
257
+ * ```ts
258
+ * import { dual, pipe } from "effect/Function"
259
+ *
260
+ * const sum: {
261
+ * (that: number): (self: number) => number
262
+ * (self: number, that: number): number
263
+ * } = dual(2, (self: number, that: number): number => self + that)
264
+ *
265
+ * console.log(sum(2, 3)) // 5
266
+ * console.log(pipe(2, sum(3))) // 5
267
+ * ```
268
+ *
269
+ * **Example** (Using a predicate to determine data-first or data-last style)
270
+ *
271
+ * ```ts
272
+ * import { dual, pipe } from "effect/Function"
273
+ *
274
+ * const sum = dual<
275
+ * (that: number) => (self: number) => number,
276
+ * (self: number, that: number) => number
277
+ * >(
278
+ * (args) => args.length === 2,
279
+ * (self, that) => self + that
280
+ * )
281
+ *
282
+ * console.log(sum(2, 3)) // 5
283
+ * console.log(pipe(2, sum(3))) // 5
284
+ * ```
285
+ *
286
+ * @param arity - The arity of the uncurried function or a predicate that determines if the function is being used in a data-first or data-last style.
287
+ * @param body - The function to be curried.
288
+ * @since 1.0.0
289
+ */
290
+ const dual = function(arity, body) {
291
+ if (typeof arity === "function") return function() {
292
+ return arity(arguments) ? body.apply(this, arguments) : ((self) => body(self, ...arguments));
293
+ };
294
+ switch (arity) {
295
+ case 0:
296
+ case 1: throw new RangeError(`Invalid arity ${arity}`);
297
+ case 2: return function(a, b) {
298
+ if (arguments.length >= 2) return body(a, b);
299
+ return function(self) {
300
+ return body(self, a);
301
+ };
302
+ };
303
+ case 3: return function(a, b, c) {
304
+ if (arguments.length >= 3) return body(a, b, c);
305
+ return function(self) {
306
+ return body(self, a, b);
307
+ };
308
+ };
309
+ default: return function() {
310
+ if (arguments.length >= arity) return body.apply(this, arguments);
311
+ const args = arguments;
312
+ return function(self) {
313
+ return body(self, ...args);
314
+ };
315
+ };
316
+ }
317
+ };
318
+ /**
319
+ * Composes two functions, `ab` and `bc` into a single function that takes in an argument `a` of type `A` and returns a result of type `C`.
320
+ * The result is obtained by first applying the `ab` function to `a` and then applying the `bc` function to the result of `ab`.
321
+ *
322
+ * @param self - The first function to apply (or the composed function in data-last style).
323
+ * @param bc - The second function to apply.
324
+ * @returns A composed function that applies both functions in sequence.
325
+ * @example
326
+ * ```ts
327
+ * import * as assert from "node:assert"
328
+ * import { compose } from "effect/Function"
329
+ *
330
+ * const increment = (n: number) => n + 1;
331
+ * const square = (n: number) => n * n;
332
+ *
333
+ * assert.strictEqual(compose(increment, square)(2), 9);
334
+ * ```
335
+ *
336
+ * @since 1.0.0
337
+ */
338
+ const compose = dual(2, (ab, bc) => (a) => bc(ab(a)));
339
+ function flow(ab, bc, cd, de, ef, fg, gh, hi, ij) {
340
+ switch (arguments.length) {
341
+ case 1: return ab;
342
+ case 2: return function() {
343
+ return bc(ab.apply(this, arguments));
344
+ };
345
+ case 3: return function() {
346
+ return cd(bc(ab.apply(this, arguments)));
347
+ };
348
+ case 4: return function() {
349
+ return de(cd(bc(ab.apply(this, arguments))));
350
+ };
351
+ case 5: return function() {
352
+ return ef(de(cd(bc(ab.apply(this, arguments)))));
353
+ };
354
+ case 6: return function() {
355
+ return fg(ef(de(cd(bc(ab.apply(this, arguments))))));
356
+ };
357
+ case 7: return function() {
358
+ return gh(fg(ef(de(cd(bc(ab.apply(this, arguments)))))));
359
+ };
360
+ case 8: return function() {
361
+ return hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments))))))));
362
+ };
363
+ case 9: return function() {
364
+ return ij(hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments)))))))));
365
+ };
366
+ }
367
+ }
368
+
369
+ //#endregion
370
+ //#region src/rules/jsx/jsx.ts
243
371
  const RULE_NAME = "jsx";
244
372
  var jsx_default = createRule({
245
373
  meta: {
@@ -248,30 +376,26 @@ var jsx_default = createRule({
248
376
  messages: { default: "{{json}}" },
249
377
  schema: []
250
378
  },
251
- name: RULE_NAME,
379
+ name: "jsx",
252
380
  create,
253
381
  defaultOptions: []
254
382
  });
255
383
  function create(context) {
256
- const jsxConfigFromContext = core.getJsxConfigFromContext(context);
257
- const jsxConfigFromAnnotation = core.getJsxConfigFromAnnotation(context);
258
- const jsxConfig = {
259
- ...jsxConfigFromContext,
260
- ...jsxConfigFromAnnotation
261
- };
384
+ const jsx = JsxInspector.from(context);
385
+ const jsxConfig = jsx.jsxConfig;
262
386
  function getReportDescriptor(context) {
263
387
  return (node) => ({
264
- messageId: "default",
265
- node,
266
388
  data: { json: stringify({
267
- kind: match(node).with({ type: AST_NODE_TYPES$1.JSXElement }, (n) => core.isJsxFragmentElement(context, n, jsxConfig) ? "fragment" : "element").with({ type: AST_NODE_TYPES$1.JSXFragment }, () => "fragment").exhaustive(),
268
- type: core.getJsxElementType(context, node),
389
+ kind: match(node).with({ type: AST_NODE_TYPES$1.JSXElement }, (n) => jsx.isFragmentElement(n) ? "fragment" : "element").with({ type: AST_NODE_TYPES$1.JSXFragment }, () => "fragment").exhaustive(),
390
+ type: jsx.getElementType(node),
269
391
  jsx: match(jsxConfig.jsx).with(JsxEmit.None, () => "none").with(JsxEmit.ReactJSX, () => "react-jsx").with(JsxEmit.ReactJSXDev, () => "react-jsx-dev").with(JsxEmit.React, () => "react").with(JsxEmit.ReactNative, () => "react-native").with(JsxEmit.Preserve, () => "preserve").otherwise(() => "unknown"),
270
392
  jsxFactory: jsxConfig.jsxFactory,
271
393
  jsxFragmentFactory: jsxConfig.jsxFragmentFactory,
272
394
  jsxImportSource: jsxConfig.jsxImportSource,
273
395
  jsxRuntime: match(jsxConfig.jsx).with(P.union(JsxEmit.None, JsxEmit.ReactJSX, JsxEmit.ReactJSXDev), () => "automatic").otherwise(() => "classic")
274
- }) }
396
+ }) },
397
+ messageId: "default",
398
+ node
275
399
  });
276
400
  }
277
401
  return defineRuleListener({ "JSXElement, JSXFragment": flow(getReportDescriptor(context), report(context)) });
@@ -281,7 +405,7 @@ function create(context) {
281
405
  //#region src/plugin.ts
282
406
  const plugin = {
283
407
  meta: {
284
- name,
408
+ name: name$1,
285
409
  version
286
410
  },
287
411
  rules: {
@@ -294,13 +418,32 @@ const plugin = {
294
418
  }
295
419
  };
296
420
 
421
+ //#endregion
422
+ //#region src/configs/all.ts
423
+ var all_exports = /* @__PURE__ */ __exportAll({
424
+ name: () => name,
425
+ plugins: () => plugins,
426
+ rules: () => rules,
427
+ settings: () => settings
428
+ });
429
+ const name = "react-debug/all";
430
+ const rules = {
431
+ "react-debug/class-component": "warn",
432
+ "react-debug/function-component": "warn",
433
+ "react-debug/hook": "warn",
434
+ "react-debug/is-from-react": "warn",
435
+ "react-debug/is-from-ref": "warn",
436
+ "react-debug/jsx": "warn"
437
+ };
438
+ const plugins = { "react-debug": plugin };
439
+ const settings = { "react-x": DEFAULT_ESLINT_REACT_SETTINGS };
440
+
297
441
  //#endregion
298
442
  //#region src/index.ts
299
- const { toFlatConfig } = getConfigAdapters("react-debug", plugin);
300
- var src_default = {
443
+ const finalPlugin = {
301
444
  ...plugin,
302
- configs: { ["all"]: toFlatConfig(all_exports) }
445
+ configs: { ["all"]: all_exports }
303
446
  };
304
447
 
305
448
  //#endregion
306
- export { src_default as default };
449
+ export { finalPlugin as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-debug",
3
- "version": "3.0.0-next.8",
3
+ "version": "3.0.0-next.81",
4
4
  "description": "ESLint React's ESLint plugin for debugging related rules.",
5
5
  "keywords": [
6
6
  "react",
@@ -43,21 +43,22 @@
43
43
  "@typescript-eslint/types": "canary",
44
44
  "@typescript-eslint/utils": "canary",
45
45
  "ts-pattern": "^5.9.0",
46
- "@eslint-react/ast": "3.0.0-next.8",
47
- "@eslint-react/core": "3.0.0-next.8",
48
- "@eslint-react/shared": "3.0.0-next.8",
49
- "@eslint-react/eff": "3.0.0-next.8",
50
- "@eslint-react/var": "3.0.0-next.8"
46
+ "@eslint-react/shared": "3.0.0-next.81",
47
+ "@eslint-react/var": "3.0.0-next.81",
48
+ "@eslint-react/ast": "3.0.0-next.81",
49
+ "@eslint-react/core": "3.0.0-next.81"
51
50
  },
52
51
  "devDependencies": {
53
52
  "@types/react": "^19.2.14",
54
53
  "@types/react-dom": "^19.2.3",
55
- "tsdown": "^0.20.3",
54
+ "eslint": "^10.0.3",
55
+ "tsdown": "^0.21.0",
56
+ "@local/eff": "3.0.0-beta.72",
56
57
  "@local/configs": "0.0.0"
57
58
  },
58
59
  "peerDependencies": {
59
- "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0",
60
- "typescript": ">=4.8.4 <6.0.0"
60
+ "eslint": "^10.0.0",
61
+ "typescript": "*"
61
62
  },
62
63
  "engines": {
63
64
  "node": ">=22.0.0"
@@ -68,6 +69,6 @@
68
69
  "scripts": {
69
70
  "build": "tsdown",
70
71
  "lint:publish": "publint",
71
- "lint:ts": "tsc --noEmit"
72
+ "lint:ts": "tsl"
72
73
  }
73
74
  }