1- use std:: borrow:: Cow ;
1+ use std:: { borrow:: Cow , ops :: Deref } ;
22
33use itertools:: Itertools ;
44use oxc_ast:: {
@@ -42,6 +42,14 @@ impl Default for ClassMethodsUseThisConfig {
4242#[ derive( Debug , Clone , Default ) ]
4343pub struct ClassMethodsUseThis ( Box < ClassMethodsUseThisConfig > ) ;
4444
45+ impl Deref for ClassMethodsUseThis {
46+ type Target = ClassMethodsUseThisConfig ;
47+
48+ fn deref ( & self ) -> & Self :: Target {
49+ & self . 0
50+ }
51+ }
52+
4553#[ derive( Debug , Clone ) ]
4654struct MethodException {
4755 name : CompactStr ,
@@ -136,12 +144,11 @@ impl Rule for ClassMethodsUseThis {
136144 }
137145
138146 fn run < ' a > ( & self , node : & AstNode < ' a > , ctx : & LintContext < ' a > ) {
139- let config = & self . 0 ;
140147 let function_pair = match node. kind ( ) {
141148 AstKind :: AccessorProperty ( accessor) => {
142149 if accessor. r#static
143- || !config . enforce_for_class_fields
144- || ( config . ignore_override_methods && accessor. r#override )
150+ || !self . enforce_for_class_fields
151+ || ( self . ignore_override_methods && accessor. r#override )
145152 || self . check_ignore_classes_with_implements (
146153 node,
147154 ctx,
@@ -164,7 +171,7 @@ impl Rule for ClassMethodsUseThis {
164171 AstKind :: MethodDefinition ( method_definition) => {
165172 if method_definition. r#static
166173 || method_definition. kind . is_constructor ( )
167- || ( config . ignore_override_methods && method_definition. r#override )
174+ || ( self . ignore_override_methods && method_definition. r#override )
168175 || self . check_ignore_classes_with_implements (
169176 node,
170177 ctx,
@@ -179,8 +186,8 @@ impl Rule for ClassMethodsUseThis {
179186 }
180187 AstKind :: PropertyDefinition ( property_definition) => {
181188 if property_definition. r#static
182- || !config . enforce_for_class_fields
183- || ( config . ignore_override_methods && property_definition. r#override )
189+ || !self . enforce_for_class_fields
190+ || ( self . ignore_override_methods && property_definition. r#override )
184191 || self . check_ignore_classes_with_implements (
185192 node,
186193 ctx,
@@ -200,11 +207,11 @@ impl Rule for ClassMethodsUseThis {
200207 _ => None ,
201208 } )
202209 }
203- _ => None ,
210+ _ => return ,
204211 } ;
205212 let Some ( ( function_body, name) ) = function_pair else { return } ;
206213 if let Some ( name_str) = name. name ( )
207- && config . except_methods . iter ( ) . any ( |method| {
214+ && self . except_methods . iter ( ) . any ( |method| {
208215 method. name == name_str && method. private == name. is_private_identifier ( )
209216 } )
210217 {
0 commit comments