eslint-plugin-react-web-api 3.0.0-next.2 → 3.0.0-next.23

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 (2) hide show
  1. package/dist/index.js +22 -30
  2. package/package.json +10 -10
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- import { DEFAULT_ESLINT_REACT_SETTINGS, WEBSITE_URL, getConfigAdapters } from "@eslint-react/shared";
1
+ import { DEFAULT_ESLINT_REACT_SETTINGS, WEBSITE_URL, defineRuleListener, getConfigAdapters } from "@eslint-react/shared";
2
2
  import * as ast from "@eslint-react/ast";
3
3
  import * as core from "@eslint-react/core";
4
4
  import { dual, or, unit } from "@eslint-react/eff";
5
- import { findEnclosingAssignmentTarget, findProperty, findVariable, getVariableDefinitionNode, isAssignmentTargetEqual, isNodeEqual } from "@eslint-react/var";
5
+ import { findEnclosingAssignmentTarget, findProperty, findVariable, getVariableInitializer, isAssignmentTargetEqual, isValueEqual } from "@eslint-react/var";
6
6
  import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
7
7
  import { getStaticValue } from "@typescript-eslint/utils/ast-utils";
8
8
  import { P, isMatching, match } from "ts-pattern";
@@ -43,7 +43,7 @@ const settings = { "react-x": DEFAULT_ESLINT_REACT_SETTINGS };
43
43
  //#endregion
44
44
  //#region package.json
45
45
  var name = "eslint-plugin-react-web-api";
46
- var version = "3.0.0-next.2";
46
+ var version = "3.0.0-next.23";
47
47
 
48
48
  //#endregion
49
49
  //#region src/types/component-phase.ts
@@ -83,7 +83,7 @@ function getFunctionKind$1(node) {
83
83
  function getSignalValueExpression(node, initialScope) {
84
84
  if (node == null) return unit;
85
85
  switch (node.type) {
86
- case AST_NODE_TYPES.Identifier: return getSignalValueExpression(getVariableDefinitionNode(findVariable(node, initialScope), 0), initialScope);
86
+ case AST_NODE_TYPES.Identifier: return getSignalValueExpression(getVariableInitializer(findVariable(node, initialScope), 0), initialScope);
87
87
  case AST_NODE_TYPES.MemberExpression: return node;
88
88
  default: return unit;
89
89
  }
@@ -92,24 +92,10 @@ function getOptions(node, initialScope) {
92
92
  function findProp(properties, propName) {
93
93
  return findProperty(propName, properties, initialScope);
94
94
  }
95
- function getPropValue(prop, filter = (a) => true) {
96
- if (prop?.type !== AST_NODE_TYPES.Property) return unit;
97
- const { value } = prop;
98
- let v = value;
99
- switch (value.type) {
100
- case AST_NODE_TYPES.Literal:
101
- v = value.value;
102
- break;
103
- default:
104
- v = getStaticValue(value, initialScope)?.value;
105
- break;
106
- }
107
- return filter(v) ? v : unit;
108
- }
109
95
  function getOpts(node) {
110
96
  switch (node.type) {
111
97
  case AST_NODE_TYPES.Identifier: {
112
- const variableNode = getVariableDefinitionNode(findVariable(node, initialScope), 0);
98
+ const variableNode = getVariableInitializer(findVariable(node, initialScope), 0);
113
99
  if (variableNode?.type === AST_NODE_TYPES.ObjectExpression) return getOpts(variableNode);
114
100
  return defaultOptions;
115
101
  }
@@ -118,7 +104,13 @@ function getOptions(node, initialScope) {
118
104
  capture: Boolean(node.value)
119
105
  };
120
106
  case AST_NODE_TYPES.ObjectExpression: {
121
- const vCapture = !!getPropValue(findProp(node.properties, "capture"));
107
+ const vCapture = match(findProp(node.properties, "capture")).with(P.nullish, () => false).with({ type: AST_NODE_TYPES.Property }, (prop) => {
108
+ const value = prop.value;
109
+ switch (value.type) {
110
+ case AST_NODE_TYPES.Literal: return Boolean(value.value);
111
+ default: return Boolean(getStaticValue(value, initialScope)?.value);
112
+ }
113
+ }).otherwise(() => false);
122
114
  const pSignal = findProp(node.properties, "signal");
123
115
  return {
124
116
  capture: vCapture,
@@ -162,7 +154,7 @@ function create$3(context) {
162
154
  const { type: aType, callee: aCallee, capture: aCapture, listener: aListener, phase: aPhase } = aEntry;
163
155
  const { type: rType, callee: rCallee, capture: rCapture, listener: rListener, phase: rPhase } = rEntry;
164
156
  if (!isInversePhase(aPhase, rPhase)) return false;
165
- return isSameObject(aCallee, rCallee) && ast.isNodeEqual(aListener, rListener) && isNodeEqual(aType, rType, [context.sourceCode.getScope(aType), context.sourceCode.getScope(rType)]) && aCapture === rCapture;
157
+ return isSameObject(aCallee, rCallee) && ast.isNodeEqual(aListener, rListener) && isValueEqual(aType, rType, [context.sourceCode.getScope(aType), context.sourceCode.getScope(rType)]) && aCapture === rCapture;
166
158
  }
167
159
  function checkInlineFunction(node, callKind, options) {
168
160
  const listener = node.arguments.at(1);
@@ -174,7 +166,7 @@ function create$3(context) {
174
166
  data: { eventMethodKind: callKind }
175
167
  });
176
168
  }
177
- return {
169
+ return defineRuleListener({
178
170
  [":function"](node) {
179
171
  const kind = getFunctionKind$1(node);
180
172
  fEntries.push({
@@ -247,7 +239,7 @@ function create$3(context) {
247
239
  }
248
240
  }
249
241
  }
250
- };
242
+ });
251
243
  }
252
244
 
253
245
  //#endregion
@@ -283,7 +275,7 @@ function create$2(context) {
283
275
  function isInverseEntry(a, b) {
284
276
  return isAssignmentTargetEqual(context, a.timerId, b.timerId);
285
277
  }
286
- return {
278
+ return defineRuleListener({
287
279
  [":function"](node) {
288
280
  const kind = getPhaseKindOfFunction(node) ?? "other";
289
281
  fEntries.push({
@@ -357,7 +349,7 @@ function create$2(context) {
357
349
  }
358
350
  }
359
351
  }
360
- };
352
+ });
361
353
  }
362
354
 
363
355
  //#endregion
@@ -368,7 +360,7 @@ function isNewResizeObserver(node) {
368
360
  }
369
361
  function isFromObserver(context, node) {
370
362
  switch (true) {
371
- case node.type === AST_NODE_TYPES.Identifier: return isNewResizeObserver(getVariableDefinitionNode(findVariable(node, context.sourceCode.getScope(node)), 0));
363
+ case node.type === AST_NODE_TYPES.Identifier: return isNewResizeObserver(getVariableInitializer(findVariable(node, context.sourceCode.getScope(node)), 0));
372
364
  case node.type === AST_NODE_TYPES.MemberExpression: return isFromObserver(context, node.object);
373
365
  default: return false;
374
366
  }
@@ -405,7 +397,7 @@ function create$1(context) {
405
397
  const oEntries = [];
406
398
  const uEntries = [];
407
399
  const dEntries = [];
408
- return {
400
+ return defineRuleListener({
409
401
  [":function"](node) {
410
402
  const kind = getFunctionKind(node);
411
403
  fEntries.push({
@@ -499,7 +491,7 @@ function create$1(context) {
499
491
  }
500
492
  }
501
493
  }
502
- };
494
+ });
503
495
  }
504
496
 
505
497
  //#endregion
@@ -535,7 +527,7 @@ function create(context) {
535
527
  function isInverseEntry(a, b) {
536
528
  return isAssignmentTargetEqual(context, a.timerId, b.timerId);
537
529
  }
538
- return {
530
+ return defineRuleListener({
539
531
  [":function"](node) {
540
532
  const kind = getPhaseKindOfFunction(node) ?? "other";
541
533
  fEntries.push({
@@ -605,7 +597,7 @@ function create(context) {
605
597
  }
606
598
  }
607
599
  }
608
- };
600
+ });
609
601
  }
610
602
 
611
603
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-web-api",
3
- "version": "3.0.0-next.2",
3
+ "version": "3.0.0-next.23",
4
4
  "description": "ESLint React's ESLint plugin for interacting with Web APIs",
5
5
  "keywords": [
6
6
  "react",
@@ -38,16 +38,16 @@
38
38
  "./package.json"
39
39
  ],
40
40
  "dependencies": {
41
- "@typescript-eslint/scope-manager": "^8.56.0",
42
- "@typescript-eslint/types": "^8.56.0",
43
- "@typescript-eslint/utils": "^8.56.0",
41
+ "@typescript-eslint/scope-manager": "canary",
42
+ "@typescript-eslint/types": "canary",
43
+ "@typescript-eslint/utils": "canary",
44
44
  "birecord": "^0.1.1",
45
45
  "ts-pattern": "^5.9.0",
46
- "@eslint-react/ast": "3.0.0-next.2",
47
- "@eslint-react/core": "3.0.0-next.2",
48
- "@eslint-react/var": "3.0.0-next.2",
49
- "@eslint-react/shared": "3.0.0-next.2",
50
- "@eslint-react/eff": "3.0.0-next.2"
46
+ "@eslint-react/ast": "3.0.0-next.23",
47
+ "@eslint-react/eff": "3.0.0-next.23",
48
+ "@eslint-react/core": "3.0.0-next.23",
49
+ "@eslint-react/shared": "3.0.0-next.23",
50
+ "@eslint-react/var": "3.0.0-next.23"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/react": "^19.2.14",
@@ -68,6 +68,6 @@
68
68
  "scripts": {
69
69
  "build": "tsdown",
70
70
  "lint:publish": "publint",
71
- "lint:ts": "tsc --noEmit"
71
+ "lint:ts": "tsl"
72
72
  }
73
73
  }