Skip to content

Commit a9445ee

Browse files
committed
refactor: update attribute retrieval in JSX rules for consistency and remove unused utility function
1 parent 9ea3b0c commit a9445ee

19 files changed

+46
-308
lines changed

packages/plugins/eslint-plugin-react-dom/src/rules/no-dangerously-set-innerhtml-with-children.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ export default createRule<[], MessageID>({
3434
JSXElement(node) {
3535
const attributes = node.openingElement.attributes;
3636
const initialScope = context.sourceCode.getScope(node);
37-
const hasChildren = hasChildrenWithin(node) || JSX.hasAttribute("children", initialScope, attributes);
38-
if (hasChildren && JSX.hasAttribute("dangerouslySetInnerHTML", initialScope, attributes)) {
37+
const hasChildren = hasChildrenWithin(node) || JSX.hasAttribute("children", attributes, initialScope);
38+
if (hasChildren && JSX.hasAttribute("dangerouslySetInnerHTML", attributes, initialScope)) {
3939
context.report({
4040
messageId: "noDangerouslySetInnerhtmlWithChildren",
4141
node,

packages/plugins/eslint-plugin-react-dom/src/rules/no-dangerously-set-innerhtml.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ export default createRule<[], MessageID>({
3333
const attributes = node.openingElement.attributes;
3434
const attribute = JSX.getAttribute(
3535
"dangerouslySetInnerHTML",
36-
context.sourceCode.getScope(node),
3736
attributes,
37+
context.sourceCode.getScope(node),
3838
);
3939
if (attribute == null) return;
4040
context.report({

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
@@ -48,8 +48,8 @@ export default createRule<[], MessageID>({
4848
const propNameOnJsx = customComponentProp?.name ?? "type";
4949
const attributeNode = JSX.getAttribute(
5050
propNameOnJsx,
51-
elementScope,
5251
node.openingElement.attributes,
52+
elementScope,
5353
);
5454
if (attributeNode != null) {
5555
const attributeScope = context.sourceCode.getScope(attributeNode);

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
@@ -73,8 +73,8 @@ export default createRule<[], MessageID>({
7373
const propNameOnJsx = customComponentProp?.name ?? "sandbox";
7474
const attributeNode = JSX.getAttribute(
7575
propNameOnJsx,
76-
elementScope,
7776
node.openingElement.attributes,
77+
elementScope,
7878
);
7979
if (attributeNode != null) {
8080
const attributeScope = context.sourceCode.getScope(attributeNode);

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
@@ -58,8 +58,8 @@ export default createRule<[], MessageID>({
5858
const propNameOnJsx = customComponentProp?.name ?? "sandbox";
5959
const attributeNode = JSX.getAttribute(
6060
propNameOnJsx,
61-
elementScope,
6261
node.openingElement.attributes,
62+
elementScope,
6363
);
6464
if (attributeNode != null) {
6565
const attributeScope = context.sourceCode.getScope(attributeNode);

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
@@ -63,8 +63,8 @@ export default createRule<[], MessageID>({
6363
const propNameOnJsx = customComponentProp?.name ?? name;
6464
const attributeNode = JSX.getAttribute(
6565
propNameOnJsx,
66-
elementScope,
6766
node.openingElement.attributes,
67+
elementScope,
6868
);
6969
if (attributeNode == null) return customComponentProp?.defaultValue;
7070
const attributeScope = context.sourceCode.getScope(attributeNode);

packages/plugins/eslint-plugin-react-dom/src/rules/no-void-elements-with-children.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
const { attributes } = node.openingElement;
6565
const initialScope = context.sourceCode.getScope(node);
66-
const hasAttribute = (name: string) => JSX.hasAttribute(name, initialScope, attributes);
66+
const hasAttribute = (name: string) => JSX.hasAttribute(name, attributes, initialScope);
6767
if (hasAttribute("children") || hasAttribute("dangerouslySetInnerHTML")) {
6868
// e.g. <br children="Foo" />
6969
context.report({

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
@@ -20,8 +20,8 @@ export function getElementNameOnJsxAndDom(
2020
const initialScope = context.sourceCode.getScope(node);
2121
const attributeNode = JSX.getAttribute(
2222
polymorphicPropName,
23-
initialScope,
2423
node.openingElement.attributes,
24+
initialScope,
2525
);
2626
if (attributeNode == null) return [name, name];
2727
const polymorphicPropValue = JSX.getAttributeValue(attributeNode, polymorphicPropName, initialScope);

packages/plugins/eslint-plugin-react-x/src/rules/no-children-prop.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export default createRule<[], MessageID>({
3030
JSXElement(node) {
3131
const attribute = JSX.getAttribute(
3232
"children",
33-
context.sourceCode.getScope(node),
3433
node.openingElement.attributes,
34+
context.sourceCode.getScope(node),
3535
);
3636
if (attribute != null) {
3737
context.report({

packages/plugins/eslint-plugin-react-x/src/rules/no-implicit-key.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default createRule<[], MessageID>({
3131
return {
3232
JSXOpeningElement(node: TSESTree.JSXOpeningElement) {
3333
const initialScope = context.sourceCode.getScope(node);
34-
const keyPropFound = JSX.getAttribute("key", initialScope, node.attributes);
34+
const keyPropFound = JSX.getAttribute("key", node.attributes, initialScope);
3535
const keyPropOnElement = node.attributes
3636
.some((n) =>
3737
n.type === T.JSXAttribute

0 commit comments

Comments
 (0)