Skip to content

Commit

Permalink
feat(no-use-context): enhance auto-fix to support remove aliased … (#933
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Rel1cx authored Jan 29, 2025
1 parent c9d7766 commit 9f8e770
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ ruleTester.run(RULE_NAME, rule, {
{ messageId: "noUseContext" },
],
output: /* tsx */ `
import { use, useContext as useCtx } from 'react'
import { use } from 'react'
export const Component = () => {
const value = use(MyContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,10 @@ export default createRule<[], MessageID>({
if (specifier.type !== T.ImportSpecifier) continue;
if (specifier.imported.type !== T.Identifier) continue;
if (specifier.imported.name === "useContext") {
// import { useContext as useCtx } from 'react'
if (specifier.local.name !== "useContext") {
// add alias to useContextAlias to keep track of it in future call expressions
useContextAlias.add(specifier.local.name);
context.report({
messageId: "noUseContext",
node: specifier,
});
return;
}
context.report({
messageId: "noUseContext",
Expand Down

0 comments on commit 9f8e770

Please sign in to comment.