@@ -46,45 +46,38 @@ describe('package', () => {
46
46
}
47
47
} ) ;
48
48
49
- it ( 'has rules flagged according to their configs' , ( ) => {
50
- if ( ! plugin . configs ) {
51
- expect . fail ( 'No configs found.' ) ;
52
- }
53
-
49
+ it . for ( Object . keys ( plugin . rules ) ) ( 'includes rule %s in configurations based on meta.docs.recommended' , ( ruleName , { expect } ) => {
50
+ const rule = plugin . rules [ ruleName as keyof typeof plugin . rules ] ;
54
51
const namespace = 'rxjs-x' ;
55
- const recommendedRules = plugin . configs . recommended . rules ;
56
- const strictRules = plugin . configs . strict . rules ;
52
+ const fullRuleName = `${ namespace } /${ ruleName } ` ;
57
53
58
- for ( const [ ruleName , rule ] of Object . entries ( plugin . rules ) ) {
59
- const fullRuleName = `${ namespace } /${ ruleName } ` ;
60
- const ruleRec = rule . meta . docs ?. recommended ;
54
+ if ( ! rule . meta . docs ?. recommended ) {
55
+ // Rule is not included in any configuration.
56
+ expect ( plugin . configs . recommended . rules ) . not . toHaveProperty ( fullRuleName ) ;
57
+ expect ( plugin . configs . strict . rules ) . not . toHaveProperty ( fullRuleName ) ;
58
+ } else if ( typeof rule . meta . docs . recommended === 'string' ) {
59
+ // Rule specifies only a configuration name.
60
+ expect ( rule . meta . docs . recommended ) . toMatch ( / ^ ( r e c o m m e n d e d | s t r i c t ) $ / ) ;
61
+ if ( rule . meta . docs . recommended === 'recommended' ) {
62
+ expect ( plugin . configs . recommended . rules ) . toHaveProperty ( fullRuleName ) ;
63
+ } else {
64
+ expect ( plugin . configs . recommended . rules ) . not . toHaveProperty ( fullRuleName ) ;
65
+ }
61
66
62
- if ( ! ruleRec ) {
63
- // Rule is not part of any config.
64
- expect ( recommendedRules ) . not . toHaveProperty ( fullRuleName ) ;
65
- expect ( strictRules ) . not . toHaveProperty ( fullRuleName ) ;
66
- } else if ( typeof ruleRec === 'string' ) {
67
- // Rule is part of a single config.
68
- if ( ruleRec === 'recommended' ) {
69
- expect ( recommendedRules ) . toHaveProperty ( fullRuleName ) ;
70
- } else if ( ruleRec === 'strict' ) {
71
- expect ( strictRules ) . toHaveProperty ( fullRuleName ) ;
72
- expect ( strictRules [ fullRuleName as keyof typeof strictRules ] ) . toBe ( 'error' ) ;
73
- expect ( recommendedRules ) . not . toHaveProperty ( fullRuleName ) ;
74
- } else {
75
- expect . fail ( `Invalid recommended value for rule ${ fullRuleName } : ${ ruleRec } ` ) ;
76
- }
67
+ // Strict configuration always includes all recommended rules.
68
+ expect ( plugin . configs . strict . rules ) . toHaveProperty ( fullRuleName ) ;
69
+ // Not allowed to specify non-default options if rule only specifies a configuration name.
70
+ expect ( typeof plugin . configs . strict . rules [ fullRuleName as keyof typeof plugin . configs . strict . rules ] ) . toBe ( 'string' ) ;
71
+ } else {
72
+ // Rule specifies non-default options for strict.
73
+ if ( rule . meta . docs . recommended . recommended ) {
74
+ expect ( plugin . configs . recommended . rules ) . toHaveProperty ( fullRuleName ) ;
77
75
} else {
78
- // Rule is part of several configs.
79
- if ( ruleRec . recommended ) {
80
- expect ( recommendedRules ) . toHaveProperty ( fullRuleName ) ;
81
- } else {
82
- expect ( recommendedRules ) . not . toHaveProperty ( fullRuleName ) ;
83
- }
84
- expect ( strictRules ) . toHaveProperty ( fullRuleName ) ;
85
- expect ( strictRules [ fullRuleName as keyof typeof strictRules ] ) . toBeInstanceOf ( Array ) ;
86
- expect ( strictRules [ fullRuleName as keyof typeof strictRules ] [ 1 ] ) . toEqual ( ruleRec . strict [ 0 ] ) ;
76
+ expect ( plugin . configs . recommended . rules ) . not . toHaveProperty ( fullRuleName ) ;
87
77
}
78
+ expect ( plugin . configs . strict . rules ) . toHaveProperty ( fullRuleName ) ;
79
+ expect ( plugin . configs . strict . rules [ fullRuleName as keyof typeof plugin . configs . strict . rules ] ) . toBeInstanceOf ( Array ) ;
80
+ expect ( plugin . configs . strict . rules [ fullRuleName as keyof typeof plugin . configs . strict . rules ] [ 1 ] ) . toEqual ( rule . meta . docs . recommended . strict [ 0 ] ) ;
88
81
}
89
82
} ) ;
90
83
} ) ;
0 commit comments