@murky-web/oxlint-plugin-solid 1.4.1 → 1.5.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.
@@ -18,7 +18,7 @@ import {
18
18
  ignoreTransparentWrappers,
19
19
  getFunctionName,
20
20
  isJSXElementOrFragment,
21
- trace,
21
+ trace
22
22
  } from "../utils.mjs";
23
23
  // Solid 2.0 removed `createResource`, `createMutable`, `indexArray` and
24
24
  // `<Index>`. Their branches below are kept structurally but matched against
@@ -49,10 +49,10 @@ class ScopeStack extends Array {
49
49
  pushSignal(variable, declarationScope = this.currentScope().node) {
50
50
  this.signals.push({
51
51
  references: variable.references.filter(
52
- (reference) => !reference.init,
52
+ (reference) => !reference.init
53
53
  ),
54
54
  variable,
55
- declarationScope,
55
+ declarationScope
56
56
  });
57
57
  }
58
58
  /**
@@ -68,7 +68,7 @@ class ScopeStack extends Array {
68
68
  } else {
69
69
  foundSignal.declarationScope = this.findDeepestDeclarationScope(
70
70
  foundSignal.declarationScope,
71
- declarationScope,
71
+ declarationScope
72
72
  );
73
73
  }
74
74
  }
@@ -76,10 +76,10 @@ class ScopeStack extends Array {
76
76
  pushProps(variable, declarationScope = this.currentScope().node) {
77
77
  this.props.push({
78
78
  references: variable.references.filter(
79
- (reference) => !reference.init,
79
+ (reference) => !reference.init
80
80
  ),
81
81
  variable,
82
- declarationScope,
82
+ declarationScope
83
83
  });
84
84
  }
85
85
  /** Function callbacks that run synchronously and don't create a new scope. */
@@ -92,14 +92,14 @@ class ScopeStack extends Array {
92
92
  *consumeSignalReferencesInScope() {
93
93
  yield* this.consumeReferencesInScope(this.signals);
94
94
  this.signals = this.signals.filter(
95
- (variable) => variable.references.length !== 0,
95
+ (variable) => variable.references.length !== 0
96
96
  );
97
97
  }
98
98
  /** Iterate through and remove the props references in the current scope. */
99
99
  *consumePropsReferencesInScope() {
100
100
  yield* this.consumeReferencesInScope(this.props);
101
101
  this.props = this.props.filter(
102
- (variable) => variable.references.length !== 0,
102
+ (variable) => variable.references.length !== 0
103
103
  );
104
104
  }
105
105
  *consumeReferencesInScope(variables) {
@@ -116,7 +116,7 @@ class ScopeStack extends Array {
116
116
  });
117
117
  yield* inScope.map((reference) => ({
118
118
  reference,
119
- declarationScope: variable.declarationScope,
119
+ declarationScope: variable.declarationScope
120
120
  }));
121
121
  // I don't think this is needed! Just a perf optimization
122
122
  variable.references = notInScope;
@@ -143,7 +143,7 @@ class ScopeStack extends Array {
143
143
  isReferenceInCurrentScope(reference) {
144
144
  let parentFunction = findParent(
145
145
  reference.identifier,
146
- isProgramOrFunctionNode,
146
+ isProgramOrFunctionNode
147
147
  );
148
148
  while (
149
149
  isFunctionNode(parentFunction) &&
@@ -151,7 +151,7 @@ class ScopeStack extends Array {
151
151
  ) {
152
152
  parentFunction = findParent(
153
153
  parentFunction,
154
- isProgramOrFunctionNode,
154
+ isProgramOrFunctionNode
155
155
  );
156
156
  }
157
157
  return parentFunction === this.currentScope().node;
@@ -185,7 +185,7 @@ export default {
185
185
  docs: {
186
186
  description:
187
187
  "Enforce that reactivity (props, signals, memos, etc.) is properly used, so changes in those values will be tracked and update the view as expected.",
188
- url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/reactivity.md",
188
+ url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/reactivity.md"
189
189
  },
190
190
  schema: [
191
191
  {
@@ -196,13 +196,13 @@ export default {
196
196
  "List of function names to consider as reactive functions (allow signals to be safely passed as arguments). In addition, any create* or use* functions are automatically included.",
197
197
  type: "array",
198
198
  items: {
199
- type: "string",
199
+ type: "string"
200
200
  },
201
- default: [],
202
- },
201
+ default: []
202
+ }
203
203
  },
204
- additionalProperties: false,
205
- },
204
+ additionalProperties: false
205
+ }
206
206
  ],
207
207
  messages: {
208
208
  noWrite:
@@ -220,13 +220,13 @@ export default {
220
220
  shouldAssign:
221
221
  "For proper analysis, a variable should be used to capture the result of this function call.",
222
222
  noAsyncTrackedScope:
223
- "The reactive variable '{{name}}' is read after an await, so it registers no dependency and this computation will not re-run when it changes. Read every reactive input before the first async gap.",
224
- },
223
+ "The reactive variable '{{name}}' is read after an await, so it registers no dependency and this computation will not re-run when it changes. Read every reactive input before the first async gap."
224
+ }
225
225
  },
226
226
  defaultOptions: [
227
227
  {
228
- customReactiveFunctions: [],
229
- },
228
+ customReactiveFunctions: []
229
+ }
230
230
  ],
231
231
  create(context) {
232
232
  // `RuleCreator` used to merge `defaultOptions` into `context.options`
@@ -238,7 +238,7 @@ export default {
238
238
  context.report({
239
239
  node,
240
240
  messageId: "shouldDestructure",
241
- data: nth ? { nth: nth + " " } : undefined,
241
+ data: nth ? { nth: nth + " " } : undefined
242
242
  });
243
243
  const warnShouldAssign = (node) =>
244
244
  context.report({ node, messageId: "shouldAssign" });
@@ -275,7 +275,7 @@ export default {
275
275
  return;
276
276
  }
277
277
  markPropsOnCondition(node, (props) =>
278
- isPropsByName(props.name),
278
+ isPropsByName(props.name)
279
279
  );
280
280
  }
281
281
  scopeStack.push(new ScopeStackItem(node));
@@ -294,8 +294,8 @@ export default {
294
294
  findInScope(
295
295
  node,
296
296
  currentScope().node,
297
- (node) => node === trackedScope.node,
298
- ),
297
+ (node) => node === trackedScope.node
298
+ )
299
299
  );
300
300
  }
301
301
  };
@@ -308,15 +308,15 @@ export default {
308
308
  // Check if the call falls outside any tracked scopes in the current scope
309
309
  if (
310
310
  !currentScope().trackedScopes.find((trackedScope) =>
311
- matchTrackedScope(trackedScope, identifier),
311
+ matchTrackedScope(trackedScope, identifier)
312
312
  )
313
313
  ) {
314
314
  const matchedExpression = currentScope().trackedScopes.find(
315
315
  (trackedScope) =>
316
316
  matchTrackedScope(
317
317
  { ...trackedScope, expect: "expression" },
318
- identifier,
319
- ),
318
+ identifier
319
+ )
320
320
  );
321
321
  if (declarationScope === currentScopeNode) {
322
322
  // If the reactivity is not contained in a tracked scope, and any of
@@ -350,8 +350,8 @@ export default {
350
350
  data: {
351
351
  name: parentMemberExpression
352
352
  ? sourceCode.getText(parentMemberExpression)
353
- : identifier.name,
354
- },
353
+ : identifier.name
354
+ }
355
355
  });
356
356
  } else {
357
357
  // If all of the reactive variables were declared above the current
@@ -367,18 +367,18 @@ export default {
367
367
  // of the tracked scopes, as we can't easily find references.
368
368
  const pushUnnamedDerivedSignal = () =>
369
369
  (parentScope().unnamedDerivedSignals ??= new Set()).add(
370
- currentScopeNode,
370
+ currentScopeNode
371
371
  );
372
372
  if (currentScopeNode.type === "FunctionDeclaration") {
373
373
  // get variable representing function, function node only defines one variable
374
374
  const functionVariable =
375
375
  sourceCode.scopeManager?.getDeclaredVariables(
376
- currentScopeNode,
376
+ currentScopeNode
377
377
  )?.[0];
378
378
  if (functionVariable) {
379
379
  scopeStack.pushUniqueSignal(
380
380
  functionVariable,
381
- declarationScope, // use declaration scope of a signal contained in this function
381
+ declarationScope // use declaration scope of a signal contained in this function
382
382
  );
383
383
  } else {
384
384
  pushUnnamedDerivedSignal();
@@ -390,13 +390,13 @@ export default {
390
390
  // for nameless or arrow function expressions, use the declared variable it's assigned to
391
391
  const functionVariable =
392
392
  sourceCode.scopeManager?.getDeclaredVariables(
393
- declarator,
393
+ declarator
394
394
  )?.[0];
395
395
  if (functionVariable) {
396
396
  // use declaration scope of a signal contained in this scope, not the function itself
397
397
  scopeStack.pushUniqueSignal(
398
398
  functionVariable,
399
- declarationScope,
399
+ declarationScope
400
400
  );
401
401
  } else {
402
402
  pushUnnamedDerivedSignal();
@@ -513,7 +513,7 @@ export default {
513
513
  // Iterate through all usages of (derived) signals in the current scope
514
514
  for (const {
515
515
  reference,
516
- declarationScope,
516
+ declarationScope
517
517
  } of scopeStack.consumeSignalReferencesInScope()) {
518
518
  const identifier = reference.identifier;
519
519
  if (
@@ -524,7 +524,7 @@ export default {
524
524
  context.report({
525
525
  node: identifier,
526
526
  messageId: "noAsyncTrackedScope",
527
- data: { name: identifier.name },
527
+ data: { name: identifier.name }
528
528
  });
529
529
  }
530
530
  if (reference.isWrite()) {
@@ -533,15 +533,15 @@ export default {
533
533
  node: identifier,
534
534
  messageId: "noWrite",
535
535
  data: {
536
- name: identifier.name,
537
- },
536
+ name: identifier.name
537
+ }
538
538
  });
539
539
  } else if (identifier.type === "Identifier") {
540
540
  const reportBadSignal = (where) =>
541
541
  context.report({
542
542
  node: identifier,
543
543
  messageId: "badSignal",
544
- data: { name: identifier.name, where },
544
+ data: { name: identifier.name, where }
545
545
  });
546
546
  if (
547
547
  // This allows both calling a signal and calling a function with a signal.
@@ -573,7 +573,7 @@ export default {
573
573
  "|",
574
574
  "^",
575
575
  "&",
576
- "in",
576
+ "in"
577
577
  ].includes(identifier.parent.operator)
578
578
  ) {
579
579
  // We're in an arithmetic/comparison expression where using an uncalled signal wouldn't make sense
@@ -597,7 +597,7 @@ export default {
597
597
  (trackedScope) =>
598
598
  trackedScope.node === identifier &&
599
599
  (trackedScope.expect === "function" ||
600
- trackedScope.expect === "called-function"),
600
+ trackedScope.expect === "called-function")
601
601
  )
602
602
  ) {
603
603
  // If the signal is in a JSXExpressionContainer that's also marked as a "function" or "called-function" tracked scope,
@@ -615,7 +615,7 @@ export default {
615
615
  elementOrAttribute.parent.name.type ===
616
616
  "JSXIdentifier" &&
617
617
  isDOMElementName(
618
- elementOrAttribute.parent.name.name,
618
+ elementOrAttribute.parent.name.name
619
619
  ))
620
620
  ) {
621
621
  reportBadSignal("JSX");
@@ -629,7 +629,7 @@ export default {
629
629
  // Do a similar thing with all usages of props in the current function
630
630
  for (const {
631
631
  reference,
632
- declarationScope,
632
+ declarationScope
633
633
  } of scopeStack.consumePropsReferencesInScope()) {
634
634
  const identifier = reference.identifier;
635
635
  if (reference.isWrite()) {
@@ -638,8 +638,8 @@ export default {
638
638
  node: identifier,
639
639
  messageId: "noWrite",
640
640
  data: {
641
- name: identifier.name,
642
- },
641
+ name: identifier.name
642
+ }
643
643
  });
644
644
  } else if (
645
645
  identifier.parent?.type === "MemberExpression" &&
@@ -655,13 +655,13 @@ export default {
655
655
  node: identifier,
656
656
  messageId: "noWrite",
657
657
  data: {
658
- name: identifier.name,
659
- },
658
+ name: identifier.name
659
+ }
660
660
  });
661
661
  } else if (
662
662
  parent.property.type === "Identifier" &&
663
663
  /^(?:initial|default|static[A-Z])/.test(
664
- parent.property.name,
664
+ parent.property.name
665
665
  )
666
666
  ) {
667
667
  // We're using a prop with a name that starts with `initial` or
@@ -682,7 +682,7 @@ export default {
682
682
  context.report({
683
683
  node: identifier,
684
684
  messageId: "untrackedReactive",
685
- data: { name: identifier.name },
685
+ data: { name: identifier.name }
686
686
  });
687
687
  }
688
688
  // The props are being read, but not in a MemberExpression. Since
@@ -697,12 +697,12 @@ export default {
697
697
  for (const node of unnamedDerivedSignals) {
698
698
  if (
699
699
  !currentScope().trackedScopes.find((trackedScope) =>
700
- matchTrackedScope(trackedScope, node),
700
+ matchTrackedScope(trackedScope, node)
701
701
  )
702
702
  ) {
703
703
  context.report({
704
704
  loc: getFunctionHeadLocation(node, sourceCode),
705
- messageId: "badUnnamedDerivedSignal",
705
+ messageId: "badUnnamedDerivedSignal"
706
706
  });
707
707
  }
708
708
  }
@@ -743,7 +743,7 @@ export default {
743
743
  !node.callee.computed &&
744
744
  node.callee.object.type !== "ObjectExpression" &&
745
745
  /^(?:forEach|map|flatMap|reduce|reduceRight|find|findIndex|filter|every|some)$/.test(
746
- node.callee.property.name,
746
+ node.callee.property.name
747
747
  )
748
748
  ) {
749
749
  // These common array methods (or likely array methods) take synchronous callbacks
@@ -754,7 +754,7 @@ export default {
754
754
  if (
755
755
  matchImport(
756
756
  ["createSignal", "createStore"],
757
- node.callee.name,
757
+ node.callee.name
758
758
  ) &&
759
759
  node.parent?.type === "VariableDeclarator"
760
760
  ) {
@@ -764,7 +764,7 @@ export default {
764
764
  const setter = getNthDestructuredVar(
765
765
  node.parent.id,
766
766
  1,
767
- context,
767
+ context
768
768
  );
769
769
  if (setter) {
770
770
  for (const reference of setter.references) {
@@ -818,7 +818,7 @@ export default {
818
818
  } else if (
819
819
  matchImport(
820
820
  ["createMemo", "createDeferred", "createProjection"],
821
- callee.name,
821
+ callee.name
822
822
  )
823
823
  ) {
824
824
  const memo = id && getReturnedVar(id, context);
@@ -848,7 +848,7 @@ export default {
848
848
  if (id?.type === "ArrayPattern") {
849
849
  const vars = id.elements
850
850
  .map((_, i) =>
851
- getNthDestructuredVar(id, i, context),
851
+ getNthDestructuredVar(id, i, context)
852
852
  )
853
853
  .filter(Boolean);
854
854
  if (vars.length === 0) {
@@ -857,7 +857,7 @@ export default {
857
857
  vars.forEach((variable) => {
858
858
  scopeStack.pushProps(
859
859
  variable,
860
- currentScope().node,
860
+ currentScope().node
861
861
  );
862
862
  });
863
863
  }
@@ -877,7 +877,7 @@ export default {
877
877
  if (resourceReturn) {
878
878
  scopeStack.pushProps(
879
879
  resourceReturn,
880
- currentScope().node,
880
+ currentScope().node
881
881
  );
882
882
  }
883
883
  } else if (
@@ -896,7 +896,7 @@ export default {
896
896
  ) {
897
897
  const indexSignal = findVariable(
898
898
  context,
899
- arg1.params[1],
899
+ arg1.params[1]
900
900
  );
901
901
  if (indexSignal) {
902
902
  scopeStack.pushSignal(indexSignal);
@@ -911,7 +911,7 @@ export default {
911
911
  ) {
912
912
  const valueSignal = findVariable(
913
913
  context,
914
- arg1.params[0],
914
+ arg1.params[0]
915
915
  );
916
916
  if (valueSignal) {
917
917
  scopeStack.pushSignal(valueSignal);
@@ -945,7 +945,7 @@ export default {
945
945
  this.skip(); // poor-man's `findInScope`: don't enter child scopes
946
946
  }
947
947
  },
948
- fallback: "iteration", // Don't crash when encounter unknown node.
948
+ fallback: "iteration" // Don't crash when encounter unknown node.
949
949
  });
950
950
  };
951
951
  if (node.type === "JSXExpressionContainer") {
@@ -1030,7 +1030,7 @@ export default {
1030
1030
  } else if (node.type === "NewExpression") {
1031
1031
  const {
1032
1032
  callee,
1033
- arguments: { 0: arg0 },
1033
+ arguments: { 0: arg0 }
1034
1034
  } = node;
1035
1035
  if (
1036
1036
  callee.type === "Identifier" &&
@@ -1041,7 +1041,7 @@ export default {
1041
1041
  "MutationObserver",
1042
1042
  "PerformanceObserver",
1043
1043
  "ReportingObserver",
1044
- "ResizeObserver",
1044
+ "ResizeObserver"
1045
1045
  ].includes(callee.name)
1046
1046
  ) {
1047
1047
  // Observers callbacks are NOT tracked scopes. However, they
@@ -1054,7 +1054,7 @@ export default {
1054
1054
  if (node.callee.type === "Identifier") {
1055
1055
  const {
1056
1056
  callee,
1057
- arguments: { 0: arg0, 1: arg1 },
1057
+ arguments: { 0: arg0, 1: arg1 }
1058
1058
  } = node;
1059
1059
  if (
1060
1060
  matchImport(
@@ -1071,9 +1071,9 @@ export default {
1071
1071
  "latest",
1072
1072
  "resolve",
1073
1073
  // The predicate is re-evaluated reactively until it is truthy.
1074
- "until",
1074
+ "until"
1075
1075
  ],
1076
- callee.name,
1076
+ callee.name
1077
1077
  ) ||
1078
1078
  false /* Solid 2.0 removed createResource */
1079
1079
  ) {
@@ -1082,7 +1082,7 @@ export default {
1082
1082
  } else if (
1083
1083
  matchImport(
1084
1084
  ["createEffect", "createRenderEffect"],
1085
- callee.name,
1085
+ callee.name
1086
1086
  )
1087
1087
  ) {
1088
1088
  // Solid 2.0 split these into `(compute, apply)`. The
@@ -1100,7 +1100,7 @@ export default {
1100
1100
  ) {
1101
1101
  pushTrackedScope(
1102
1102
  property.value,
1103
- "called-function",
1103
+ "called-function"
1104
1104
  );
1105
1105
  }
1106
1106
  }
@@ -1115,7 +1115,7 @@ export default {
1115
1115
  } else if (
1116
1116
  matchImport(
1117
1117
  ["onSettled", "onFlush", "onCleanup"],
1118
- callee.name,
1118
+ callee.name
1119
1119
  ) ||
1120
1120
  [
1121
1121
  // Timers
@@ -1123,7 +1123,7 @@ export default {
1123
1123
  "setTimeout",
1124
1124
  "setImmediate",
1125
1125
  "requestAnimationFrame",
1126
- "requestIdleCallback",
1126
+ "requestIdleCallback"
1127
1127
  ].includes(callee.name)
1128
1128
  ) {
1129
1129
  // on* and timers are NOT tracked scopes. However, they
@@ -1185,19 +1185,18 @@ export default {
1185
1185
  "Identifier" &&
1186
1186
  matchImport(
1187
1187
  "getOwner",
1188
- decl.node.init.callee.name,
1188
+ decl.node.init.callee.name
1189
1189
  )
1190
1190
  ) {
1191
1191
  // Check if the function in which getOwner() is called is a tracked scope. If the scopeStack
1192
1192
  // has moved on from that scope already, assume it's tracked, since that's less intrusive.
1193
1193
  const ownerFunction = findParent(
1194
1194
  decl.node,
1195
- isProgramOrFunctionNode,
1195
+ isProgramOrFunctionNode
1196
1196
  );
1197
1197
  const scopeStackIndex =
1198
1198
  scopeStack.findIndex(
1199
- ({ node }) =>
1200
- ownerFunction === node,
1199
+ ({ node }) => ownerFunction === node
1201
1200
  );
1202
1201
  if (
1203
1202
  (scopeStackIndex >= 1 &&
@@ -1208,7 +1207,7 @@ export default {
1208
1207
  trackedScope.expect ===
1209
1208
  "function" &&
1210
1209
  trackedScope.node ===
1211
- ownerFunction,
1210
+ ownerFunction
1212
1211
  )) ||
1213
1212
  scopeStackIndex === 0
1214
1213
  ) {
@@ -1244,7 +1243,7 @@ export default {
1244
1243
  property.type === "Identifier" &&
1245
1244
  (/^(?:use|create)[A-Z]/.test(property.name) ||
1246
1245
  options.customReactiveFunctions.includes(
1247
- property.name,
1246
+ property.name
1248
1247
  ))
1249
1248
  ) {
1250
1249
  // Handle custom hook parameters for property access custom hooks
@@ -1264,7 +1263,7 @@ export default {
1264
1263
  if (
1265
1264
  matchImport(
1266
1265
  ["createReactive", "createReaction"],
1267
- node.init.callee.name,
1266
+ node.init.callee.name
1268
1267
  )
1269
1268
  ) {
1270
1269
  const track = getReturnedVar(node.id, context);
@@ -1290,7 +1289,7 @@ export default {
1290
1289
  if (isFunctionNode(node.init.arguments[0])) {
1291
1290
  pushTrackedScope(
1292
1291
  node.init.arguments[0],
1293
- "called-function",
1292
+ "called-function"
1294
1293
  );
1295
1294
  }
1296
1295
  }
@@ -1327,7 +1326,7 @@ export default {
1327
1326
  if (variable)
1328
1327
  scopeStack.pushProps(
1329
1328
  variable,
1330
- currentScope().node,
1329
+ currentScope().node
1331
1330
  );
1332
1331
  }
1333
1332
  }
@@ -1393,7 +1392,7 @@ export default {
1393
1392
  if (index) {
1394
1393
  scopeStack.pushSignal(
1395
1394
  index,
1396
- currentScope().node,
1395
+ currentScope().node
1397
1396
  );
1398
1397
  }
1399
1398
  } else if (
@@ -1406,7 +1405,7 @@ export default {
1406
1405
  if (item) {
1407
1406
  scopeStack.pushSignal(
1408
1407
  item,
1409
- currentScope().node,
1408
+ currentScope().node
1410
1409
  );
1411
1410
  }
1412
1411
  }
@@ -1432,7 +1431,7 @@ export default {
1432
1431
  if (scopeStack.length) {
1433
1432
  currentScope().hasJSX = true;
1434
1433
  }
1435
- },
1434
+ }
1436
1435
  };
1437
- },
1436
+ }
1438
1437
  };