Skip to content

Commit da4be2c

Browse files
committed
refactor: minor improvements
1 parent a37cd96 commit da4be2c

File tree

11 files changed

+13
-12
lines changed

11 files changed

+13
-12
lines changed

packages/plugins/eslint-plugin-react-dom/src/rules/no-missing-button-type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default createRule<[], MessageID>({
5353
);
5454
if (attributeNode != null) {
5555
const attributeScope = context.sourceCode.getScope(attributeNode);
56-
const attributeValue = JSX.getAttributeValue(propNameOnJsx, attributeNode, attributeScope);
56+
const attributeValue = JSX.getAttributeValue(attributeNode, propNameOnJsx, attributeScope);
5757
if (attributeValue.kind === "some" && typeof attributeValue.value !== "string") {
5858
context.report({
5959
messageId: "noMissingButtonType",

packages/plugins/eslint-plugin-react-dom/src/rules/no-missing-iframe-sandbox.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export default createRule<[], MessageID>({
7878
);
7979
if (attributeNode != null) {
8080
const attributeScope = context.sourceCode.getScope(attributeNode);
81-
const attributeValue = JSX.getAttributeValue(propNameOnJsx, attributeNode, attributeScope);
81+
const attributeValue = JSX.getAttributeValue(attributeNode, propNameOnJsx, attributeScope);
8282
if (attributeValue.kind === "some" && hasValidSandBox(attributeValue.value)) return;
8383
context.report({
8484
messageId: "noMissingIframeSandbox",

packages/plugins/eslint-plugin-react-dom/src/rules/no-script-url.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ export default createRule<[], MessageID>({
3838
return;
3939
}
4040
const attributeScope = context.sourceCode.getScope(node);
41-
const attributeValue = JSX.getAttributeValue(JSX.toString(node.name), node, attributeScope);
41+
const attributeName = JSX.getAttributeName(node);
42+
const attributeValue = JSX.getAttributeValue(node, attributeName, attributeScope);
4243
if (attributeValue.kind === "none" || typeof attributeValue.value !== "string") return;
4344
if (RE_JAVASCRIPT_PROTOCOL.test(attributeValue.value)) {
4445
context.report({

packages/plugins/eslint-plugin-react-dom/src/rules/no-unsafe-iframe-sandbox.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export default createRule<[], MessageID>({
6363
);
6464
if (attributeNode != null) {
6565
const attributeScope = context.sourceCode.getScope(attributeNode);
66-
const attributeValue = JSX.getAttributeValue(propNameOnJsx, attributeNode, attributeScope);
66+
const attributeValue = JSX.getAttributeValue(attributeNode, propNameOnJsx, attributeScope);
6767
if (attributeValue.kind === "some" && !hasSafeSandbox(attributeValue.value)) {
6868
context.report({
6969
messageId: "noUnsafeIframeSandbox",

packages/plugins/eslint-plugin-react-dom/src/rules/no-unsafe-target-blank.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export default createRule<[], MessageID>({
6868
);
6969
if (attributeNode == null) return customComponentProp?.defaultValue;
7070
const attributeScope = context.sourceCode.getScope(attributeNode);
71-
const attributeValue = JSX.getAttributeValue(propNameOnJsx, attributeNode, attributeScope);
71+
const attributeValue = JSX.getAttributeValue(attributeNode, propNameOnJsx, attributeScope);
7272
if (attributeValue.kind === "some" && typeof attributeValue.value === "string") {
7373
return attributeValue.value;
7474
}

packages/plugins/eslint-plugin-react-dom/src/utils/get-element-name-on-jsx-and-dom.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function getElementNameOnJsxAndDom(
2424
node.openingElement.attributes,
2525
);
2626
if (attributeNode == null) return [name, name];
27-
const polymorphicPropValue = JSX.getAttributeValue(polymorphicPropName, attributeNode, initialScope);
27+
const polymorphicPropValue = JSX.getAttributeValue(attributeNode, polymorphicPropName, initialScope);
2828
if (polymorphicPropValue.kind === "some" && typeof polymorphicPropValue.value === "string") {
2929
return [name, polymorphicPropValue.value];
3030
}

packages/utilities/jsx/src/get-attribute-value.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import { match, P } from "ts-pattern";
66

77
/**
88
* Get a StaticValue of the attribute value
9-
* @param name The name of the attribute
109
* @param node The JSX attribute node
10+
* @param name The name of the attribute
1111
* @param initialScope The initial scope to use
1212
* @returns The StaticValue of the attribute value
1313
*/
1414
export function getAttributeValue(
15-
name: string,
1615
node: TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute,
16+
name: string,
1717
initialScope: Scope,
1818
): Exclude<VAR.LazyValue, { kind: "lazy" }> {
1919
switch (node.type) {

packages/utilities/jsx/src/get-attribute.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { Scope } from "@typescript-eslint/scope-manager";
44
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
55
import type { TSESTree } from "@typescript-eslint/utils";
66

7-
import { getAttributeName } from "./attribute-name";
7+
import { getAttributeName } from "./get-attribute-name";
88

99
/**
1010
* Get the JSX attribute node with the given name

0 commit comments

Comments
 (0)