@murky-web/oxlint-plugin-solid 1.1.0 → 1.2.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 +16 -1
- package/package.json +3 -4
- package/src/compat.mjs +2 -2
- package/src/index.mjs +6 -0
- package/src/rules/components_return_once.mjs +2 -5
- package/src/rules/event_handlers.mjs +3 -5
- package/src/rules/imports.mjs +9 -5
- package/src/rules/jsx_no_duplicate_props.mjs +3 -6
- package/src/rules/jsx_no_script_url.mjs +3 -5
- package/src/rules/jsx_no_undef.mjs +2 -5
- package/src/rules/jsx_uses_vars.mjs +2 -6
- package/src/rules/no_array_handlers.mjs +2 -6
- package/src/rules/no_destructure.mjs +3 -5
- package/src/rules/no_innerhtml.mjs +3 -5
- package/src/rules/no_owned_primitives_in_ref.mjs +122 -0
- package/src/rules/no_proxy_apis.mjs +2 -6
- package/src/rules/no_react_deps.mjs +3 -6
- package/src/rules/no_react_specific_props.mjs +2 -5
- package/src/rules/no_setter_in_effect.mjs +168 -0
- package/src/rules/no_unknown_namespaces.mjs +2 -5
- package/src/rules/no_untracked_effect_read.mjs +175 -0
- package/src/rules/prefer_class_object.mjs +9 -9
- package/src/rules/prefer_for.mjs +3 -5
- package/src/rules/prefer_show.mjs +2 -5
- package/src/rules/reactivity.mjs +10 -8
- package/src/rules/self_closing_comp.mjs +2 -5
- package/src/rules/style_prop.mjs +3 -5
package/README.md
CHANGED
|
@@ -8,10 +8,25 @@ projektspezifische Regeln wie `solid/prefer-arrow-components`.
|
|
|
8
8
|
Die Regelmodule unter `src/rules/` sind aus dem Upstream-Quellstand abgeleitet
|
|
9
9
|
und laufen ohne `eslint-plugin-solid` als Zielprojekt-Dependency.
|
|
10
10
|
|
|
11
|
+
Das Paket zieht auch ESLint selbst nicht mehr nach. Die Regeln sind schlichte
|
|
12
|
+
Objekte, wie Oxlint sie erwartet -- der `createRule`-Wrapper aus
|
|
13
|
+
`@typescript-eslint/utils` war nur eine TypeScript-Typhilfe und ist entfallen.
|
|
14
|
+
Geblieben sind fuenf AST-Helfer, die jetzt direkt aus
|
|
15
|
+
`@eslint-community/eslint-utils` kommen, statt die komplette
|
|
16
|
+
TypeScript-ESLint-Toolchain in den Baum jedes Konsumenten zu ziehen.
|
|
17
|
+
|
|
11
18
|
Aktuell sind enthalten:
|
|
12
19
|
|
|
13
20
|
- die komplette von `eslint-plugin-solid` exportierte Regelmenge
|
|
14
|
-
- die
|
|
21
|
+
- die zusaetzlichen Projektregeln `solid/prefer-arrow-components`,
|
|
22
|
+
`solid/no-setter-in-effect` (meldet Effects, die nur in ein Signal oder einen
|
|
23
|
+
Store schreiben, statt den Wert abzuleiten -- und Effects, die etwas awaiten
|
|
24
|
+
und das Ergebnis zurueckschreiben, statt es aus einer Derivation zu liefern)
|
|
25
|
+
`solid/no-untracked-effect-read` (meldet reaktive Reads in der
|
|
26
|
+
apply-Phase eines zweiphasigen `createEffect`, die dort nicht tracken) und
|
|
27
|
+
`solid/no-owned-primitives-in-ref` (meldet `createEffect`/`onCleanup` und
|
|
28
|
+
Verwandte in einem Ref-Callback -- der laeuft ohne Owner, nichts raeumt sie
|
|
29
|
+
je wieder ab)
|
|
15
30
|
- ein Test-Harness, der die exportierte Rule-Surface und echte Diagnostik
|
|
16
31
|
gegen Temp-Projekte prueft
|
|
17
32
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@murky-web/oxlint-plugin-solid",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Local Oxlint JS plugin port for Solid rules plus Murky-specific Solid conventions.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
@@ -26,8 +26,7 @@
|
|
|
26
26
|
},
|
|
27
27
|
"sideEffects": false,
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@
|
|
30
|
-
"eslint": "^9.38.0",
|
|
29
|
+
"@eslint-community/eslint-utils": "^4.9.1",
|
|
31
30
|
"estraverse": "^5.3.0",
|
|
32
31
|
"is-html": "^2.0.0",
|
|
33
32
|
"kebab-case": "^1.0.2",
|
|
@@ -35,7 +34,7 @@
|
|
|
35
34
|
"style-to-object": "^1.0.8"
|
|
36
35
|
},
|
|
37
36
|
"devDependencies": {
|
|
38
|
-
"solid-js": "^1.9.
|
|
37
|
+
"solid-js": "^1.9.15"
|
|
39
38
|
},
|
|
40
39
|
"publishConfig": {
|
|
41
40
|
"access": "public",
|
package/src/compat.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { findVariable as utilsFindVariable } from "@eslint-community/eslint-utils";
|
|
2
2
|
|
|
3
3
|
export function getSourceCode(context) {
|
|
4
4
|
if (typeof context.getSourceCode === "function") {
|
|
@@ -23,7 +23,7 @@ export function getScope(context, node) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export function findVariable(context, node) {
|
|
26
|
-
return
|
|
26
|
+
return utilsFindVariable(getScope(context, node), node);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export function markVariableAsUsed(context, name, node) {
|
package/src/index.mjs
CHANGED
|
@@ -8,10 +8,13 @@ import { jsxUsesVarsRule } from "./rules/jsx_uses_vars.mjs";
|
|
|
8
8
|
import { noArrayHandlersRule } from "./rules/no_array_handlers.mjs";
|
|
9
9
|
import noDestructureRule from "./rules/no_destructure.mjs";
|
|
10
10
|
import noInnerhtmlRule from "./rules/no_innerhtml.mjs";
|
|
11
|
+
import noOwnedPrimitivesInRefRule from "./rules/no_owned_primitives_in_ref.mjs";
|
|
11
12
|
import noProxyApisRule from "./rules/no_proxy_apis.mjs";
|
|
12
13
|
import noReactDepsRule from "./rules/no_react_deps.mjs";
|
|
13
14
|
import { noReactSpecificPropsRule } from "./rules/no_react_specific_props.mjs";
|
|
15
|
+
import noSetterInEffectRule from "./rules/no_setter_in_effect.mjs";
|
|
14
16
|
import noUnknownNamespacesRule from "./rules/no_unknown_namespaces.mjs";
|
|
17
|
+
import noUntrackedEffectReadRule from "./rules/no_untracked_effect_read.mjs";
|
|
15
18
|
import { preferArrowComponentsRule } from "./rules/prefer_arrow_components.mjs";
|
|
16
19
|
import preferClassObjectRule from "./rules/prefer_class_object.mjs";
|
|
17
20
|
import preferForRule from "./rules/prefer_for.mjs";
|
|
@@ -37,10 +40,13 @@ const extendedPlugin = {
|
|
|
37
40
|
"no-array-handlers": noArrayHandlersRule,
|
|
38
41
|
"no-destructure": noDestructureRule,
|
|
39
42
|
"no-innerhtml": noInnerhtmlRule,
|
|
43
|
+
"no-owned-primitives-in-ref": noOwnedPrimitivesInRefRule,
|
|
40
44
|
"no-proxy-apis": noProxyApisRule,
|
|
41
45
|
"no-react-deps": noReactDepsRule,
|
|
42
46
|
"no-react-specific-props": noReactSpecificPropsRule,
|
|
47
|
+
"no-setter-in-effect": noSetterInEffectRule,
|
|
43
48
|
"no-unknown-namespaces": noUnknownNamespacesRule,
|
|
49
|
+
"no-untracked-effect-read": noUntrackedEffectReadRule,
|
|
44
50
|
"prefer-arrow-components": preferArrowComponentsRule,
|
|
45
51
|
"prefer-class-object": preferClassObjectRule,
|
|
46
52
|
"prefer-for": preferForRule,
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
-
|
|
3
1
|
import { getSourceCode } from "../compat.mjs";
|
|
4
2
|
import { getFunctionName } from "../utils.mjs";
|
|
5
|
-
const createRule = ESLintUtils.RuleCreator.withoutDocs;
|
|
6
3
|
const isNothing = (node) => {
|
|
7
4
|
if (!node) {
|
|
8
5
|
return true;
|
|
@@ -17,7 +14,7 @@ const isNothing = (node) => {
|
|
|
17
14
|
}
|
|
18
15
|
};
|
|
19
16
|
const getLineLength = (loc) => loc.end.line - loc.start.line + 1;
|
|
20
|
-
export default
|
|
17
|
+
export default {
|
|
21
18
|
meta: {
|
|
22
19
|
type: "problem",
|
|
23
20
|
docs: {
|
|
@@ -199,4 +196,4 @@ export default createRule({
|
|
|
199
196
|
},
|
|
200
197
|
};
|
|
201
198
|
},
|
|
202
|
-
}
|
|
199
|
+
};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getStaticValue } from "@eslint-community/eslint-utils";
|
|
2
2
|
|
|
3
3
|
import { getScope, getSourceCode } from "../compat.mjs";
|
|
4
4
|
import { isDOMElementName } from "../utils.mjs";
|
|
5
|
-
const createRule = ESLintUtils.RuleCreator.withoutDocs;
|
|
6
|
-
const { getStaticValue } = ASTUtils;
|
|
7
5
|
const COMMON_EVENTS = [
|
|
8
6
|
"onAnimationEnd",
|
|
9
7
|
"onAnimationIteration",
|
|
@@ -82,7 +80,7 @@ const isNonstandardEventName = (lowercaseEventName) =>
|
|
|
82
80
|
Boolean(NONSTANDARD_EVENTS_MAP[lowercaseEventName]);
|
|
83
81
|
const getStandardEventHandlerName = (lowercaseEventName) =>
|
|
84
82
|
NONSTANDARD_EVENTS_MAP[lowercaseEventName];
|
|
85
|
-
export default
|
|
83
|
+
export default {
|
|
86
84
|
meta: {
|
|
87
85
|
type: "problem",
|
|
88
86
|
docs: {
|
|
@@ -295,4 +293,4 @@ export default createRule({
|
|
|
295
293
|
},
|
|
296
294
|
};
|
|
297
295
|
},
|
|
298
|
-
}
|
|
296
|
+
};
|
package/src/rules/imports.mjs
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
-
|
|
3
1
|
import { getSourceCode } from "../compat.mjs";
|
|
4
2
|
import { appendImports, insertImports, removeSpecifier } from "../utils.mjs";
|
|
5
|
-
const createRule = ESLintUtils.RuleCreator.withoutDocs;
|
|
6
3
|
// Solid 2.0 moved the renderers into `@solidjs/*` packages and pulled the store
|
|
7
4
|
// APIs into the core. Symbols that are legitimately exported from more than one
|
|
8
5
|
// package (the control-flow components, `ComponentProps`) are deliberately left
|
|
@@ -14,12 +11,19 @@ for (const primitive of [
|
|
|
14
11
|
"children",
|
|
15
12
|
"createContext",
|
|
16
13
|
"createEffect",
|
|
14
|
+
// The primitive forms of `Loading`, `Errored` and `Reveal`. Only custom
|
|
15
|
+
// boundary components and renderer integrations reach for them, which is
|
|
16
|
+
// why they were missing here — and why a wrong-module import of one went
|
|
17
|
+
// unreported while every neighbouring primitive was checked.
|
|
18
|
+
"createErrorBoundary",
|
|
19
|
+
"createLoadingBoundary",
|
|
17
20
|
"createMemo",
|
|
18
21
|
"createOptimistic",
|
|
19
22
|
"createOptimisticStore",
|
|
20
23
|
"createProjection",
|
|
21
24
|
"createReaction",
|
|
22
25
|
"createRenderEffect",
|
|
26
|
+
"createRevealOrder",
|
|
23
27
|
"createRoot",
|
|
24
28
|
"createSignal",
|
|
25
29
|
"createStore",
|
|
@@ -98,7 +102,7 @@ for (const type of ["ClassValue", "IntrinsicElement", "JSX", "RequestEvent"]) {
|
|
|
98
102
|
}
|
|
99
103
|
const sourceRegex = /^(?:solid-js|@solidjs\/(?:web|h|html|universal))$/;
|
|
100
104
|
const isSource = (source) => sourceRegex.test(source);
|
|
101
|
-
export default
|
|
105
|
+
export default {
|
|
102
106
|
meta: {
|
|
103
107
|
type: "suggestion",
|
|
104
108
|
docs: {
|
|
@@ -189,4 +193,4 @@ export default createRule({
|
|
|
189
193
|
},
|
|
190
194
|
};
|
|
191
195
|
},
|
|
192
|
-
}
|
|
196
|
+
};
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
-
|
|
3
1
|
import { jsxGetAllProps } from "../utils.mjs";
|
|
4
|
-
|
|
5
|
-
export default createRule({
|
|
2
|
+
export default {
|
|
6
3
|
meta: {
|
|
7
4
|
type: "problem",
|
|
8
5
|
docs: {
|
|
@@ -26,7 +23,7 @@ export default createRule({
|
|
|
26
23
|
messages: {
|
|
27
24
|
noDuplicateProps: "Duplicate props are not allowed.",
|
|
28
25
|
noDuplicateClass:
|
|
29
|
-
"Duplicate `class` props are not allowed; while it might seem to work, it can break unexpectedly.
|
|
26
|
+
"Duplicate `class` props are not allowed; while it might seem to work, it can break unexpectedly. Pass one `class` with the object or array form instead.",
|
|
30
27
|
noDuplicateChildren:
|
|
31
28
|
"Using {{used}} at the same time is not allowed.",
|
|
32
29
|
},
|
|
@@ -84,4 +81,4 @@ export default createRule({
|
|
|
84
81
|
},
|
|
85
82
|
};
|
|
86
83
|
},
|
|
87
|
-
}
|
|
84
|
+
};
|
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getStaticValue } from "@eslint-community/eslint-utils";
|
|
2
2
|
|
|
3
3
|
import { getScope } from "../compat.mjs";
|
|
4
4
|
|
|
5
|
-
const createRule = ESLintUtils.RuleCreator.withoutDocs;
|
|
6
|
-
const { getStaticValue } = ASTUtils;
|
|
7
5
|
const JAVASCRIPT_PROTOCOL_PATTERN =
|
|
8
6
|
"^[\\\\u0000-\\\\u001F ]*j[\\\\r\\\\n\\\\t]*a[\\\\r\\\\n\\\\t]*v[\\\\r\\\\n\\\\t]*a[\\\\r\\\\n\\\\t]*s[\\\\r\\\\n\\\\t]*c[\\\\r\\\\n\\\\t]*r[\\\\r\\\\n\\\\t]*i[\\\\r\\\\n\\\\t]*p[\\\\r\\\\n\\\\t]*t[\\\\r\\\\n\\\\t]*:";
|
|
9
7
|
const JAVASCRIPT_PROTOCOL_REGEX = new RegExp(JAVASCRIPT_PROTOCOL_PATTERN, "i");
|
|
10
8
|
|
|
11
|
-
export const jsxNoScriptUrlRule =
|
|
9
|
+
export const jsxNoScriptUrlRule = {
|
|
12
10
|
meta: {
|
|
13
11
|
docs: {
|
|
14
12
|
description: "Disallow javascript: URLs.",
|
|
@@ -51,4 +49,4 @@ export const jsxNoScriptUrlRule = createRule({
|
|
|
51
49
|
},
|
|
52
50
|
};
|
|
53
51
|
},
|
|
54
|
-
}
|
|
52
|
+
};
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
-
|
|
3
1
|
import { getScope, getSourceCode } from "../compat.mjs";
|
|
4
2
|
import {
|
|
5
3
|
isDOMElementName,
|
|
@@ -7,7 +5,6 @@ import {
|
|
|
7
5
|
appendImports,
|
|
8
6
|
insertImports,
|
|
9
7
|
} from "../utils.mjs";
|
|
10
|
-
const createRule = ESLintUtils.RuleCreator.withoutDocs;
|
|
11
8
|
// Currently all of the control flow components are from 'solid-js'.
|
|
12
9
|
// Solid 2.0 dropped `Index` (use `<For keyed={false}>`) and renamed the
|
|
13
10
|
// async/error boundaries. All of these are exported from `solid-js`.
|
|
@@ -22,7 +19,7 @@ const AUTO_COMPONENTS = [
|
|
|
22
19
|
"Reveal",
|
|
23
20
|
];
|
|
24
21
|
const SOURCE_MODULE = "solid-js";
|
|
25
|
-
export default
|
|
22
|
+
export default {
|
|
26
23
|
meta: {
|
|
27
24
|
type: "problem",
|
|
28
25
|
docs: {
|
|
@@ -225,4 +222,4 @@ export default createRule({
|
|
|
225
222
|
},
|
|
226
223
|
};
|
|
227
224
|
},
|
|
228
|
-
}
|
|
225
|
+
};
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
-
|
|
3
1
|
import { markVariableAsUsed } from "../compat.mjs";
|
|
4
2
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
export const jsxUsesVarsRule = createRule({
|
|
3
|
+
export const jsxUsesVarsRule = {
|
|
8
4
|
meta: {
|
|
9
5
|
docs: {
|
|
10
6
|
description:
|
|
@@ -52,4 +48,4 @@ export const jsxUsesVarsRule = createRule({
|
|
|
52
48
|
},
|
|
53
49
|
};
|
|
54
50
|
},
|
|
55
|
-
}
|
|
51
|
+
};
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
-
|
|
3
1
|
import { isDOMElementName, trace } from "../utils.mjs";
|
|
4
2
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
export const noArrayHandlersRule = createRule({
|
|
3
|
+
export const noArrayHandlersRule = {
|
|
8
4
|
meta: {
|
|
9
5
|
docs: {
|
|
10
6
|
description: "Disallow usage of type-unsafe event handlers.",
|
|
@@ -50,4 +46,4 @@ export const noArrayHandlersRule = createRule({
|
|
|
50
46
|
},
|
|
51
47
|
};
|
|
52
48
|
},
|
|
53
|
-
}
|
|
49
|
+
};
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getStringIfConstant } from "@eslint-community/eslint-utils";
|
|
2
2
|
|
|
3
3
|
import { getSourceCode } from "../compat.mjs";
|
|
4
|
-
const createRule = ESLintUtils.RuleCreator.withoutDocs;
|
|
5
|
-
const { getStringIfConstant } = ASTUtils;
|
|
6
4
|
const getName = (node) => {
|
|
7
5
|
switch (node.type) {
|
|
8
6
|
case "Literal":
|
|
@@ -32,7 +30,7 @@ const getPropertyInfo = (prop) => {
|
|
|
32
30
|
return null;
|
|
33
31
|
}
|
|
34
32
|
};
|
|
35
|
-
export default
|
|
33
|
+
export default {
|
|
36
34
|
meta: {
|
|
37
35
|
type: "problem",
|
|
38
36
|
docs: {
|
|
@@ -212,4 +210,4 @@ export default createRule({
|
|
|
212
210
|
},
|
|
213
211
|
};
|
|
214
212
|
},
|
|
215
|
-
}
|
|
213
|
+
};
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getStringIfConstant } from "@eslint-community/eslint-utils";
|
|
2
2
|
import isHtml from "is-html";
|
|
3
3
|
|
|
4
4
|
import { jsxPropName } from "../utils.mjs";
|
|
5
|
-
|
|
6
|
-
const { getStringIfConstant } = ASTUtils;
|
|
7
|
-
export default createRule({
|
|
5
|
+
export default {
|
|
8
6
|
meta: {
|
|
9
7
|
type: "problem",
|
|
10
8
|
docs: {
|
|
@@ -142,4 +140,4 @@ export default createRule({
|
|
|
142
140
|
},
|
|
143
141
|
};
|
|
144
142
|
},
|
|
145
|
-
}
|
|
143
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { isFunctionNode, jsxPropName, trackImports } from "../utils.mjs";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Primitives that attach to the current owner.
|
|
5
|
+
*
|
|
6
|
+
* An effect or memo created without an owner is never disposed, and a cleanup
|
|
7
|
+
* registered without one never runs.
|
|
8
|
+
*/
|
|
9
|
+
const OWNED_PRIMITIVES = [
|
|
10
|
+
"createEffect",
|
|
11
|
+
"createMemo",
|
|
12
|
+
"createProjection",
|
|
13
|
+
"createReaction",
|
|
14
|
+
"createRenderEffect",
|
|
15
|
+
"onCleanup",
|
|
16
|
+
"onSettled",
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
/** The callbacks a `ref` prop applies, including the ones in a ref array. */
|
|
20
|
+
function getRefCallbacks(expression) {
|
|
21
|
+
if (isFunctionNode(expression)) {
|
|
22
|
+
return [expression];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// `ref={[storeElement, autofocus, listen(...)]}` — Solid flattens the array
|
|
26
|
+
// and calls each entry, so an inline callback anywhere in it is a ref
|
|
27
|
+
// callback like any other.
|
|
28
|
+
if (expression?.type === "ArrayExpression") {
|
|
29
|
+
return expression.elements.flatMap((element) =>
|
|
30
|
+
element !== null && isFunctionNode(element) ? [element] : [],
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Walk a callback body, stopping at nested functions.
|
|
39
|
+
*
|
|
40
|
+
* Only calls the ref callback makes itself are reported. A nested function may
|
|
41
|
+
* be handed to something that supplies an owner, and guessing wrong would flag
|
|
42
|
+
* working code.
|
|
43
|
+
*/
|
|
44
|
+
function walkOwnBody(node, visit) {
|
|
45
|
+
if (node === null || typeof node !== "object") {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
visit(node);
|
|
50
|
+
|
|
51
|
+
for (const [key, value] of Object.entries(node)) {
|
|
52
|
+
if (key === "parent") {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const candidates = Array.isArray(value) ? value : [value];
|
|
57
|
+
for (const candidate of candidates) {
|
|
58
|
+
if (
|
|
59
|
+
candidate !== null &&
|
|
60
|
+
typeof candidate === "object" &&
|
|
61
|
+
typeof candidate.type === "string" &&
|
|
62
|
+
!isFunctionNode(candidate)
|
|
63
|
+
) {
|
|
64
|
+
walkOwnBody(candidate, visit);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export default {
|
|
71
|
+
meta: {
|
|
72
|
+
type: "problem",
|
|
73
|
+
docs: {
|
|
74
|
+
description:
|
|
75
|
+
"Disallow creating owner-bound primitives inside a ref callback.",
|
|
76
|
+
url: "https://docs.solidjs.com/",
|
|
77
|
+
},
|
|
78
|
+
schema: [],
|
|
79
|
+
messages: {
|
|
80
|
+
ownedPrimitiveInRef:
|
|
81
|
+
"`{{name}}` is called inside a ref callback, which runs without an owner — nothing will ever dispose it. Create it in the directive factory instead, and let the returned callback only store the element.",
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
defaultOptions: [],
|
|
85
|
+
create(context) {
|
|
86
|
+
const { matchImport, handleImportDeclaration } = trackImports();
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
ImportDeclaration: handleImportDeclaration,
|
|
90
|
+
JSXAttribute(node) {
|
|
91
|
+
if (jsxPropName(node) !== "ref") {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (node.value?.type !== "JSXExpressionContainer") {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
for (const callback of getRefCallbacks(node.value.expression)) {
|
|
100
|
+
walkOwnBody(callback.body, (candidate) => {
|
|
101
|
+
if (
|
|
102
|
+
candidate.type !== "CallExpression" ||
|
|
103
|
+
candidate.callee.type !== "Identifier" ||
|
|
104
|
+
!matchImport(
|
|
105
|
+
OWNED_PRIMITIVES,
|
|
106
|
+
candidate.callee.name,
|
|
107
|
+
)
|
|
108
|
+
) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
context.report({
|
|
113
|
+
node: candidate,
|
|
114
|
+
messageId: "ownedPrimitiveInRef",
|
|
115
|
+
data: { name: candidate.callee.name },
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
},
|
|
122
|
+
};
|
|
@@ -1,20 +1,16 @@
|
|
|
1
|
-
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
-
|
|
3
1
|
import {
|
|
4
2
|
isFunctionNode,
|
|
5
3
|
trackImports,
|
|
6
4
|
isPropsByName,
|
|
7
5
|
trace,
|
|
8
6
|
} from "../utils.mjs";
|
|
9
|
-
const createRule = ESLintUtils.RuleCreator.withoutDocs;
|
|
10
|
-
|
|
11
7
|
// Store APIs that hand back a Proxy. Solid 2.0 exports these from `solid-js`.
|
|
12
8
|
const PROXY_BACKED_STORE_APIS = new Set([
|
|
13
9
|
"createStore",
|
|
14
10
|
"createProjection",
|
|
15
11
|
"createOptimisticStore",
|
|
16
12
|
]);
|
|
17
|
-
export default
|
|
13
|
+
export default {
|
|
18
14
|
meta: {
|
|
19
15
|
type: "problem",
|
|
20
16
|
docs: {
|
|
@@ -116,4 +112,4 @@ export default createRule({
|
|
|
116
112
|
},
|
|
117
113
|
};
|
|
118
114
|
},
|
|
119
|
-
}
|
|
115
|
+
};
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
-
|
|
3
1
|
import { isFunctionNode, trace, trackImports } from "../utils.mjs";
|
|
4
|
-
|
|
5
|
-
export default createRule({
|
|
2
|
+
export default {
|
|
6
3
|
meta: {
|
|
7
4
|
type: "problem",
|
|
8
5
|
docs: {
|
|
@@ -14,7 +11,7 @@ export default createRule({
|
|
|
14
11
|
schema: [],
|
|
15
12
|
messages: {
|
|
16
13
|
noUselessDep:
|
|
17
|
-
"In Solid, `{{name}}` doesn't accept a dependency array because it automatically tracks its dependencies.
|
|
14
|
+
"In Solid, `{{name}}` doesn't accept a dependency array because it automatically tracks its dependencies. To narrow what is tracked, read only those values in the compute phase.",
|
|
18
15
|
},
|
|
19
16
|
},
|
|
20
17
|
defaultOptions: [],
|
|
@@ -62,4 +59,4 @@ export default createRule({
|
|
|
62
59
|
},
|
|
63
60
|
};
|
|
64
61
|
},
|
|
65
|
-
}
|
|
62
|
+
};
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
-
|
|
3
1
|
import { isDOMElementName, jsxGetProp, jsxHasProp } from "../utils.mjs";
|
|
4
2
|
|
|
5
|
-
const createRule = ESLintUtils.RuleCreator.withoutDocs;
|
|
6
3
|
const REACT_SPECIFIC_PROPS = [
|
|
7
4
|
{ from: "className", to: "class" },
|
|
8
5
|
{ from: "htmlFor", to: "for" },
|
|
9
6
|
];
|
|
10
7
|
|
|
11
|
-
export const noReactSpecificPropsRule =
|
|
8
|
+
export const noReactSpecificPropsRule = {
|
|
12
9
|
meta: {
|
|
13
10
|
docs: {
|
|
14
11
|
description:
|
|
@@ -68,4 +65,4 @@ export const noReactSpecificPropsRule = createRule({
|
|
|
68
65
|
},
|
|
69
66
|
};
|
|
70
67
|
},
|
|
71
|
-
}
|
|
68
|
+
};
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { isFunctionNode, trackImports } from "../utils.mjs";
|
|
2
|
+
|
|
3
|
+
const SETTER_INDEX = 1;
|
|
4
|
+
|
|
5
|
+
/** `const [value, setValue] = createSignal(...)` -> "setValue". */
|
|
6
|
+
function getSetterName(declarator) {
|
|
7
|
+
if (declarator.id.type !== "ArrayPattern") {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const element = declarator.id.elements[SETTER_INDEX];
|
|
12
|
+
|
|
13
|
+
return element?.type === "Identifier" ? element.name : null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The phase that runs untracked and performs the work. Solid 2.0 passes it as
|
|
18
|
+
* the second argument; a lone function is still the whole effect.
|
|
19
|
+
*/
|
|
20
|
+
function getEffectPhase(node) {
|
|
21
|
+
const [compute, apply] = node.arguments;
|
|
22
|
+
|
|
23
|
+
if (apply) {
|
|
24
|
+
return isFunctionNode(apply) ? apply : null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return isFunctionNode(compute) ? compute : null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function isSetterCall(node, setterNames) {
|
|
31
|
+
return (
|
|
32
|
+
node?.type === "CallExpression" &&
|
|
33
|
+
node.callee.type === "Identifier" &&
|
|
34
|
+
setterNames.has(node.callee.name)
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** True when any statement anywhere in the phase writes to a signal or store. */
|
|
39
|
+
function writesSignalsAnywhere(node, setterNames) {
|
|
40
|
+
if (node === null || typeof node !== "object") {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (isSetterCall(node, setterNames)) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return Object.entries(node).some(([key, value]) => {
|
|
49
|
+
// `parent` points back up the tree; following it would not terminate.
|
|
50
|
+
if (key === "parent") {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const candidates = Array.isArray(value) ? value : [value];
|
|
55
|
+
|
|
56
|
+
return candidates.some(
|
|
57
|
+
(candidate) =>
|
|
58
|
+
candidate !== null &&
|
|
59
|
+
typeof candidate === "object" &&
|
|
60
|
+
!isFunctionNode(candidate) &&
|
|
61
|
+
writesSignalsAnywhere(candidate, setterNames),
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** True when the phase does nothing but write to signals or stores. */
|
|
67
|
+
function onlyWritesSignals(phase, setterNames) {
|
|
68
|
+
if (phase.body.type !== "BlockStatement") {
|
|
69
|
+
return isSetterCall(phase.body, setterNames);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const { body } = phase.body;
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
body.length > 0 &&
|
|
76
|
+
body.every(
|
|
77
|
+
(statement) =>
|
|
78
|
+
statement.type === "ExpressionStatement" &&
|
|
79
|
+
isSetterCall(statement.expression, setterNames),
|
|
80
|
+
)
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export default {
|
|
85
|
+
meta: {
|
|
86
|
+
type: "problem",
|
|
87
|
+
docs: {
|
|
88
|
+
description:
|
|
89
|
+
"Disallow effects that only copy a reactive value into another signal or store.",
|
|
90
|
+
url: "https://docs.solidjs.com/",
|
|
91
|
+
},
|
|
92
|
+
schema: [],
|
|
93
|
+
messages: {
|
|
94
|
+
asyncSetterInEffect:
|
|
95
|
+
"This effect awaits and then writes the result into a signal or store. Return the value from a derivation instead: `createMemo(async () => ...)`, or the function form of `createStore` for nested data. Solid coordinates readiness, error propagation, and dropping superseded runs.",
|
|
96
|
+
noSetterInEffect:
|
|
97
|
+
"This effect only writes to a signal or store. Calculate the value where it is read instead: a derived function, `createMemo`, or a writable derived `createSignal(() => ...)` for a local override.",
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
defaultOptions: [],
|
|
101
|
+
create(context) {
|
|
102
|
+
const { matchImport, handleImportDeclaration } = trackImports();
|
|
103
|
+
const setterNames = new Set();
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
ImportDeclaration: handleImportDeclaration,
|
|
107
|
+
VariableDeclarator(node) {
|
|
108
|
+
if (
|
|
109
|
+
node.init?.type !== "CallExpression" ||
|
|
110
|
+
node.init.callee.type !== "Identifier" ||
|
|
111
|
+
!matchImport(
|
|
112
|
+
["createSignal", "createStore"],
|
|
113
|
+
node.init.callee.name,
|
|
114
|
+
)
|
|
115
|
+
) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const setterName = getSetterName(node);
|
|
120
|
+
if (setterName) {
|
|
121
|
+
setterNames.add(setterName);
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
CallExpression(node) {
|
|
125
|
+
if (
|
|
126
|
+
node.callee.type !== "Identifier" ||
|
|
127
|
+
!matchImport(
|
|
128
|
+
["createEffect", "createRenderEffect"],
|
|
129
|
+
node.callee.name,
|
|
130
|
+
)
|
|
131
|
+
) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const phase = getEffectPhase(node);
|
|
136
|
+
if (!phase) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Asynchrony is checked first because it is the more specific
|
|
141
|
+
// diagnosis: `onlyWritesSignals` also matches a lone
|
|
142
|
+
// `setResults(await search(q))`, and the async message is the
|
|
143
|
+
// one that names readiness and superseded runs.
|
|
144
|
+
//
|
|
145
|
+
// `onlyWritesSignals` never sees the multi-statement shape at
|
|
146
|
+
// all — the `await` is not a setter call — which is why an
|
|
147
|
+
// async phase gets its own search.
|
|
148
|
+
if (
|
|
149
|
+
phase.async === true &&
|
|
150
|
+
writesSignalsAnywhere(phase.body, setterNames)
|
|
151
|
+
) {
|
|
152
|
+
context.report({
|
|
153
|
+
node: phase,
|
|
154
|
+
messageId: "asyncSetterInEffect",
|
|
155
|
+
});
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (onlyWritesSignals(phase, setterNames)) {
|
|
160
|
+
context.report({
|
|
161
|
+
node: phase,
|
|
162
|
+
messageId: "noSetterInEffect",
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
},
|
|
168
|
+
};
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
-
|
|
3
1
|
import { isDOMElementName } from "../utils.mjs";
|
|
4
|
-
const createRule = ESLintUtils.RuleCreator.withoutDocs;
|
|
5
2
|
// Solid 2.0 removed every Solid-specific JSX namespace. What is left are the
|
|
6
3
|
// XML namespaces the DOM itself defines.
|
|
7
4
|
const xmlNamespaces = ["xmlns", "xlink"];
|
|
@@ -17,7 +14,7 @@ const replacements = {
|
|
|
17
14
|
style: "the `style` prop with an object value",
|
|
18
15
|
use: "a ref callback or directive factory, composing with a ref array",
|
|
19
16
|
};
|
|
20
|
-
export default
|
|
17
|
+
export default {
|
|
21
18
|
meta: {
|
|
22
19
|
type: "problem",
|
|
23
20
|
docs: {
|
|
@@ -107,4 +104,4 @@ export default createRule({
|
|
|
107
104
|
},
|
|
108
105
|
};
|
|
109
106
|
},
|
|
110
|
-
}
|
|
107
|
+
};
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { isFunctionNode, isPropsByName, trackImports } from "../utils.mjs";
|
|
2
|
+
|
|
3
|
+
const GETTER_INDEX = 0;
|
|
4
|
+
|
|
5
|
+
/** `const [value, setValue] = createSignal(...)` -> "value". */
|
|
6
|
+
function getGetterName(declarator) {
|
|
7
|
+
if (declarator.id.type !== "ArrayPattern") {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const element = declarator.id.elements[GETTER_INDEX];
|
|
12
|
+
|
|
13
|
+
return element?.type === "Identifier" ? element.name : null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Every name a function's parameters bind, however they are destructured. */
|
|
17
|
+
function collectParameterNames(fn, into) {
|
|
18
|
+
const pending = [...fn.params];
|
|
19
|
+
|
|
20
|
+
while (pending.length > 0) {
|
|
21
|
+
const pattern = pending.pop();
|
|
22
|
+
if (pattern === null || typeof pattern !== "object") {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (pattern.type === "Identifier") {
|
|
27
|
+
into.add(pattern.name);
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
for (const [key, value] of Object.entries(pattern)) {
|
|
32
|
+
if (key === "parent") {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const candidates = Array.isArray(value) ? value : [value];
|
|
37
|
+
for (const candidate of candidates) {
|
|
38
|
+
if (candidate !== null && typeof candidate === "object") {
|
|
39
|
+
pending.push(candidate);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Walk the phase body, stopping at nested functions.
|
|
48
|
+
*
|
|
49
|
+
* A read inside a nested function runs whenever that function is called, which
|
|
50
|
+
* is a different question from whether this phase subscribes to it.
|
|
51
|
+
*/
|
|
52
|
+
function walkPhase(node, visit) {
|
|
53
|
+
if (node === null || typeof node !== "object") {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
visit(node);
|
|
58
|
+
|
|
59
|
+
for (const [key, value] of Object.entries(node)) {
|
|
60
|
+
if (key === "parent") {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const candidates = Array.isArray(value) ? value : [value];
|
|
65
|
+
for (const candidate of candidates) {
|
|
66
|
+
if (
|
|
67
|
+
candidate !== null &&
|
|
68
|
+
typeof candidate === "object" &&
|
|
69
|
+
typeof candidate.type === "string" &&
|
|
70
|
+
!isFunctionNode(candidate)
|
|
71
|
+
) {
|
|
72
|
+
walkPhase(candidate, visit);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export default {
|
|
79
|
+
meta: {
|
|
80
|
+
type: "problem",
|
|
81
|
+
docs: {
|
|
82
|
+
description:
|
|
83
|
+
"Disallow reading reactive values in the untracked apply phase of an effect.",
|
|
84
|
+
url: "https://docs.solidjs.com/",
|
|
85
|
+
},
|
|
86
|
+
schema: [],
|
|
87
|
+
messages: {
|
|
88
|
+
untrackedEffectRead:
|
|
89
|
+
"'{{name}}' is read in the effect's apply phase, which runs untracked — changes to it will not re-run this effect. Read it in the compute phase and take it as an argument instead.",
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
defaultOptions: [],
|
|
93
|
+
create(context) {
|
|
94
|
+
const { matchImport, handleImportDeclaration } = trackImports();
|
|
95
|
+
const getterNames = new Set();
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
ImportDeclaration: handleImportDeclaration,
|
|
99
|
+
VariableDeclarator(node) {
|
|
100
|
+
if (
|
|
101
|
+
node.init?.type !== "CallExpression" ||
|
|
102
|
+
node.init.callee.type !== "Identifier" ||
|
|
103
|
+
!matchImport(["createSignal"], node.init.callee.name)
|
|
104
|
+
) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const getterName = getGetterName(node);
|
|
109
|
+
if (getterName) {
|
|
110
|
+
getterNames.add(getterName);
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
CallExpression(node) {
|
|
114
|
+
if (
|
|
115
|
+
node.callee.type !== "Identifier" ||
|
|
116
|
+
!matchImport(
|
|
117
|
+
["createEffect", "createRenderEffect"],
|
|
118
|
+
node.callee.name,
|
|
119
|
+
)
|
|
120
|
+
) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Only the two-argument form has an apply phase. A lone
|
|
125
|
+
// function is the whole effect and tracks throughout.
|
|
126
|
+
const [compute, apply] = node.arguments;
|
|
127
|
+
if (!compute || !apply || !isFunctionNode(apply)) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Whatever the compute phase handed over arrives as a
|
|
132
|
+
// parameter, so those names are already settled values.
|
|
133
|
+
const settled = new Set();
|
|
134
|
+
collectParameterNames(apply, settled);
|
|
135
|
+
|
|
136
|
+
walkPhase(apply.body, (candidate) => {
|
|
137
|
+
// `signal()` — a getter call that did not come through the
|
|
138
|
+
// compute phase.
|
|
139
|
+
if (
|
|
140
|
+
candidate.type === "CallExpression" &&
|
|
141
|
+
candidate.callee.type === "Identifier" &&
|
|
142
|
+
getterNames.has(candidate.callee.name) &&
|
|
143
|
+
!settled.has(candidate.callee.name)
|
|
144
|
+
) {
|
|
145
|
+
context.report({
|
|
146
|
+
node: candidate,
|
|
147
|
+
messageId: "untrackedEffectRead",
|
|
148
|
+
data: { name: candidate.callee.name },
|
|
149
|
+
});
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// `props.value` — a props read is reactive for the same
|
|
154
|
+
// reason and is just as invisible to the tracker here.
|
|
155
|
+
if (
|
|
156
|
+
candidate.type === "MemberExpression" &&
|
|
157
|
+
!candidate.computed &&
|
|
158
|
+
candidate.object.type === "Identifier" &&
|
|
159
|
+
isPropsByName(candidate.object.name) &&
|
|
160
|
+
!settled.has(candidate.object.name) &&
|
|
161
|
+
candidate.property.type === "Identifier"
|
|
162
|
+
) {
|
|
163
|
+
context.report({
|
|
164
|
+
node: candidate,
|
|
165
|
+
messageId: "untrackedEffectRead",
|
|
166
|
+
data: {
|
|
167
|
+
name: `${candidate.object.name}.${candidate.property.name}`,
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
},
|
|
175
|
+
};
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
-
|
|
3
1
|
import { jsxPropName } from "../utils.mjs";
|
|
4
|
-
const createRule = ESLintUtils.RuleCreator.withoutDocs;
|
|
5
2
|
const DEFAULT_CLASSNAMES = ["cn", "clsx", "classnames"];
|
|
6
|
-
export default
|
|
3
|
+
export default {
|
|
7
4
|
meta: {
|
|
8
5
|
type: "problem",
|
|
9
6
|
docs: {
|
|
10
7
|
description:
|
|
11
|
-
"Enforce the `class` object/array form over the removed `
|
|
8
|
+
"Enforce the `class` object/array form over the removed `classList` prop or a classnames helper. Solid 2.0 accepts `{ [class: string]: boolean }` on `class` directly.",
|
|
12
9
|
url: "https://docs.solidjs.com/",
|
|
13
10
|
},
|
|
14
11
|
fixable: "code",
|
|
@@ -33,7 +30,7 @@ export default createRule({
|
|
|
33
30
|
],
|
|
34
31
|
messages: {
|
|
35
32
|
classlistRemoved:
|
|
36
|
-
"The `
|
|
33
|
+
"The `classList` prop was removed in Solid 2.0. Pass the object to `class` instead.",
|
|
37
34
|
preferClassObject:
|
|
38
35
|
"Pass the object to `class` directly instead of through {{ classnames }}.",
|
|
39
36
|
},
|
|
@@ -46,8 +43,11 @@ export default createRule({
|
|
|
46
43
|
JSXAttribute(node) {
|
|
47
44
|
const name = jsxPropName(node);
|
|
48
45
|
|
|
49
|
-
// `
|
|
50
|
-
|
|
46
|
+
// `classList={{...}}` no longer exists; the object belongs on
|
|
47
|
+
// `class`. JSX prop names are case-sensitive, so matching only
|
|
48
|
+
// the lowercase spelling missed every real Solid 1 call site —
|
|
49
|
+
// which is the code this rule exists to migrate.
|
|
50
|
+
if (name === "classList" || name === "classlist") {
|
|
51
51
|
context.report({
|
|
52
52
|
node,
|
|
53
53
|
messageId: "classlistRemoved",
|
|
@@ -95,4 +95,4 @@ export default createRule({
|
|
|
95
95
|
},
|
|
96
96
|
};
|
|
97
97
|
},
|
|
98
|
-
}
|
|
98
|
+
};
|
package/src/rules/prefer_for.mjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getPropertyName } from "@eslint-community/eslint-utils";
|
|
2
2
|
|
|
3
3
|
import { isFunctionNode, isJSXElementOrFragment } from "../utils.mjs";
|
|
4
|
-
|
|
5
|
-
const { getPropertyName } = ASTUtils;
|
|
6
|
-
export default createRule({
|
|
4
|
+
export default {
|
|
7
5
|
meta: {
|
|
8
6
|
type: "problem",
|
|
9
7
|
docs: {
|
|
@@ -89,4 +87,4 @@ export default createRule({
|
|
|
89
87
|
},
|
|
90
88
|
};
|
|
91
89
|
},
|
|
92
|
-
}
|
|
90
|
+
};
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
-
|
|
3
1
|
import { getSourceCode } from "../compat.mjs";
|
|
4
2
|
import { isJSXElementOrFragment } from "../utils.mjs";
|
|
5
|
-
const createRule = ESLintUtils.RuleCreator.withoutDocs;
|
|
6
3
|
const EXPENSIVE_TYPES = ["JSXElement", "JSXFragment", "Identifier"];
|
|
7
|
-
export default
|
|
4
|
+
export default {
|
|
8
5
|
meta: {
|
|
9
6
|
type: "problem",
|
|
10
7
|
docs: {
|
|
@@ -89,4 +86,4 @@ export default createRule({
|
|
|
89
86
|
},
|
|
90
87
|
};
|
|
91
88
|
},
|
|
92
|
-
}
|
|
89
|
+
};
|
package/src/rules/reactivity.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* File overview here, scroll to bottom.
|
|
3
3
|
* @link https://github.com/solidjs-community/eslint-plugin-solid/blob/main/docs/reactivity.md
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
5
|
+
import { getFunctionHeadLocation } from "@eslint-community/eslint-utils";
|
|
6
6
|
import { traverse } from "estraverse";
|
|
7
7
|
|
|
8
8
|
import { findVariable, getSourceCode } from "../compat.mjs";
|
|
@@ -19,9 +19,6 @@ import {
|
|
|
19
19
|
isJSXElementOrFragment,
|
|
20
20
|
trace,
|
|
21
21
|
} from "../utils.mjs";
|
|
22
|
-
const { getFunctionHeadLocation } = ASTUtils;
|
|
23
|
-
const createRule = ESLintUtils.RuleCreator.withoutDocs;
|
|
24
|
-
|
|
25
22
|
// Solid 2.0 removed `createResource`, `createMutable`, `indexArray` and
|
|
26
23
|
// `<Index>`. Their branches below are kept structurally but matched against
|
|
27
24
|
// `__removed_*` names so they can never fire; delete them once no Solid 1
|
|
@@ -174,7 +171,7 @@ const getReturnedVar = (id, context) => {
|
|
|
174
171
|
}
|
|
175
172
|
return null;
|
|
176
173
|
};
|
|
177
|
-
export default
|
|
174
|
+
export default {
|
|
178
175
|
meta: {
|
|
179
176
|
type: "problem",
|
|
180
177
|
docs: {
|
|
@@ -203,7 +200,7 @@ export default createRule({
|
|
|
203
200
|
noWrite:
|
|
204
201
|
"The reactive variable '{{name}}' should not be reassigned or altered directly.",
|
|
205
202
|
untrackedReactive:
|
|
206
|
-
"The reactive variable '{{name}}' should be used within JSX, a tracked scope (like createEffect), or inside an event handler function, or else changes will be ignored.",
|
|
203
|
+
"The reactive variable '{{name}}' should be used within JSX, a tracked scope (like createEffect), or inside an event handler function, or else changes will be ignored. To keep it reactive, derive it rather than copy it: a plain function, `createMemo`, or `createSignal(() => ...)` / `createStore(() => ...)` for a local override that a new source value should replace.",
|
|
207
204
|
expectedFunctionGotExpression:
|
|
208
205
|
"The reactive variable '{{name}}' should be wrapped in a function for reactivity. This includes event handler bindings on native elements, which are not reactive like other JSX props.",
|
|
209
206
|
badSignal:
|
|
@@ -223,7 +220,12 @@ export default createRule({
|
|
|
223
220
|
customReactiveFunctions: [],
|
|
224
221
|
},
|
|
225
222
|
],
|
|
226
|
-
create(context
|
|
223
|
+
create(context) {
|
|
224
|
+
// `RuleCreator` used to merge `defaultOptions` into `context.options`
|
|
225
|
+
// and hand the result to a second `create` parameter. Without that
|
|
226
|
+
// wrapper the parameter is undefined, so the default is applied here.
|
|
227
|
+
const options = context.options[0] ?? { customReactiveFunctions: [] };
|
|
228
|
+
|
|
227
229
|
const warnShouldDestructure = (node, nth) =>
|
|
228
230
|
context.report({
|
|
229
231
|
node,
|
|
@@ -1397,4 +1399,4 @@ export default createRule({
|
|
|
1397
1399
|
},
|
|
1398
1400
|
};
|
|
1399
1401
|
},
|
|
1400
|
-
}
|
|
1402
|
+
};
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
-
|
|
3
1
|
import { getSourceCode } from "../compat.mjs";
|
|
4
2
|
import { isDOMElementName } from "../utils.mjs";
|
|
5
|
-
const createRule = ESLintUtils.RuleCreator.withoutDocs;
|
|
6
3
|
function isComponent(node) {
|
|
7
4
|
return (
|
|
8
5
|
(node.name.type === "JSXIdentifier" &&
|
|
@@ -31,7 +28,7 @@ function childrenIsMultilineSpaces(node) {
|
|
|
31
28
|
* This rule is adapted from eslint-plugin-react's self-closing-comp rule under the MIT license,
|
|
32
29
|
* with some enhancements. Thank you for your work!
|
|
33
30
|
*/
|
|
34
|
-
export default
|
|
31
|
+
export default {
|
|
35
32
|
meta: {
|
|
36
33
|
type: "layout",
|
|
37
34
|
docs: {
|
|
@@ -150,4 +147,4 @@ export default createRule({
|
|
|
150
147
|
},
|
|
151
148
|
};
|
|
152
149
|
},
|
|
153
|
-
}
|
|
150
|
+
};
|
package/src/rules/style_prop.mjs
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getPropertyName, getStaticValue } from "@eslint-community/eslint-utils";
|
|
2
2
|
import kebabCase from "kebab-case";
|
|
3
3
|
import { all as allCssProperties } from "known-css-properties";
|
|
4
4
|
import parse from "style-to-object";
|
|
5
5
|
|
|
6
6
|
import { getScope } from "../compat.mjs";
|
|
7
7
|
import { jsxPropName } from "../utils.mjs";
|
|
8
|
-
const createRule = ESLintUtils.RuleCreator.withoutDocs;
|
|
9
|
-
const { getPropertyName, getStaticValue } = ASTUtils;
|
|
10
8
|
const lengthPercentageRegex =
|
|
11
9
|
/\b(?:width|height|margin|padding|border-width|font-size)\b/i;
|
|
12
|
-
export default
|
|
10
|
+
export default {
|
|
13
11
|
meta: {
|
|
14
12
|
type: "problem",
|
|
15
13
|
docs: {
|
|
@@ -152,4 +150,4 @@ export default createRule({
|
|
|
152
150
|
},
|
|
153
151
|
};
|
|
154
152
|
},
|
|
155
|
-
}
|
|
153
|
+
};
|