11import * as AST from "@eslint-react/ast" ;
22import { isClassComponent } from "@eslint-react/core" ;
3- import { _ , constFalse , constTrue } from "@eslint-react/eff" ;
3+ import { constFalse , constTrue } from "@eslint-react/eff" ;
44import type { RuleFeature } from "@eslint-react/shared" ;
55import { AST_NODE_TYPES as T } from "@typescript-eslint/types" ;
66import type { TSESTree } from "@typescript-eslint/utils" ;
@@ -54,26 +54,6 @@ function isKeyLiteral(
5454 . otherwise ( constFalse ) ;
5555}
5656
57- // Return the name of an identifier or the string value of a literal. Useful
58- // anywhere that a literal may be used as a key (e.g., member expressions,
59- // method definitions, ObjectExpression property keys).
60- function getName ( node : TSESTree . Expression | TSESTree . PrivateIdentifier ) : string | _ {
61- if ( AST . isTypeExpression ( node ) ) {
62- return getName ( node . expression ) ;
63- }
64- if ( node . type === T . Identifier || node . type === T . PrivateIdentifier ) {
65- return node . name ;
66- }
67- if ( node . type === T . Literal ) {
68- return node . value ?. toString ( ) ;
69- }
70- if ( node . type === T . TemplateLiteral && node . expressions . length === 0 ) {
71- return node . quasis [ 0 ] ?. value . raw ;
72- }
73-
74- return _ ;
75- }
76-
7757export default createRule < [ ] , MessageID > ( {
7858 meta : {
7959 type : "problem" ,
@@ -112,7 +92,7 @@ export default createRule<[], MessageID>({
11292 return ;
11393 }
11494 for ( const def of defs ) {
115- const methodName = getName ( def ) ;
95+ const methodName = AST . getPropertyName ( def ) ;
11696 if ( methodName == null ) {
11797 continue ;
11898 }
@@ -170,7 +150,7 @@ export default createRule<[], MessageID>({
170150 return ;
171151 }
172152 // detect `this.property()`, `x = this.property`, etc.
173- const propertyName = getName ( node . property ) ;
153+ const propertyName = AST . getPropertyName ( node . property ) ;
174154 if ( propertyName != null ) {
175155 propertyUsages . get ( currentClass ) ?. add ( propertyName ) ;
176156 }
@@ -192,7 +172,7 @@ export default createRule<[], MessageID>({
192172 if ( node . init != null && AST . isThisExpression ( node . init ) && node . id . type === T . ObjectPattern ) {
193173 for ( const prop of node . id . properties ) {
194174 if ( prop . type === T . Property && isKeyLiteral ( prop , prop . key ) ) {
195- const keyName = getName ( prop . key ) ;
175+ const keyName = AST . getPropertyName ( prop . key ) ;
196176 if ( keyName != null ) {
197177 propertyUsages . get ( currentClass ) ?. add ( keyName ) ;
198178 }
0 commit comments