Skip to content

Commit 9f8e770

Browse files
authored
feat(no-use-context): enhance auto-fix to support remove aliased … (#933)
1 parent c9d7766 commit 9f8e770

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ ruleTester.run(RULE_NAME, rule, {
178178
{ messageId: "noUseContext" },
179179
],
180180
output: /* tsx */ `
181-
import { use, useContext as useCtx } from 'react'
181+
import { use } from 'react'
182182
183183
export const Component = () => {
184184
const value = use(MyContext)

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,10 @@ export default createRule<[], MessageID>({
7373
if (specifier.type !== T.ImportSpecifier) continue;
7474
if (specifier.imported.type !== T.Identifier) continue;
7575
if (specifier.imported.name === "useContext") {
76+
// import { useContext as useCtx } from 'react'
7677
if (specifier.local.name !== "useContext") {
78+
// add alias to useContextAlias to keep track of it in future call expressions
7779
useContextAlias.add(specifier.local.name);
78-
context.report({
79-
messageId: "noUseContext",
80-
node: specifier,
81-
});
82-
return;
8380
}
8481
context.report({
8582
messageId: "noUseContext",

0 commit comments

Comments
 (0)