@murky-web/oxlint-plugin-solid 1.5.0 → 1.6.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 +163 -18
- package/THIRD_PARTY_NOTICES.md +7 -4
- package/package.json +5 -2
- package/src/compat.mjs +3 -0
- package/src/index.mjs +26 -3
- package/src/rules/components_return_once.mjs +136 -89
- package/src/rules/event_handlers.mjs +55 -35
- package/src/rules/filename_matches_export.mjs +292 -0
- package/src/rules/function_size.mjs +189 -0
- package/src/rules/imports.mjs +24 -21
- package/src/rules/init_declarations.mjs +139 -0
- package/src/rules/jsx_no_duplicate_props.mjs +46 -18
- package/src/rules/jsx_no_script_url.mjs +7 -6
- package/src/rules/jsx_no_undef.mjs +35 -38
- package/src/rules/jsx_uses_vars.mjs +4 -4
- package/src/rules/no_array_handlers.mjs +38 -9
- package/src/rules/no_cleanup_in_effect_apply.mjs +154 -0
- package/src/rules/no_destructure.mjs +105 -35
- package/src/rules/no_innerhtml.mjs +64 -31
- package/src/rules/no_module_scope_reactive_primitive.mjs +73 -0
- package/src/rules/no_owned_primitives_in_ref.mjs +30 -9
- package/src/rules/no_proxy_apis.mjs +44 -15
- package/src/rules/no_react_deps.mjs +397 -41
- package/src/rules/no_react_specific_props.mjs +40 -11
- package/src/rules/no_server_import_in_client.mjs +9 -9
- package/src/rules/no_setter_in_effect.mjs +153 -30
- package/src/rules/no_single_arg_create_effect.mjs +55 -0
- package/src/rules/no_unassigned_vars.mjs +99 -0
- package/src/rules/no_unknown_namespaces.mjs +108 -29
- package/src/rules/no_untracked_effect_read.mjs +69 -32
- package/src/rules/no_write_in_pure_computation.mjs +273 -0
- package/src/rules/prefer_arrow_components.mjs +47 -21
- package/src/rules/prefer_class_object.mjs +52 -20
- package/src/rules/prefer_destructuring.mjs +164 -0
- package/src/rules/prefer_for.mjs +42 -12
- package/src/rules/prefer_ref_shorthand.mjs +142 -0
- package/src/rules/prefer_show.mjs +55 -24
- package/src/rules/reactive_async.mjs +64 -17
- package/src/rules/reactivity.mjs +1218 -350
- package/src/rules/self_closing_comp.mjs +23 -18
- package/src/rules/strict_void_return.mjs +50 -20
- package/src/rules/style_prop.mjs +53 -25
- package/src/rules/typed_merge_defaults.mjs +88 -0
- package/src/rules/validate_jsx_nesting.mjs +16 -16
- package/src/utils.mjs +65 -34
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getSourceCode } from "../compat.mjs";
|
|
2
|
-
import { getFunctionName } from "../utils.mjs";
|
|
2
|
+
import { getFunctionName, messageCode } from "../utils.mjs";
|
|
3
3
|
const isNothing = (node) => {
|
|
4
4
|
if (!node) {
|
|
5
5
|
return true;
|
|
@@ -14,22 +14,50 @@ const isNothing = (node) => {
|
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
16
|
const getLineLength = (loc) => loc.end.line - loc.start.line + 1;
|
|
17
|
+
const EARLY_RETURN_PATTERN = "return <Show when={…} fallback={…}>…</Show>;";
|
|
18
|
+
// `if (test) return A; ... return B;` as one `<Show>`, when the `if` holds
|
|
19
|
+
// nothing but that return and both returns have a value.
|
|
20
|
+
const earlyReturnFix = (earlyReturn, lastReturn, sourceCode) => {
|
|
21
|
+
const block = earlyReturn.parent;
|
|
22
|
+
const ifStatement =
|
|
23
|
+
block.type === "BlockStatement" && block.body.length === 1
|
|
24
|
+
? block.parent
|
|
25
|
+
: block;
|
|
26
|
+
if (
|
|
27
|
+
ifStatement.type !== "IfStatement" ||
|
|
28
|
+
ifStatement.alternate ||
|
|
29
|
+
!earlyReturn.argument ||
|
|
30
|
+
!lastReturn?.argument
|
|
31
|
+
) {
|
|
32
|
+
return EARLY_RETURN_PATTERN;
|
|
33
|
+
}
|
|
34
|
+
const jsx = (node) => {
|
|
35
|
+
const text = sourceCode.getText(node);
|
|
36
|
+
return node.type === "JSXElement" || node.type === "JSXFragment"
|
|
37
|
+
? text
|
|
38
|
+
: `{${text}}`;
|
|
39
|
+
};
|
|
40
|
+
return messageCode(
|
|
41
|
+
`return <Show when={${sourceCode.getText(ifStatement.test)}} fallback={${sourceCode.getText(lastReturn.argument)}}>${jsx(earlyReturn.argument)}</Show>;`,
|
|
42
|
+
EARLY_RETURN_PATTERN
|
|
43
|
+
);
|
|
44
|
+
};
|
|
17
45
|
export default {
|
|
18
46
|
meta: {
|
|
19
47
|
type: "problem",
|
|
20
48
|
docs: {
|
|
21
49
|
description:
|
|
22
50
|
"Disallow early returns in components. Solid components only run once, and so conditionals should be inside JSX.",
|
|
23
|
-
url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/components-return-once.md"
|
|
51
|
+
url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/components-return-once.md"
|
|
24
52
|
},
|
|
25
53
|
fixable: "code",
|
|
26
54
|
schema: [],
|
|
27
55
|
messages: {
|
|
28
56
|
noEarlyReturn:
|
|
29
|
-
"
|
|
57
|
+
"{{component}} returns early. A component body runs once, so it never switches branches when the condition changes (dev: `STRICT_READ_UNTRACKED`). Fix: one return with the condition in JSX, `{{fix}}` (`<Switch>`/`<Match>` for more branches). Do not: `untrack()` the condition.",
|
|
30
58
|
noConditionalReturn:
|
|
31
|
-
"
|
|
32
|
-
}
|
|
59
|
+
"{{component}} picks its return with `{{test}}`. A component body runs once, so it never switches when `{{test}}` changes. Fix: `{{fix}}`. Do not: `untrack()` the condition."
|
|
60
|
+
}
|
|
33
61
|
},
|
|
34
62
|
defaultOptions: [],
|
|
35
63
|
create(context) {
|
|
@@ -40,13 +68,58 @@ export default {
|
|
|
40
68
|
? text
|
|
41
69
|
: `{${text}}`;
|
|
42
70
|
};
|
|
71
|
+
// The autofix's replacement for `return test ? a : b`.
|
|
72
|
+
const conditionalReplacement = (argument) => {
|
|
73
|
+
const sourceCode = getSourceCode(context);
|
|
74
|
+
const { test, consequent, alternate } = argument;
|
|
75
|
+
const conditions = [{ test, consequent }];
|
|
76
|
+
let fallback = alternate;
|
|
77
|
+
while (fallback.type === "ConditionalExpression") {
|
|
78
|
+
conditions.push({
|
|
79
|
+
test: fallback.test,
|
|
80
|
+
consequent: fallback.consequent
|
|
81
|
+
});
|
|
82
|
+
fallback = fallback.alternate;
|
|
83
|
+
}
|
|
84
|
+
if (conditions.length >= 2) {
|
|
85
|
+
// we have a nested ternary, use <Switch><Match /></Switch>
|
|
86
|
+
const fallbackStr = !isNothing(fallback)
|
|
87
|
+
? ` fallback={${sourceCode.getText(fallback)}}`
|
|
88
|
+
: "";
|
|
89
|
+
return `<Switch${fallbackStr}>\n${conditions
|
|
90
|
+
.map(
|
|
91
|
+
({ test, consequent }) =>
|
|
92
|
+
`<Match when={${sourceCode.getText(test)}}>${putIntoJSX(consequent)}</Match>`
|
|
93
|
+
)
|
|
94
|
+
.join("\n")}\n</Switch>`;
|
|
95
|
+
}
|
|
96
|
+
if (isNothing(consequent)) {
|
|
97
|
+
// we have a single ternary and the consequent is nothing. Negate the condition and use a <Show>.
|
|
98
|
+
return `<Show when={!(${sourceCode.getText(test)})}>${putIntoJSX(alternate)}</Show>`;
|
|
99
|
+
}
|
|
100
|
+
if (
|
|
101
|
+
isNothing(fallback) ||
|
|
102
|
+
getLineLength(consequent.loc) >=
|
|
103
|
+
getLineLength(alternate.loc) * 1.5
|
|
104
|
+
) {
|
|
105
|
+
// we have a standard ternary, and the alternate is a bit shorter in LOC than the consequent, which
|
|
106
|
+
// should be enough to tell that it's logically a fallback instead of an equal branch.
|
|
107
|
+
const fallbackStr = !isNothing(fallback)
|
|
108
|
+
? ` fallback={${sourceCode.getText(fallback)}}`
|
|
109
|
+
: "";
|
|
110
|
+
return `<Show when={${sourceCode.getText(test)}}${fallbackStr}>${putIntoJSX(consequent)}</Show>`;
|
|
111
|
+
}
|
|
112
|
+
// we have a standard ternary, but no signal from the user as to which branch is the "fallback" and
|
|
113
|
+
// which is the children. Move the whole conditional inside a JSX fragment.
|
|
114
|
+
return `<>${putIntoJSX(argument)}</>`;
|
|
115
|
+
};
|
|
43
116
|
const currentFunction = () => functionStack[functionStack.length - 1];
|
|
44
117
|
const onFunctionEnter = (node) => {
|
|
45
118
|
let lastReturn;
|
|
46
119
|
if (node.body.type === "BlockStatement") {
|
|
47
120
|
// find last statement, ignoring function/class/variable declarations (hoisting)
|
|
48
121
|
const last = node.body.body.findLast(
|
|
49
|
-
(node) => !node.type.endsWith("Declaration")
|
|
122
|
+
(node) => !node.type.endsWith("Declaration")
|
|
50
123
|
);
|
|
51
124
|
// if it's a return, store it
|
|
52
125
|
if (last && last.type === "ReturnStatement") {
|
|
@@ -56,7 +129,7 @@ export default {
|
|
|
56
129
|
functionStack.push({
|
|
57
130
|
isComponent: false,
|
|
58
131
|
lastReturn,
|
|
59
|
-
earlyReturns: []
|
|
132
|
+
earlyReturns: []
|
|
60
133
|
});
|
|
61
134
|
};
|
|
62
135
|
const onFunctionExit = (node) => {
|
|
@@ -72,98 +145,72 @@ export default {
|
|
|
72
145
|
currentFunction().isComponent = false;
|
|
73
146
|
}
|
|
74
147
|
if (currentFunction().isComponent) {
|
|
75
|
-
|
|
76
|
-
|
|
148
|
+
const sourceCode = getSourceCode(context);
|
|
149
|
+
const name = getFunctionName(node);
|
|
150
|
+
const component = name ? `\`${name}\`` : "This component";
|
|
151
|
+
const { lastReturn } = currentFunction();
|
|
152
|
+
// Warn on each early return; with more than one, the branches
|
|
153
|
+
// go into a <Switch>, which no single `if` shows.
|
|
154
|
+
const { earlyReturns } = currentFunction();
|
|
155
|
+
earlyReturns.forEach((earlyReturn) => {
|
|
77
156
|
context.report({
|
|
78
157
|
node: earlyReturn,
|
|
79
158
|
messageId: "noEarlyReturn",
|
|
159
|
+
data: {
|
|
160
|
+
component,
|
|
161
|
+
fix:
|
|
162
|
+
earlyReturns.length > 1
|
|
163
|
+
? "return <Switch fallback={…}><Match when={…}>…</Match></Switch>;"
|
|
164
|
+
: earlyReturnFix(
|
|
165
|
+
earlyReturn,
|
|
166
|
+
lastReturn,
|
|
167
|
+
sourceCode
|
|
168
|
+
)
|
|
169
|
+
}
|
|
80
170
|
});
|
|
81
171
|
});
|
|
82
|
-
const argument =
|
|
172
|
+
const argument = lastReturn?.argument;
|
|
173
|
+
// What the conditional return becomes: the autofix's
|
|
174
|
+
// replacement where there is one, else the whole expression
|
|
175
|
+
// in a fragment, which keeps it reactive.
|
|
176
|
+
const conditionalData = (test, replacement) => ({
|
|
177
|
+
component,
|
|
178
|
+
test: messageCode(sourceCode.getText(test), "condition"),
|
|
179
|
+
fix: messageCode(
|
|
180
|
+
`return ${replacement};`,
|
|
181
|
+
"return <Show when={condition} fallback={…}>…</Show>;"
|
|
182
|
+
)
|
|
183
|
+
});
|
|
83
184
|
if (argument?.type === "ConditionalExpression") {
|
|
84
|
-
const sourceCode = getSourceCode(context);
|
|
85
185
|
context.report({
|
|
86
186
|
node: argument.parent,
|
|
87
187
|
messageId: "noConditionalReturn",
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
test: fallback.test,
|
|
95
|
-
consequent: fallback.consequent,
|
|
96
|
-
});
|
|
97
|
-
fallback = fallback.alternate;
|
|
98
|
-
}
|
|
99
|
-
if (conditions.length >= 2) {
|
|
100
|
-
// we have a nested ternary, use <Switch><Match /></Switch>
|
|
101
|
-
const fallbackStr = !isNothing(fallback)
|
|
102
|
-
? ` fallback={${sourceCode.getText(fallback)}}`
|
|
103
|
-
: "";
|
|
104
|
-
return fixer.replaceText(
|
|
105
|
-
argument,
|
|
106
|
-
`<Switch${fallbackStr}>\n${conditions
|
|
107
|
-
.map(
|
|
108
|
-
({ test, consequent }) =>
|
|
109
|
-
`<Match when={${sourceCode.getText(test)}}>${putIntoJSX(consequent)}</Match>`,
|
|
110
|
-
)
|
|
111
|
-
.join("\n")}\n</Switch>`,
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
if (isNothing(consequent)) {
|
|
115
|
-
// we have a single ternary and the consequent is nothing. Negate the condition and use a <Show>.
|
|
116
|
-
return fixer.replaceText(
|
|
117
|
-
argument,
|
|
118
|
-
`<Show when={!(${sourceCode.getText(test)})}>${putIntoJSX(alternate)}</Show>`,
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
if (
|
|
122
|
-
isNothing(fallback) ||
|
|
123
|
-
getLineLength(consequent.loc) >=
|
|
124
|
-
getLineLength(alternate.loc) * 1.5
|
|
125
|
-
) {
|
|
126
|
-
// we have a standard ternary, and the alternate is a bit shorter in LOC than the consequent, which
|
|
127
|
-
// should be enough to tell that it's logically a fallback instead of an equal branch.
|
|
128
|
-
const fallbackStr = !isNothing(fallback)
|
|
129
|
-
? ` fallback={${sourceCode.getText(fallback)}}`
|
|
130
|
-
: "";
|
|
131
|
-
return fixer.replaceText(
|
|
132
|
-
argument,
|
|
133
|
-
`<Show when={${sourceCode.getText(test)}}${fallbackStr}>${putIntoJSX(consequent)}</Show>`,
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
// we have a standard ternary, but no signal from the user as to which branch is the "fallback" and
|
|
137
|
-
// which is the children. Move the whole conditional inside a JSX fragment.
|
|
138
|
-
return fixer.replaceText(
|
|
188
|
+
data: conditionalData(
|
|
189
|
+
argument.test,
|
|
190
|
+
conditionalReplacement(argument)
|
|
191
|
+
),
|
|
192
|
+
fix: (fixer) =>
|
|
193
|
+
fixer.replaceText(
|
|
139
194
|
argument,
|
|
140
|
-
|
|
141
|
-
)
|
|
142
|
-
},
|
|
195
|
+
conditionalReplacement(argument)
|
|
196
|
+
)
|
|
143
197
|
});
|
|
144
198
|
} else if (argument?.type === "LogicalExpression") {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
} else {
|
|
161
|
-
// we have some other kind of conditional, warn
|
|
162
|
-
context.report({
|
|
163
|
-
node: argument,
|
|
164
|
-
messageId: "noConditionalReturn",
|
|
165
|
-
});
|
|
166
|
-
}
|
|
199
|
+
// `return condition && expression` goes into a <Show />;
|
|
200
|
+
// any other operator into a fragment, without a fix.
|
|
201
|
+
const isAnd = argument.operator === "&&";
|
|
202
|
+
const replacement = isAnd
|
|
203
|
+
? `<Show when={${sourceCode.getText(argument.left)}}>${putIntoJSX(argument.right)}</Show>`
|
|
204
|
+
: `<>${putIntoJSX(argument)}</>`;
|
|
205
|
+
context.report({
|
|
206
|
+
node: argument,
|
|
207
|
+
messageId: "noConditionalReturn",
|
|
208
|
+
data: conditionalData(argument.left, replacement),
|
|
209
|
+
fix: isAnd
|
|
210
|
+
? (fixer) =>
|
|
211
|
+
fixer.replaceText(argument, replacement)
|
|
212
|
+
: undefined
|
|
213
|
+
});
|
|
167
214
|
}
|
|
168
215
|
}
|
|
169
216
|
// Pop on exit
|
|
@@ -193,7 +240,7 @@ export default {
|
|
|
193
240
|
) {
|
|
194
241
|
currentFunction().earlyReturns.push(node);
|
|
195
242
|
}
|
|
196
|
-
}
|
|
243
|
+
}
|
|
197
244
|
};
|
|
198
|
-
}
|
|
245
|
+
}
|
|
199
246
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getStaticValue } from "@eslint-community/eslint-utils";
|
|
2
2
|
|
|
3
3
|
import { getScope, getSourceCode } from "../compat.mjs";
|
|
4
|
-
import { isDOMElementName } from "../utils.mjs";
|
|
4
|
+
import { isDOMElementName, messageCode } from "../utils.mjs";
|
|
5
5
|
const COMMON_EVENTS = [
|
|
6
6
|
"onAnimationEnd",
|
|
7
7
|
"onAnimationIteration",
|
|
@@ -60,17 +60,18 @@ const COMMON_EVENTS = [
|
|
|
60
60
|
"onTouchMove",
|
|
61
61
|
"onTouchStart",
|
|
62
62
|
"onTransitionEnd",
|
|
63
|
-
"onWheel"
|
|
63
|
+
"onWheel"
|
|
64
64
|
];
|
|
65
65
|
const COMMON_EVENTS_MAP = new Map(
|
|
66
66
|
(function* () {
|
|
67
67
|
for (const event of COMMON_EVENTS) {
|
|
68
68
|
yield [event.toLowerCase(), event];
|
|
69
69
|
}
|
|
70
|
-
})()
|
|
70
|
+
})()
|
|
71
71
|
);
|
|
72
|
+
const IDENTIFIER = /^[A-Za-z_$][\w$]*$/;
|
|
72
73
|
const NONSTANDARD_EVENTS_MAP = {
|
|
73
|
-
ondoubleclick: "onDblClick"
|
|
74
|
+
ondoubleclick: "onDblClick"
|
|
74
75
|
};
|
|
75
76
|
const isCommonHandlerName = (lowercaseHandlerName) =>
|
|
76
77
|
COMMON_EVENTS_MAP.has(lowercaseHandlerName);
|
|
@@ -86,7 +87,7 @@ export default {
|
|
|
86
87
|
docs: {
|
|
87
88
|
description:
|
|
88
89
|
"Enforce naming DOM element event handlers consistently and prevent Solid's analysis from misunderstanding whether a prop should be an event handler.",
|
|
89
|
-
url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/event-handlers.md"
|
|
90
|
+
url: "https://github.com/solidjs-community/eslint-plugin-solid/blob/main/packages/eslint-plugin-solid/docs/event-handlers.md"
|
|
90
91
|
},
|
|
91
92
|
fixable: "code",
|
|
92
93
|
hasSuggestions: true,
|
|
@@ -98,34 +99,39 @@ export default {
|
|
|
98
99
|
type: "boolean",
|
|
99
100
|
description:
|
|
100
101
|
"if true, don't warn on ambiguously named event handlers like `onclick` or `onchange`",
|
|
101
|
-
default: false
|
|
102
|
+
default: false
|
|
102
103
|
},
|
|
103
104
|
warnOnSpread: {
|
|
104
105
|
type: "boolean",
|
|
105
106
|
description:
|
|
106
107
|
"if true, warn when spreading event handlers onto JSX. Enable for Solid < v1.6.",
|
|
107
|
-
default: false
|
|
108
|
-
}
|
|
108
|
+
default: false
|
|
109
|
+
}
|
|
109
110
|
},
|
|
110
|
-
additionalProperties: false
|
|
111
|
-
}
|
|
111
|
+
additionalProperties: false
|
|
112
|
+
}
|
|
112
113
|
],
|
|
113
114
|
messages: {
|
|
114
115
|
"detected-attr":
|
|
115
|
-
|
|
116
|
-
naming: "
|
|
116
|
+
"`{{name}}` is named like an event handler but has the constant value `{{staticValue}}`, so Solid writes it into the template as an attribute and attaches no listener. Fix: to handle the event, pass a function, `{{name}}={{{handler}}}`; to keep an attribute, use a name that does not start with `on`.",
|
|
117
|
+
naming: "`{{name}}` is not an event handler in Solid 2.0: only `on` followed by an uppercase letter is, so `{{name}}` is set as an attribute and a function value is never called. Fix: `{{handlerName}}` if it handles the `{{event}}` event; otherwise a name that does not start with `on`.",
|
|
117
118
|
capitalization:
|
|
118
|
-
"
|
|
119
|
+
"`{{name}}` is not an event handler in Solid 2.0: only `on` followed by an uppercase letter is, so `{{name}}` is set as an attribute and a function value is never called. Fix: `{{fixedName}}`.",
|
|
119
120
|
nonstandard:
|
|
120
|
-
"
|
|
121
|
-
"make-handler": "
|
|
121
|
+
"`{{name}}` listens to a `{{event}}` event, which the DOM never fires. Fix: `{{fixedName}}`.",
|
|
122
|
+
"make-handler": "Rename `{{name}}` to `{{handlerName}}`.",
|
|
122
123
|
"spread-handler":
|
|
123
|
-
"
|
|
124
|
-
}
|
|
124
|
+
"`{{name}}` is spread in from an object literal. Solid before 1.6 attaches no listener for a spread handler, which is what the `warnOnSpread` option checks. Fix: pass it as an attribute, `{{name}}={{{value}}}`."
|
|
125
|
+
}
|
|
125
126
|
},
|
|
126
127
|
defaultOptions: [],
|
|
127
128
|
create(context) {
|
|
128
129
|
const sourceCode = getSourceCode(context);
|
|
130
|
+
// `onClick="save"` most likely means the function `save`.
|
|
131
|
+
const handlerFor = (value) =>
|
|
132
|
+
typeof value === "string" && IDENTIFIER.test(value)
|
|
133
|
+
? value
|
|
134
|
+
: "(event) => { … }";
|
|
129
135
|
return {
|
|
130
136
|
JSXAttribute(node) {
|
|
131
137
|
const openingElement = node.parent;
|
|
@@ -150,7 +156,7 @@ export default {
|
|
|
150
156
|
node.value.expression.type !== "ArrayExpression" && // array syntax prevents inlining
|
|
151
157
|
(staticValue = getStaticValue(
|
|
152
158
|
node.value.expression,
|
|
153
|
-
getScope(context, node)
|
|
159
|
+
getScope(context, node)
|
|
154
160
|
)) !== null &&
|
|
155
161
|
(typeof staticValue.value === "string" ||
|
|
156
162
|
typeof staticValue.value === "number")
|
|
@@ -171,21 +177,23 @@ export default {
|
|
|
171
177
|
data: {
|
|
172
178
|
name,
|
|
173
179
|
staticValue: staticValue.value,
|
|
174
|
-
|
|
180
|
+
handler: handlerFor(staticValue.value)
|
|
181
|
+
}
|
|
175
182
|
});
|
|
176
183
|
} else if (
|
|
177
184
|
node.value === null ||
|
|
178
185
|
node.value?.type === "Literal"
|
|
179
186
|
) {
|
|
180
187
|
// Check for same as above for literal values
|
|
188
|
+
const value = node.value !== null ? node.value.value : true;
|
|
181
189
|
context.report({
|
|
182
190
|
node,
|
|
183
191
|
messageId: "detected-attr",
|
|
184
192
|
data: {
|
|
185
193
|
name,
|
|
186
|
-
staticValue:
|
|
187
|
-
|
|
188
|
-
}
|
|
194
|
+
staticValue: value,
|
|
195
|
+
handler: handlerFor(value)
|
|
196
|
+
}
|
|
189
197
|
});
|
|
190
198
|
} else if (!context.options[0]?.ignoreCase) {
|
|
191
199
|
const lowercaseHandlerName = name.toLowerCase();
|
|
@@ -195,9 +203,13 @@ export default {
|
|
|
195
203
|
context.report({
|
|
196
204
|
node: node.name,
|
|
197
205
|
messageId: "nonstandard",
|
|
198
|
-
data: {
|
|
206
|
+
data: {
|
|
207
|
+
name,
|
|
208
|
+
fixedName,
|
|
209
|
+
event: name.slice(2).toLowerCase()
|
|
210
|
+
},
|
|
199
211
|
fix: (fixer) =>
|
|
200
|
-
fixer.replaceText(node.name, fixedName)
|
|
212
|
+
fixer.replaceText(node.name, fixedName)
|
|
201
213
|
});
|
|
202
214
|
} else if (isCommonHandlerName(lowercaseHandlerName)) {
|
|
203
215
|
const fixedName =
|
|
@@ -210,7 +222,7 @@ export default {
|
|
|
210
222
|
messageId: "capitalization",
|
|
211
223
|
data: { name, fixedName },
|
|
212
224
|
fix: (fixer) =>
|
|
213
|
-
fixer.replaceText(node.name, fixedName)
|
|
225
|
+
fixer.replaceText(node.name, fixedName)
|
|
214
226
|
});
|
|
215
227
|
}
|
|
216
228
|
} else if (name[2] === name[2].toLowerCase()) {
|
|
@@ -223,7 +235,11 @@ export default {
|
|
|
223
235
|
context.report({
|
|
224
236
|
node: node.name,
|
|
225
237
|
messageId: "naming",
|
|
226
|
-
data: {
|
|
238
|
+
data: {
|
|
239
|
+
name,
|
|
240
|
+
handlerName,
|
|
241
|
+
event: name.slice(2).toLowerCase()
|
|
242
|
+
},
|
|
227
243
|
suggest: [
|
|
228
244
|
{
|
|
229
245
|
messageId: "make-handler",
|
|
@@ -231,10 +247,10 @@ export default {
|
|
|
231
247
|
fix: (fixer) =>
|
|
232
248
|
fixer.replaceText(
|
|
233
249
|
node.name,
|
|
234
|
-
handlerName
|
|
235
|
-
)
|
|
236
|
-
}
|
|
237
|
-
]
|
|
250
|
+
handlerName
|
|
251
|
+
)
|
|
252
|
+
}
|
|
253
|
+
]
|
|
238
254
|
});
|
|
239
255
|
}
|
|
240
256
|
}
|
|
@@ -263,6 +279,10 @@ export default {
|
|
|
263
279
|
messageId: "spread-handler",
|
|
264
280
|
data: {
|
|
265
281
|
name: node.key.name,
|
|
282
|
+
value: messageCode(
|
|
283
|
+
sourceCode.getText(node.value),
|
|
284
|
+
"handler"
|
|
285
|
+
)
|
|
266
286
|
},
|
|
267
287
|
*fix(fixer) {
|
|
268
288
|
const commaAfter =
|
|
@@ -270,21 +290,21 @@ export default {
|
|
|
270
290
|
yield fixer.remove(
|
|
271
291
|
node.parent.properties.length === 1
|
|
272
292
|
? node.parent.parent
|
|
273
|
-
: node
|
|
293
|
+
: node
|
|
274
294
|
);
|
|
275
295
|
if (commaAfter?.value === ",") {
|
|
276
296
|
yield fixer.remove(commaAfter);
|
|
277
297
|
}
|
|
278
298
|
yield fixer.insertTextAfter(
|
|
279
299
|
node.parent.parent,
|
|
280
|
-
` ${handlerName}={${sourceCode.getText(node.value)}}
|
|
300
|
+
` ${handlerName}={${sourceCode.getText(node.value)}}`
|
|
281
301
|
);
|
|
282
|
-
}
|
|
302
|
+
}
|
|
283
303
|
});
|
|
284
304
|
}
|
|
285
305
|
}
|
|
286
306
|
}
|
|
287
|
-
}
|
|
307
|
+
}
|
|
288
308
|
};
|
|
289
|
-
}
|
|
309
|
+
}
|
|
290
310
|
};
|