Skip to content

Commit 7135243

Browse files
committed
refactor(plugins/x): minor improvements
1 parent b4c869e commit 7135243

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

packages/plugins/eslint-plugin-react-x/src/rules/no-context-provider.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ export default createRule<[], MessageID>({
3030
},
3131
name: RULE_NAME,
3232
create(context) {
33-
if (!context.sourceCode.text.includes(".Provider")) {
34-
return {};
35-
}
33+
if (!context.sourceCode.text.includes(".Provider")) return {};
3634
const { version } = getSettingsFromContext(context);
3735
if (compare(version, "19.0.0", "<")) {
3836
return {};
@@ -47,15 +45,15 @@ export default createRule<[], MessageID>({
4745
messageId: "noContextProvider",
4846
node,
4947
fix(fixer) {
50-
const providerName = elementName.replace(/\.Provider$/, "");
48+
const contextName = elementName.replace(/\.Provider$/, "");
5149
const openingElement = node.openingElement;
5250
const closingElement = node.closingElement;
5351
if (closingElement == null) {
54-
return fixer.replaceText(openingElement.name, providerName);
52+
return fixer.replaceText(openingElement.name, contextName);
5553
}
5654
return [
57-
fixer.replaceText(openingElement.name, providerName),
58-
fixer.replaceText(closingElement.name, providerName),
55+
fixer.replaceText(openingElement.name, contextName),
56+
fixer.replaceText(closingElement.name, contextName),
5957
];
6058
},
6159
});

packages/plugins/eslint-plugin-react-x/src/rules/no-forward-ref.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,20 @@ function getFix(node: TSESTree.CallExpression, context: RuleContext): (fixer: Ru
7171
fixer.removeRange([componentNode.range[1], node.range[1]]),
7272
// update component props and ref arguments to match the new signature
7373
...getComponentPropsFixes(
74+
context,
75+
fixer,
7476
componentNode,
7577
node.typeArguments?.params ?? [],
76-
fixer,
77-
context,
7878
),
7979
] as const;
8080
};
8181
}
8282

8383
function getComponentPropsFixes(
84+
context: RuleContext,
85+
fixer: RuleFixer,
8486
node: AST.TSESTreeFunction,
8587
typeArguments: TSESTree.TypeNode[],
86-
fixer: RuleFixer,
87-
context: RuleContext,
8888
) {
8989
const getText = (node: TSESTree.Node) => context.sourceCode.getText(node);
9090
const [arg0, arg1] = node.params;
@@ -99,7 +99,7 @@ function getComponentPropsFixes(
9999
const fixedArg1Text = match(arg1)
100100
.with(P.nullish, () => "ref")
101101
.with({ type: T.Identifier, name: "ref" }, () => "ref")
102-
.with({ type: T.Identifier, name: P.not("ref") }, (n) => `ref: ${n.name}`)
102+
.with({ type: T.Identifier, name: P.string }, (n) => `ref: ${n.name}`)
103103
.otherwise(() => _);
104104
if (fixedArg0Text == null || fixedArg1Text == null) {
105105
return [];

0 commit comments

Comments
 (0)