eslint-plugin-react-debug 3.0.0-rc.5 → 4.0.0-beta.0

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/README.md +2 -2
  2. package/dist/index.js +35 -15
  3. package/package.json +12 -11
package/README.md CHANGED
@@ -15,7 +15,7 @@ npm install --save-dev eslint-plugin-react-debug
15
15
 
16
16
  ```ts
17
17
  import js from "@eslint/js";
18
- import debug from "eslint-plugin-react-debug";
18
+ import reactDebug from "eslint-plugin-react-debug";
19
19
  import { defineConfig } from "eslint/config";
20
20
  import tseslint from "typescript-eslint";
21
21
 
@@ -26,7 +26,7 @@ export default defineConfig(
26
26
  js.configs.recommended,
27
27
  tseslint.configs.recommended,
28
28
  // Add configs from eslint-plugin-react-debug
29
- debug.configs.all,
29
+ reactDebug.configs.all,
30
30
  ],
31
31
  rules: {
32
32
  // Put rules you want to override here
package/dist/index.js CHANGED
@@ -1,7 +1,10 @@
1
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
+ import { isUseRefCall } from "@eslint-react/core";
4
4
  import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
5
+ import { findVariable } from "@typescript-eslint/utils/ast-utils";
6
+ import "@eslint-react/ast";
7
+ import { JsxEmit, getElementFullType, getJsxConfig, isFragmentElement } from "@eslint-react/jsx";
5
8
  import { AST_NODE_TYPES as AST_NODE_TYPES$1 } from "@typescript-eslint/types";
6
9
  import { P, match } from "ts-pattern";
7
10
 
@@ -24,7 +27,7 @@ var __exportAll = (all, no_symbols) => {
24
27
  //#endregion
25
28
  //#region package.json
26
29
  var name$1 = "eslint-plugin-react-debug";
27
- var version = "3.0.0-rc.5";
30
+ var version = "4.0.0-beta.0";
28
31
 
29
32
  //#endregion
30
33
  //#region src/utils/create-rule.ts
@@ -54,9 +57,9 @@ var class_component_default = createRule({
54
57
  defaultOptions: []
55
58
  });
56
59
  function create$5(context) {
57
- const { ctx, visitor } = core.useComponentCollectorLegacy(context);
60
+ const { api, visitor } = core.getComponentCollectorLegacy(context);
58
61
  return defineRuleListener(visitor, { "Program:exit"(program) {
59
- for (const { name = "anonymous", node: component } of ctx.getAllComponents(program)) context.report({
62
+ for (const { name = "anonymous", node: component } of api.getAllComponents(program)) context.report({
60
63
  data: { json: stringify({ name }) },
61
64
  messageId: "default",
62
65
  node: component
@@ -79,12 +82,12 @@ var function_component_default = createRule({
79
82
  defaultOptions: []
80
83
  });
81
84
  function create$4(context) {
82
- const { ctx, visitor } = core.useComponentCollector(context, {
85
+ const { api, visitor } = core.getComponentCollector(context, {
83
86
  collectDisplayName: true,
84
87
  hint: core.DEFAULT_COMPONENT_DETECTION_HINT
85
88
  });
86
89
  return defineRuleListener(visitor, { "Program:exit"(program) {
87
- for (const { name, displayName, flag, hookCalls, node } of ctx.getAllComponents(program)) context.report({
90
+ for (const { name, displayName, flag, hookCalls, node } of api.getAllComponents(program)) context.report({
88
91
  data: { json: stringify({
89
92
  name: name ?? "anonymous",
90
93
  displayName: displayName == null ? "none" : context.sourceCode.getText(displayName),
@@ -113,9 +116,9 @@ var hook_default = createRule({
113
116
  defaultOptions: []
114
117
  });
115
118
  function create$3(context) {
116
- const { ctx, visitor } = core.useHookCollector(context);
119
+ const { api, visitor } = core.getHookCollector(context);
117
120
  return defineRuleListener(visitor, { "Program:exit"(program) {
118
- for (const { name, hookCalls, node } of ctx.getAllHooks(program)) context.report({
121
+ for (const { name, hookCalls, node } of api.getAllHooks(program)) context.report({
119
122
  data: { json: stringify({
120
123
  name,
121
124
  hookCalls: hookCalls.length
@@ -213,11 +216,29 @@ function create$1(context) {
213
216
  function getRefInitNode(node, initialScope) {
214
217
  const name = node.name;
215
218
  switch (true) {
216
- case node.parent.type === AST_NODE_TYPES.MemberExpression && node.parent.property === node && node.parent.object.type === AST_NODE_TYPES.Identifier: return core.getRefInit(node.parent.object.name, initialScope);
217
- case node.parent.type === AST_NODE_TYPES.JSXMemberExpression && node.parent.property === node && node.parent.object.type === AST_NODE_TYPES.JSXIdentifier: return core.getRefInit(node.parent.object.name, initialScope);
218
- default: return core.getRefInit(name, initialScope);
219
+ case node.parent.type === AST_NODE_TYPES.MemberExpression && node.parent.property === node && node.parent.object.type === AST_NODE_TYPES.Identifier: return getRefInit(node.parent.object.name, initialScope);
220
+ case node.parent.type === AST_NODE_TYPES.JSXMemberExpression && node.parent.property === node && node.parent.object.type === AST_NODE_TYPES.JSXIdentifier: return getRefInit(node.parent.object.name, initialScope);
221
+ default: return getRefInit(name, initialScope);
219
222
  }
220
223
  }
224
+ /**
225
+ * Get the init expression of a ref variable
226
+ * @param name The variable name
227
+ * @param initialScope The initial scope
228
+ * @returns The init expression node if the variable is derived from a ref, or null otherwise
229
+ */
230
+ function getRefInit(name, initialScope) {
231
+ for (const { node } of findVariable(initialScope, name)?.defs ?? []) {
232
+ if (node.type !== AST_NODE_TYPES.VariableDeclarator) continue;
233
+ const init = node.init;
234
+ if (init == null) continue;
235
+ switch (true) {
236
+ case init.type === AST_NODE_TYPES.MemberExpression && init.object.type === AST_NODE_TYPES.Identifier && (init.object.name === "ref" || init.object.name.endsWith("Ref")): return init;
237
+ case init.type === AST_NODE_TYPES.CallExpression && isUseRefCall(init): return init;
238
+ }
239
+ }
240
+ return null;
241
+ }
221
242
 
222
243
  //#endregion
223
244
  //#region ../../../.pkgs/eff/dist/index.js
@@ -381,13 +402,12 @@ var jsx_default = createRule({
381
402
  defaultOptions: []
382
403
  });
383
404
  function create(context) {
384
- const jsx = JsxInspector.from(context);
385
- const jsxConfig = jsx.jsxConfig;
405
+ const jsxConfig = getJsxConfig(context);
386
406
  function getReportDescriptor(context) {
387
407
  return (node) => ({
388
408
  data: { json: stringify({
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),
409
+ kind: match(node).with({ type: AST_NODE_TYPES$1.JSXElement }, (n) => isFragmentElement(n, jsxConfig.jsxFragmentFactory) ? "fragment" : "element").with({ type: AST_NODE_TYPES$1.JSXFragment }, () => "fragment").exhaustive(),
410
+ type: getElementFullType(node),
391
411
  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"),
392
412
  jsxFactory: jsxConfig.jsxFactory,
393
413
  jsxFragmentFactory: jsxConfig.jsxFragmentFactory,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-debug",
3
- "version": "3.0.0-rc.5",
3
+ "version": "4.0.0-beta.0",
4
4
  "description": "ESLint React's ESLint plugin for debugging related rules.",
5
5
  "keywords": [
6
6
  "react",
@@ -38,21 +38,22 @@
38
38
  "./package.json"
39
39
  ],
40
40
  "dependencies": {
41
- "@typescript-eslint/scope-manager": "^8.57.0",
42
- "@typescript-eslint/type-utils": "^8.57.0",
43
- "@typescript-eslint/types": "^8.57.0",
44
- "@typescript-eslint/utils": "^8.57.0",
41
+ "@typescript-eslint/scope-manager": "^8.57.2",
42
+ "@typescript-eslint/type-utils": "^8.57.2",
43
+ "@typescript-eslint/types": "^8.57.2",
44
+ "@typescript-eslint/utils": "^8.57.2",
45
45
  "ts-pattern": "^5.9.0",
46
- "@eslint-react/core": "3.0.0-rc.5",
47
- "@eslint-react/ast": "3.0.0-rc.5",
48
- "@eslint-react/var": "3.0.0-rc.5",
49
- "@eslint-react/shared": "3.0.0-rc.5"
46
+ "@eslint-react/ast": "4.0.0-beta.0",
47
+ "@eslint-react/core": "4.0.0-beta.0",
48
+ "@eslint-react/jsx": "4.0.0-beta.0",
49
+ "@eslint-react/shared": "4.0.0-beta.0",
50
+ "@eslint-react/var": "4.0.0-beta.0"
50
51
  },
51
52
  "devDependencies": {
52
53
  "@types/react": "^19.2.14",
53
54
  "@types/react-dom": "^19.2.3",
54
- "eslint": "^10.0.3",
55
- "tsdown": "^0.21.2",
55
+ "eslint": "^10.1.0",
56
+ "tsdown": "^0.21.4",
56
57
  "@local/configs": "0.0.0",
57
58
  "@local/eff": "3.0.0-beta.72"
58
59
  },