Skip to content

Commit 0767f1e

Browse files
committed
refactor: enhance context name retrieval
1 parent 5b32643 commit 0767f1e

File tree

1 file changed

+8
-2
lines changed
  • packages/plugins/eslint-plugin-react-naming-convention/src/rules

1 file changed

+8
-2
lines changed

packages/plugins/eslint-plugin-react-naming-convention/src/rules/context-name.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import * as AST from "@eslint-react/ast";
21
import { isCreateContextCall } from "@eslint-react/core";
2+
import { _, identity } from "@eslint-react/eff";
33
import type { RuleFeature } from "@eslint-react/shared";
44
import * as VAR from "@eslint-react/var";
5+
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
56
import type { CamelCase } from "string-ts";
7+
import { match, P } from "ts-pattern";
68

79
import { createRule } from "../utils";
810

@@ -33,7 +35,11 @@ export default createRule<[], MessageID>({
3335
if (!isCreateContextCall(context, node)) return;
3436
const id = VAR.getVariableId(node);
3537
if (id == null) return;
36-
const name = context.sourceCode.getText(AST.getEcmaExpression(id));
38+
const name = match(id)
39+
.with({ type: T.Identifier, name: P.select() }, identity)
40+
.with({ type: T.MemberExpression, property: { name: P.select(P.string) } }, identity)
41+
.otherwise(() => _);
42+
if (name == null) return;
3743
if (name.endsWith("Context")) return;
3844
context.report({
3945
messageId: "contextName",

0 commit comments

Comments
 (0)