@@ -78,9 +78,9 @@ type Options = (
78
78
| Selector < 'parameter' >
79
79
| Selector < 'property' >
80
80
| Selector < 'parameterProperty' >
81
- | Selector < 'enumMember' >
82
81
| Selector < 'method' >
83
82
| Selector < 'accessor' >
83
+ | Selector < 'enumMember' >
84
84
| Selector < 'class' >
85
85
| Selector < 'interface' >
86
86
| Selector < 'typeAlias' >
@@ -203,7 +203,6 @@ const SCHEMA: JSONSchema.JSONSchema4 = {
203
203
'public' ,
204
204
'readonly' ,
205
205
] ) ,
206
- ...selectorSchema ( 'enumMember' , false ) ,
207
206
...selectorSchema ( 'method' , false , [
208
207
'private' ,
209
208
'protected' ,
@@ -218,6 +217,7 @@ const SCHEMA: JSONSchema.JSONSchema4 = {
218
217
'static' ,
219
218
'abstract' ,
220
219
] ) ,
220
+ ...selectorSchema ( 'enumMember' , false ) ,
221
221
...selectorSchema ( 'class' , false , [ 'abstract' ] ) ,
222
222
...selectorSchema ( 'interface' , false ) ,
223
223
...selectorSchema ( 'typeAlias' , false ) ,
@@ -270,15 +270,40 @@ export default util.createRule<Options, MessageIds>({
270
270
271
271
const key = node . key ;
272
272
/* istanbul ignore if */ if ( ! util . isLiteralOrIdentifier ( key ) ) {
273
- // shouldn't happen due to selector
273
+ // shouldn't happen due to the selectors that are used
274
+ return ;
275
+ }
276
+
277
+ validator ( key , modifiers ) ;
278
+ }
279
+
280
+ function handleMethod (
281
+ node :
282
+ | TSESTree . Property
283
+ | TSESTree . ClassProperty
284
+ | TSESTree . TSAbstractClassProperty
285
+ | TSESTree . MethodDefinition
286
+ | TSESTree . TSAbstractMethodDefinition
287
+ | TSESTree . TSMethodSignature ,
288
+ modifiers : Set < Modifiers > ,
289
+ ) : void {
290
+ const validator = validators . method ;
291
+ if ( ! validator ) {
292
+ return ;
293
+ }
294
+
295
+ const key = node . key ;
296
+ /* istanbul ignore if */ if ( ! util . isLiteralOrIdentifier ( key ) ) {
297
+ // shouldn't happen due to the selectors that are used
274
298
return ;
275
299
}
276
300
277
301
validator ( key , modifiers ) ;
278
302
}
279
303
280
304
return {
281
- // variable
305
+ // #region variable
306
+
282
307
VariableDeclarator ( node : TSESTree . VariableDeclarator ) : void {
283
308
const validator = validators . variable ;
284
309
if ( ! validator ) {
@@ -293,7 +318,10 @@ export default util.createRule<Options, MessageIds>({
293
318
} ) ;
294
319
} ,
295
320
296
- // function
321
+ // #endregion
322
+
323
+ // #region function
324
+
297
325
'FunctionDeclaration, TSDeclareFunction, FunctionExpression' (
298
326
node :
299
327
| TSESTree . FunctionDeclaration
@@ -308,7 +336,10 @@ export default util.createRule<Options, MessageIds>({
308
336
validator ( node . id ) ;
309
337
} ,
310
338
311
- // parameter
339
+ // #endregion function
340
+
341
+ // #region parameter
342
+
312
343
'FunctionDeclaration, TSDeclareFunction, FunctionExpression, ArrowFunctionExpression' (
313
344
node :
314
345
| TSESTree . FunctionDeclaration
@@ -334,7 +365,10 @@ export default util.createRule<Options, MessageIds>({
334
365
} ) ;
335
366
} ,
336
367
337
- // parameterProperty
368
+ // #endregion parameter
369
+
370
+ // #region parameterProperty
371
+
338
372
TSParameterProperty ( node ) : void {
339
373
const validator = validators . parameterProperty ;
340
374
if ( ! validator ) {
@@ -359,19 +393,28 @@ export default util.createRule<Options, MessageIds>({
359
393
} ) ;
360
394
} ,
361
395
362
- // property
363
- 'Property[computed = false][method = false][kind = "init"][value.type != "ArrowFunctionExpression"][value.type != "FunctionExpression"]' (
396
+ // #endregion parameterProperty
397
+
398
+ // #region property
399
+
400
+ 'Property[computed = false][kind = "init"][value.type != "ArrowFunctionExpression"][value.type != "FunctionExpression"][value.type != "TSEmptyBodyFunctionExpression"]' (
364
401
node : TSESTree . Property ,
365
402
) : void {
366
403
const modifiers = new Set < Modifiers > ( [ 'public' ] ) ;
367
404
handleProperty ( node , modifiers ) ;
368
405
} ,
369
- 'ClassProperty[computed = false], TSAbstractClassProperty[computed = false]' (
406
+
407
+ [ [
408
+ 'ClassProperty[computed = false][value.type != "ArrowFunctionExpression"][value.type != "FunctionExpression"][value.type != "TSEmptyBodyFunctionExpression"]' ,
409
+ 'TSAbstractClassProperty[computed = false][value.type != "ArrowFunctionExpression"][value.type != "FunctionExpression"][value.type != "TSEmptyBodyFunctionExpression"]' ,
410
+ ] . join ( ', ' ) ] (
370
411
node : TSESTree . ClassProperty | TSESTree . TSAbstractClassProperty ,
371
412
) : void {
372
413
const modifiers = new Set < Modifiers > ( ) ;
373
414
if ( node . accessibility ) {
374
415
modifiers . add ( node . accessibility ) ;
416
+ } else {
417
+ modifiers . add ( 'public' ) ;
375
418
}
376
419
if ( node . readonly ) {
377
420
modifiers . add ( 'readonly' ) ;
@@ -385,16 +428,70 @@ export default util.createRule<Options, MessageIds>({
385
428
386
429
handleProperty ( node , modifiers ) ;
387
430
} ,
431
+
388
432
'TSPropertySignature[computed = false]' (
389
433
node : TSESTree . TSPropertySignature ,
390
434
) : void {
391
- const modifiers = new Set < Modifiers > ( ) ;
435
+ const modifiers = new Set < Modifiers > ( [ 'public' ] ) ;
392
436
if ( node . readonly ) {
393
437
modifiers . add ( 'readonly' ) ;
394
438
}
395
439
396
440
handleProperty ( node , modifiers ) ;
397
441
} ,
442
+
443
+ // #endregion property
444
+
445
+ // #region method
446
+
447
+ [ [
448
+ 'Property[computed = false][kind = "init"][value.type = "ArrowFunctionExpression"]' ,
449
+ 'Property[computed = false][kind = "init"][value.type = "FunctionExpression"]' ,
450
+ 'Property[computed = false][kind = "init"][value.type = "TSEmptyBodyFunctionExpression"]' ,
451
+ 'TSMethodSignature[computed = false]' ,
452
+ ] . join ( ', ' ) ] (
453
+ node : TSESTree . Property | TSESTree . TSMethodSignature ,
454
+ ) : void {
455
+ const modifiers = new Set < Modifiers > ( [ 'public' ] ) ;
456
+ handleMethod ( node , modifiers ) ;
457
+ } ,
458
+
459
+ [ [
460
+ 'ClassProperty[computed = false][value.type = "ArrowFunctionExpression"]' ,
461
+ 'ClassProperty[computed = false][value.type = "FunctionExpression"]' ,
462
+ 'ClassProperty[computed = false][value.type = "TSEmptyBodyFunctionExpression"]' ,
463
+ 'TSAbstractClassProperty[computed = false][value.type = "ArrowFunctionExpression"]' ,
464
+ 'TSAbstractClassProperty[computed = false][value.type = "FunctionExpression"]' ,
465
+ 'TSAbstractClassProperty[computed = false][value.type = "TSEmptyBodyFunctionExpression"]' ,
466
+ 'MethodDefinition[computed = false][kind = "method"]' ,
467
+ 'TSAbstractMethodDefinition[computed = false][kind = "method"]' ,
468
+ ] . join ( ', ' ) ] (
469
+ node :
470
+ | TSESTree . ClassProperty
471
+ | TSESTree . TSAbstractClassProperty
472
+ | TSESTree . MethodDefinition
473
+ | TSESTree . TSAbstractMethodDefinition ,
474
+ ) : void {
475
+ const modifiers = new Set < Modifiers > ( ) ;
476
+ if ( node . accessibility ) {
477
+ modifiers . add ( node . accessibility ) ;
478
+ } else {
479
+ modifiers . add ( 'public' ) ;
480
+ }
481
+ if ( node . static ) {
482
+ modifiers . add ( 'static' ) ;
483
+ }
484
+ if (
485
+ node . type === AST_NODE_TYPES . TSAbstractClassProperty ||
486
+ node . type === AST_NODE_TYPES . TSAbstractMethodDefinition
487
+ ) {
488
+ modifiers . add ( 'abstract' ) ;
489
+ }
490
+
491
+ handleMethod ( node , modifiers ) ;
492
+ } ,
493
+
494
+ // #endregion method
398
495
} ;
399
496
} ,
400
497
} ) ;
0 commit comments