@@ -269,43 +269,47 @@ fn get_function_name_with_kind<'a>(func: &Function<'a>, parent_node: &AstNode<'a
269
269
270
270
match parent_node. kind ( ) {
271
271
AstKind :: MethodDefinition ( definition) => {
272
- if definition. r#static {
273
- tokens. push ( "static" . into ( ) ) ;
272
+ if !definition. computed && definition. key . is_private_identifier ( ) {
273
+ tokens. push ( Cow :: Borrowed ( "private" ) ) ;
274
+ } else if let Some ( accessibility) = definition. accessibility {
275
+ tokens. push ( Cow :: Borrowed ( accessibility. as_str ( ) ) ) ;
274
276
}
275
277
276
- if ! definition. computed && definition . key . is_private_identifier ( ) {
277
- tokens. push ( "private" . into ( ) ) ;
278
+ if definition. r#static {
279
+ tokens. push ( Cow :: Borrowed ( "static" ) ) ;
278
280
}
279
281
}
280
282
AstKind :: PropertyDefinition ( definition) => {
281
- if definition. r#static {
282
- tokens. push ( "static" . into ( ) ) ;
283
+ if !definition. computed && definition. key . is_private_identifier ( ) {
284
+ tokens. push ( Cow :: Borrowed ( "private" ) ) ;
285
+ } else if let Some ( accessibility) = definition. accessibility {
286
+ tokens. push ( Cow :: Borrowed ( accessibility. as_str ( ) ) ) ;
283
287
}
284
288
285
- if ! definition. computed && definition . key . is_private_identifier ( ) {
286
- tokens. push ( "private" . into ( ) ) ;
289
+ if definition. r#static {
290
+ tokens. push ( Cow :: Borrowed ( "static" ) ) ;
287
291
}
288
292
}
289
293
_ => { }
290
294
}
291
295
292
296
if func. r#async {
293
- tokens. push ( "async" . into ( ) ) ;
297
+ tokens. push ( Cow :: Borrowed ( "async" ) ) ;
294
298
}
295
299
296
300
if func. generator {
297
- tokens. push ( "generator" . into ( ) ) ;
301
+ tokens. push ( Cow :: Borrowed ( "generator" ) ) ;
298
302
}
299
303
300
304
match parent_node. kind ( ) {
301
305
AstKind :: MethodDefinition ( method_definition) => match method_definition. kind {
302
- MethodDefinitionKind :: Constructor => tokens. push ( "constructor" . into ( ) ) ,
303
- MethodDefinitionKind :: Get => tokens. push ( "getter" . into ( ) ) ,
304
- MethodDefinitionKind :: Set => tokens. push ( "setter" . into ( ) ) ,
305
- MethodDefinitionKind :: Method => tokens. push ( "method" . into ( ) ) ,
306
+ MethodDefinitionKind :: Constructor => tokens. push ( Cow :: Borrowed ( "constructor" ) ) ,
307
+ MethodDefinitionKind :: Get => tokens. push ( Cow :: Borrowed ( "getter" ) ) ,
308
+ MethodDefinitionKind :: Set => tokens. push ( Cow :: Borrowed ( "setter" ) ) ,
309
+ MethodDefinitionKind :: Method => tokens. push ( Cow :: Borrowed ( "method" ) ) ,
306
310
} ,
307
- AstKind :: PropertyDefinition ( _) => tokens. push ( "method" . into ( ) ) ,
308
- _ => tokens. push ( "function" . into ( ) ) ,
311
+ AstKind :: PropertyDefinition ( _) => tokens. push ( Cow :: Borrowed ( "method" ) ) ,
312
+ _ => tokens. push ( Cow :: Borrowed ( "function" ) ) ,
309
313
}
310
314
311
315
match parent_node. kind ( ) {
@@ -342,10 +346,7 @@ fn get_function_name_with_kind<'a>(func: &Function<'a>, parent_node: &AstNode<'a
342
346
impl Rule for FuncNames {
343
347
fn from_configuration ( value : serde_json:: Value ) -> Self {
344
348
let Some ( default_value) = value. get ( 0 ) else {
345
- return Self {
346
- default_config : FuncNamesConfig :: default ( ) ,
347
- generators_config : FuncNamesConfig :: default ( ) ,
348
- } ;
349
+ return Self :: default ( ) ;
349
350
} ;
350
351
351
352
let default_config = FuncNamesConfig :: try_from ( default_value) . unwrap ( ) ;
@@ -639,6 +640,7 @@ fn test() {
639
640
Some ( serde_json:: json!( [ "as-needed" , { "generators" : "never" } ] ) ) ,
640
641
) , // { "ecmaVersion": 6 },
641
642
( "class C { foo = function() {} }" , Some ( serde_json:: json!( [ "always" ] ) ) ) , // { "ecmaVersion": 2022 },
643
+ ( "class C { public foo = function() {} }" , Some ( serde_json:: json!( [ "always" ] ) ) ) , // { "ecmaVersion": 2022 },
642
644
( "class C { [foo] = function() {} }" , Some ( serde_json:: json!( [ "always" ] ) ) ) , // { "ecmaVersion": 2022 },
643
645
( "class C { #foo = function() {} }" , Some ( serde_json:: json!( [ "always" ] ) ) ) , // { "ecmaVersion": 2022 },
644
646
( "class C { foo = bar(function() {}) }" , Some ( serde_json:: json!( [ "as-needed" ] ) ) ) , // { "ecmaVersion": 2022 },
0 commit comments