@murky-web/oxlint-plugin-solid 1.3.0 → 1.4.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.
- package/README.md +103 -48
- package/THIRD_PARTY_NOTICES.md +54 -0
- package/package.json +29 -25
- package/src/index.mjs +1 -1
- package/src/rules/event_handlers.mjs +6 -12
- package/src/rules/imports.mjs +59 -22
- package/src/rules/jsx_no_script_url.mjs +7 -3
- package/src/rules/jsx_no_undef.mjs +1 -0
- package/src/rules/no_destructure.mjs +393 -24
- package/src/rules/no_proxy_apis.mjs +3 -1
- package/src/rules/no_server_import_in_client.mjs +249 -36
- package/src/rules/no_unknown_namespaces.mjs +2 -1
- package/src/rules/prefer_arrow_components.mjs +232 -196
- package/src/rules/prefer_class_object.mjs +12 -4
- package/src/rules/reactive_async.mjs +16 -5
- package/src/rules/reactivity.mjs +66 -30
- package/src/rules/self_closing_comp.mjs +2 -2
- package/src/rules/style_prop.mjs +4 -1
- package/src/rules/validate_jsx_nesting.mjs +480 -7
- package/src/utils.mjs +77 -12
package/src/rules/reactivity.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* File overview here, scroll to bottom.
|
|
3
|
+
*
|
|
3
4
|
* @link https://github.com/solidjs-community/eslint-plugin-solid/blob/main/docs/reactivity.md
|
|
4
5
|
*/
|
|
5
6
|
import { getFunctionHeadLocation } from "@eslint-community/eslint-utils";
|
|
@@ -24,18 +25,18 @@ import {
|
|
|
24
25
|
// `__removed_*` names so they can never fire; delete them once no Solid 1
|
|
25
26
|
// code is linted with this plugin any more.
|
|
26
27
|
class ScopeStackItem {
|
|
27
|
-
/**
|
|
28
|
+
/** The node for the current scope, or program if global scope */
|
|
28
29
|
node;
|
|
29
30
|
/**
|
|
30
|
-
*
|
|
31
|
-
* JSXExpressionContainers can be any expression containing reactivity,
|
|
32
|
-
* function nodes/identifiers are typically arguments to solid-js
|
|
33
|
-
* and should match a tracked scope exactly.
|
|
31
|
+
* Nodes whose descendants in the current scope are allowed to be reactive.
|
|
32
|
+
* JSXExpressionContainers can be any expression containing reactivity,
|
|
33
|
+
* while function nodes/identifiers are typically arguments to solid-js
|
|
34
|
+
* primitives and should match a tracked scope exactly.
|
|
34
35
|
*/
|
|
35
36
|
trackedScopes = [];
|
|
36
|
-
/**
|
|
37
|
+
/** Nameless functions with reactivity, should exactly match a tracked scope */
|
|
37
38
|
unnamedDerivedSignals = new Set();
|
|
38
|
-
/**
|
|
39
|
+
/** Switched to true by time of :exit if JSX is detected in the current scope */
|
|
39
40
|
hasJSX = false;
|
|
40
41
|
constructor(node) {
|
|
41
42
|
this.node = node;
|
|
@@ -57,8 +58,8 @@ class ScopeStack extends Array {
|
|
|
57
58
|
/**
|
|
58
59
|
* Add references to a signal, merging with existing references if the
|
|
59
60
|
* variable is the same. Derived signals are special; they don't use the
|
|
60
|
-
* declaration scope of the function, but rather the minimum declaration
|
|
61
|
-
* of any signals they contain.
|
|
61
|
+
* declaration scope of the function, but rather the minimum declaration
|
|
62
|
+
* scope of any signals they contain.
|
|
62
63
|
*/
|
|
63
64
|
pushUniqueSignal(variable, declarationScope) {
|
|
64
65
|
const foundSignal = this.signals.find((s) => s.variable === variable);
|
|
@@ -85,7 +86,8 @@ class ScopeStack extends Array {
|
|
|
85
86
|
syncCallbacks = new Set();
|
|
86
87
|
/**
|
|
87
88
|
* Iterate through and remove the signal references in the current scope.
|
|
88
|
-
* That way, the next Scope up can safely check for references in its
|
|
89
|
+
* That way, the next Scope up can safely check for references in its
|
|
90
|
+
* scope.
|
|
89
91
|
*/
|
|
90
92
|
*consumeSignalReferencesInScope() {
|
|
91
93
|
yield* this.consumeReferencesInScope(this.signals);
|
|
@@ -120,7 +122,10 @@ class ScopeStack extends Array {
|
|
|
120
122
|
variable.references = notInScope;
|
|
121
123
|
}
|
|
122
124
|
}
|
|
123
|
-
/**
|
|
125
|
+
/**
|
|
126
|
+
* Returns the function node deepest in the tree. Assumes a === b, a is
|
|
127
|
+
* inside b, or b is inside a.
|
|
128
|
+
*/
|
|
124
129
|
findDeepestDeclarationScope = (a, b) => {
|
|
125
130
|
if (a === b) return a;
|
|
126
131
|
for (let i = this.length - 1; i >= 0; i -= 1) {
|
|
@@ -151,9 +156,12 @@ class ScopeStack extends Array {
|
|
|
151
156
|
}
|
|
152
157
|
return parentFunction === this.currentScope().node;
|
|
153
158
|
}
|
|
154
|
-
/**
|
|
159
|
+
/**
|
|
160
|
+
* Variable references to be treated as signals, memos, derived signals,
|
|
161
|
+
* etc.
|
|
162
|
+
*/
|
|
155
163
|
signals = [];
|
|
156
|
-
/**
|
|
164
|
+
/** Variables references to be treated as props (or stores) */
|
|
157
165
|
props = [];
|
|
158
166
|
}
|
|
159
167
|
const getNthDestructuredVar = (id, n, context) => {
|
|
@@ -235,7 +243,10 @@ export default {
|
|
|
235
243
|
const warnShouldAssign = (node) =>
|
|
236
244
|
context.report({ node, messageId: "shouldAssign" });
|
|
237
245
|
const sourceCode = getSourceCode(context);
|
|
238
|
-
/**
|
|
246
|
+
/**
|
|
247
|
+
* Represents the lexical function stack and relevant information for
|
|
248
|
+
* each function
|
|
249
|
+
*/
|
|
239
250
|
const scopeStack = new ScopeStack();
|
|
240
251
|
const { currentScope, parentScope } = scopeStack;
|
|
241
252
|
/** Tracks imports from 'solid-js', handling aliases. */
|
|
@@ -269,7 +280,10 @@ export default {
|
|
|
269
280
|
}
|
|
270
281
|
scopeStack.push(new ScopeStackItem(node));
|
|
271
282
|
};
|
|
272
|
-
/**
|
|
283
|
+
/**
|
|
284
|
+
* Returns whether a node falls under a tracked scope in the current
|
|
285
|
+
* function scope
|
|
286
|
+
*/
|
|
273
287
|
const matchTrackedScope = (trackedScope, node) => {
|
|
274
288
|
switch (trackedScope.expect) {
|
|
275
289
|
case "function":
|
|
@@ -285,7 +299,10 @@ export default {
|
|
|
285
299
|
);
|
|
286
300
|
}
|
|
287
301
|
};
|
|
288
|
-
/**
|
|
302
|
+
/**
|
|
303
|
+
* Inspects a specific reference of a reactive variable for correct
|
|
304
|
+
* handling.
|
|
305
|
+
*/
|
|
289
306
|
const handleTrackedScopes = (identifier, declarationScope) => {
|
|
290
307
|
const currentScopeNode = currentScope().node;
|
|
291
308
|
// Check if the call falls outside any tracked scopes in the current scope
|
|
@@ -398,10 +415,11 @@ export default {
|
|
|
398
415
|
/**
|
|
399
416
|
* Where a function first suspends, or null if it never does.
|
|
400
417
|
*
|
|
401
|
-
* `yield` counts alongside `await`: an async generator driven by
|
|
402
|
-
* suspends there in exactly the same way, and a read
|
|
403
|
-
* detached. Nested functions are skipped — their
|
|
404
|
-
* callback defined after an await still runs
|
|
418
|
+
* `yield` counts alongside `await`: an async generator driven by
|
|
419
|
+
* `action` suspends there in exactly the same way, and a read
|
|
420
|
+
* afterwards is just as detached. Nested functions are skipped — their
|
|
421
|
+
* gaps are their own, and a callback defined after an await still runs
|
|
422
|
+
* with its own tracking.
|
|
405
423
|
*/
|
|
406
424
|
const firstAsyncGapStart = (node) => {
|
|
407
425
|
if (!isFunctionNode(node) || node.async !== true) {
|
|
@@ -429,7 +447,10 @@ export default {
|
|
|
429
447
|
const start = Array.isArray(current.range)
|
|
430
448
|
? current.range[0]
|
|
431
449
|
: null;
|
|
432
|
-
if (
|
|
450
|
+
if (
|
|
451
|
+
start !== null &&
|
|
452
|
+
(earliest === null || start < earliest)
|
|
453
|
+
) {
|
|
433
454
|
earliest = start;
|
|
434
455
|
}
|
|
435
456
|
// An await nested inside this one cannot start earlier.
|
|
@@ -442,7 +463,10 @@ export default {
|
|
|
442
463
|
if (
|
|
443
464
|
value &&
|
|
444
465
|
typeof value === "object" &&
|
|
445
|
-
!(
|
|
466
|
+
!(
|
|
467
|
+
typeof value.type === "string" &&
|
|
468
|
+
isFunctionNode(value)
|
|
469
|
+
)
|
|
446
470
|
) {
|
|
447
471
|
pending.push(value);
|
|
448
472
|
}
|
|
@@ -772,7 +796,10 @@ export default {
|
|
|
772
796
|
scopeStack.syncCallbacks.add(node.callee);
|
|
773
797
|
}
|
|
774
798
|
};
|
|
775
|
-
/**
|
|
799
|
+
/**
|
|
800
|
+
* Checks VariableDeclarators, AssignmentExpressions, and
|
|
801
|
+
* CallExpressions for reactivity.
|
|
802
|
+
*/
|
|
776
803
|
const checkForReactiveAssignment = (id, init) => {
|
|
777
804
|
init = ignoreTransparentWrappers(init);
|
|
778
805
|
// Mark return values of certain functions as reactive
|
|
@@ -781,9 +808,7 @@ export default {
|
|
|
781
808
|
init.callee.type === "Identifier"
|
|
782
809
|
) {
|
|
783
810
|
const { callee } = init;
|
|
784
|
-
if (
|
|
785
|
-
matchImport(["createSignal"], callee.name)
|
|
786
|
-
) {
|
|
811
|
+
if (matchImport(["createSignal"], callee.name)) {
|
|
787
812
|
const signal = id && getNthDestructuredVar(id, 0, context);
|
|
788
813
|
if (signal) {
|
|
789
814
|
scopeStack.pushSignal(signal, currentScope().node);
|
|
@@ -791,7 +816,10 @@ export default {
|
|
|
791
816
|
warnShouldDestructure(id ?? init, "first");
|
|
792
817
|
}
|
|
793
818
|
} else if (
|
|
794
|
-
matchImport(
|
|
819
|
+
matchImport(
|
|
820
|
+
["createMemo", "createDeferred", "createProjection"],
|
|
821
|
+
callee.name,
|
|
822
|
+
)
|
|
795
823
|
) {
|
|
796
824
|
const memo = id && getReturnedVar(id, context);
|
|
797
825
|
// memos act like signals
|
|
@@ -840,7 +868,9 @@ export default {
|
|
|
840
868
|
scopeStack.pushProps(vars, currentScope().node);
|
|
841
869
|
}
|
|
842
870
|
}
|
|
843
|
-
} else if (
|
|
871
|
+
} else if (
|
|
872
|
+
matchImport("__removed_createResource", callee.name)
|
|
873
|
+
) {
|
|
844
874
|
// createResource return value has reactive .loading and .error
|
|
845
875
|
const resourceReturn =
|
|
846
876
|
id && getNthDestructuredVar(id, 0, context);
|
|
@@ -850,7 +880,9 @@ export default {
|
|
|
850
880
|
currentScope().node,
|
|
851
881
|
);
|
|
852
882
|
}
|
|
853
|
-
} else if (
|
|
883
|
+
} else if (
|
|
884
|
+
matchImport("__removed_createMutable", callee.name)
|
|
885
|
+
) {
|
|
854
886
|
const mutable = id && getReturnedVar(id, context);
|
|
855
887
|
if (mutable) {
|
|
856
888
|
scopeStack.pushProps(mutable, currentScope().node);
|
|
@@ -1028,6 +1060,8 @@ export default {
|
|
|
1028
1060
|
matchImport(
|
|
1029
1061
|
[
|
|
1030
1062
|
"createMemo",
|
|
1063
|
+
// An async memo: the callback may return a promise.
|
|
1064
|
+
"createDeferred",
|
|
1031
1065
|
"children",
|
|
1032
1066
|
"createTrackedEffect",
|
|
1033
1067
|
"createProjection",
|
|
@@ -1036,6 +1070,8 @@ export default {
|
|
|
1036
1070
|
"isPending",
|
|
1037
1071
|
"latest",
|
|
1038
1072
|
"resolve",
|
|
1073
|
+
// The predicate is re-evaluated reactively until it is truthy.
|
|
1074
|
+
"until",
|
|
1039
1075
|
],
|
|
1040
1076
|
callee.name,
|
|
1041
1077
|
) ||
|
|
@@ -1078,7 +1114,7 @@ export default {
|
|
|
1078
1114
|
pushTrackedScope(arg0, "called-function");
|
|
1079
1115
|
} else if (
|
|
1080
1116
|
matchImport(
|
|
1081
|
-
["onSettled", "onCleanup"],
|
|
1117
|
+
["onSettled", "onFlush", "onCleanup"],
|
|
1082
1118
|
callee.name,
|
|
1083
1119
|
) ||
|
|
1084
1120
|
[
|
|
@@ -25,8 +25,8 @@ function childrenIsMultilineSpaces(node) {
|
|
|
25
25
|
);
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
|
-
* This rule is adapted from eslint-plugin-react's self-closing-comp rule under
|
|
29
|
-
* with some enhancements. Thank you for your work!
|
|
28
|
+
* This rule is adapted from eslint-plugin-react's self-closing-comp rule under
|
|
29
|
+
* the MIT license, with some enhancements. Thank you for your work!
|
|
30
30
|
*/
|
|
31
31
|
export default {
|
|
32
32
|
meta: {
|
package/src/rules/style_prop.mjs
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
getPropertyName,
|
|
3
|
+
getStaticValue,
|
|
4
|
+
} from "@eslint-community/eslint-utils";
|
|
2
5
|
import kebabCase from "kebab-case";
|
|
3
6
|
import { all as allCssProperties } from "known-css-properties";
|
|
4
7
|
import parse from "style-to-object";
|