@@ -38,6 +38,51 @@ export const NOTICE_TYPE_DEFAULT_PRESENCE_AND_ORDERING: {
38
38
[ NOTICE_TYPE . TYPE ] : false ,
39
39
} ;
40
40
41
+ function severityToTerminology ( severity : SEVERITY_TYPE ) {
42
+ switch ( severity ) {
43
+ case SEVERITY_TYPE . error :
44
+ return 'is enabled' ;
45
+ case SEVERITY_TYPE . warn :
46
+ return '_warns_' ;
47
+ case SEVERITY_TYPE . off :
48
+ return 'is _disabled_' ;
49
+ /* istanbul ignore next -- this shouldn't happen */
50
+ default :
51
+ throw new Error ( `Unknown severity: ${ severity } ` ) ;
52
+ }
53
+ }
54
+
55
+ function configsToNoticeSentence (
56
+ configs : string [ ] ,
57
+ severity : SEVERITY_TYPE ,
58
+ configsLinkOrWord : string ,
59
+ configLinkOrWord : string ,
60
+ configEmojis : ConfigEmojis ,
61
+ useGenericConfigEmoji : boolean
62
+ ) : string | undefined {
63
+ // Create CSV list of configs with their emojis.
64
+ const csv = configs
65
+ . map ( ( config ) => {
66
+ const emoji = findConfigEmoji ( configEmojis , config ) ;
67
+ return `${ emoji ? `${ emoji } ` : '' } \`${ config } \`` ;
68
+ } )
69
+ . join ( ', ' ) ;
70
+
71
+ const term = severityToTerminology ( severity ) ;
72
+ const sentence =
73
+ configs . length > 1
74
+ ? `This rule ${ term } in the following ${ configsLinkOrWord } : ${ csv } .`
75
+ : configs . length === 1
76
+ ? `This rule ${ term } in the ${
77
+ // If the config's emoji isn't already being used at the front of the notice, include it here by using the CSV.
78
+ // If the config's emoji IS already being used, just use the config name only here.
79
+ useGenericConfigEmoji ? csv : `\`${ configs ?. [ 0 ] } \``
80
+ } ${ configLinkOrWord } .`
81
+ : undefined ;
82
+
83
+ return sentence ;
84
+ }
85
+
41
86
/**
42
87
* An object containing the text for each notice type (as a string or function to generate the string).
43
88
*/
@@ -82,10 +127,9 @@ const RULE_NOTICES: {
82
127
83
128
// If one applicable config with an emoji, use the emoji for that config, otherwise use the general config emoji.
84
129
let emoji = '' ;
85
- if (
86
- configsEnabled . length + configsWarn . length + configsDisabled . length >
87
- 1
88
- ) {
130
+ const useGenericConfigEmoji =
131
+ configsEnabled . length + configsWarn . length + configsDisabled . length > 1 ;
132
+ if ( useGenericConfigEmoji ) {
89
133
emoji = EMOJI_CONFIG ;
90
134
} else if ( configsEnabled . length > 0 ) {
91
135
// @ts -expect-error -- will always be a string thanks to fallback
@@ -107,63 +151,36 @@ const RULE_NOTICES: {
107
151
} ) ;
108
152
}
109
153
110
- // List of configs that enable the rule.
111
- const configsEnabledCSV = configsEnabled
112
- . map ( ( configEnabled ) => {
113
- const emoji = configEmojis . find (
114
- ( configEmoji ) => configEmoji . config === configEnabled
115
- ) ?. emoji ;
116
- return `${ emoji ? `${ emoji } ` : '' } \`${ configEnabled } \`` ;
117
- } )
118
- . join ( ', ' ) ;
119
-
120
- // List of configs that warn for the rule.
121
- const configsWarnCSV = configsWarn
122
- . map ( ( configWarn ) => {
123
- const emoji = configEmojis . find (
124
- ( configEmoji ) => configEmoji . config === configWarn
125
- ) ?. emoji ;
126
- return `${ emoji ? `${ emoji } ` : '' } \`${ configWarn } \`` ;
127
- } )
128
- . join ( ', ' ) ;
129
-
130
- // List of configs that disable the rule.
131
- const configsDisabledCSV = configsDisabled
132
- . map ( ( configDisabled ) => {
133
- const emoji = configEmojis . find (
134
- ( configEmoji ) => configEmoji . config === configDisabled
135
- ) ?. emoji ;
136
- return `${ emoji ? `${ emoji } ` : '' } \`${ configDisabled } \`` ;
137
- } )
138
- . join ( ', ' ) ;
139
-
140
- // Complete sentence for configs that enable the rule.
141
- const SENTENCE_ENABLED =
142
- configsEnabled . length > 1
143
- ? `This rule is enabled in the following ${ configsLinkOrWord } : ${ configsEnabledCSV } .`
144
- : configsEnabled . length === 1
145
- ? `This rule is enabled in the \`${ configsEnabled ?. [ 0 ] } \` ${ configLinkOrWord } .`
146
- : undefined ;
147
-
148
- // Complete sentence for configs that warn for the rule.
149
- const SENTENCE_WARN =
150
- configsWarn . length > 1
151
- ? `This rule _warns_ in the following ${ configsLinkOrWord } : ${ configsWarnCSV } .`
152
- : configsWarn . length === 1
153
- ? `This rule _warns_ in the \`${ configsWarn ?. [ 0 ] } \` ${ configLinkOrWord } .`
154
- : undefined ;
155
-
156
- // Complete sentence for configs that disable the rule.
157
- const SENTENCE_DISABLED =
158
- configsDisabled . length > 1
159
- ? `This rule is _disabled_ in the following ${ configsLinkOrWord } : ${ configsDisabledCSV } .`
160
- : configsDisabled . length === 1
161
- ? `This rule is _disabled_ in the \`${ configsDisabled ?. [ 0 ] } \` ${ configLinkOrWord } .`
162
- : undefined ;
163
-
164
- return `${ emoji } ${ [ SENTENCE_ENABLED , SENTENCE_WARN , SENTENCE_DISABLED ]
165
- . filter ( ( sentence ) => sentence !== undefined )
166
- . join ( ' ' ) } `;
154
+ const sentences = [
155
+ configsToNoticeSentence (
156
+ configsEnabled ,
157
+ SEVERITY_TYPE . error ,
158
+ configsLinkOrWord ,
159
+ configLinkOrWord ,
160
+ configEmojis ,
161
+ useGenericConfigEmoji
162
+ ) ,
163
+ configsToNoticeSentence (
164
+ configsWarn ,
165
+ SEVERITY_TYPE . warn ,
166
+ configsLinkOrWord ,
167
+ configLinkOrWord ,
168
+ configEmojis ,
169
+ useGenericConfigEmoji
170
+ ) ,
171
+ configsToNoticeSentence (
172
+ configsDisabled ,
173
+ SEVERITY_TYPE . off ,
174
+ configsLinkOrWord ,
175
+ configLinkOrWord ,
176
+ configEmojis ,
177
+ useGenericConfigEmoji
178
+ ) ,
179
+ ]
180
+ . filter ( Boolean )
181
+ . join ( ' ' ) ;
182
+
183
+ return `${ emoji } ${ sentences } ` ;
167
184
} ,
168
185
169
186
// Deprecated notice has optional "replaced by" rules list.
0 commit comments