@@ -18,7 +18,7 @@ import {
18
18
RuleDocTitleFormat ,
19
19
RULE_DOC_TITLE_FORMAT_DEFAULT ,
20
20
} from './rule-doc-title-format.js' ;
21
- import { NOTICE_TYPE } from './types.js' ;
21
+ import { NOTICE_TYPE , SEVERITY_ERROR , SEVERITY_OFF } from './types.js' ;
22
22
23
23
export const NOTICE_TYPE_DEFAULT_PRESENCE_AND_ORDERING : {
24
24
[ key in NOTICE_TYPE ] : boolean ;
@@ -43,46 +43,91 @@ const RULE_NOTICES: {
43
43
| undefined
44
44
| ( ( data : {
45
45
configsEnabled : string [ ] ;
46
+ configsDisabled : string [ ] ;
46
47
configEmojis : ConfigEmojis ;
47
48
urlConfigs ?: string ;
48
49
replacedBy : readonly string [ ] | undefined ;
49
50
type ?: RULE_TYPE ;
50
51
} ) => string ) ;
51
52
} = {
52
53
// Configs notice varies based on whether the rule is enabled in one or more configs.
53
- [ NOTICE_TYPE . CONFIGS ] : ( { configsEnabled, configEmojis, urlConfigs } ) => {
54
+ [ NOTICE_TYPE . CONFIGS ] : ( {
55
+ configsEnabled,
56
+ configsDisabled,
57
+ configEmojis,
58
+ urlConfigs,
59
+ } ) => {
54
60
// Add link to configs documentation if provided.
55
61
const configsLinkOrWord = urlConfigs
56
62
? `[configs](${ urlConfigs } )`
57
63
: 'configs' ;
58
64
const configLinkOrWord = urlConfigs ? `[config](${ urlConfigs } )` : 'config' ;
59
65
60
66
/* istanbul ignore next -- this shouldn't happen */
61
- if ( ! configsEnabled || configsEnabled . length === 0 ) {
67
+ if (
68
+ ( ! configsEnabled || configsEnabled . length === 0 ) &&
69
+ ( ! configsDisabled || configsDisabled . length === 0 )
70
+ ) {
62
71
throw new Error (
63
- 'Should not be trying to display config notice for rule not enabled in any configs.'
72
+ 'Should not be trying to display config notice for rule not enabled/disabled in any configs.'
64
73
) ;
65
74
}
66
75
67
- if ( configsEnabled . length > 1 ) {
68
- // Rule is enabled in multiple configs.
69
- const configs = configsEnabled
70
- . map ( ( configEnabled ) => {
71
- const emoji = configEmojis . find (
72
- ( configEmoji ) => configEmoji . config === configEnabled
73
- ) ?. emoji ;
74
- return `${ emoji ? `${ emoji } ` : '' } \`${ configEnabled } \`` ;
75
- } )
76
- . join ( ', ' ) ;
77
- return `${ EMOJI_CONFIG } This rule is enabled in the following ${ configsLinkOrWord } : ${ configs } .` ;
78
- } else {
79
- // Rule only enabled in one config.
80
- const emoji =
76
+ // If one applicable config with an emoji, use the emoji for that config, otherwise use the general config emoji.
77
+ let emoji = '' ;
78
+ if ( configsEnabled . length + configsDisabled . length > 1 ) {
79
+ emoji = EMOJI_CONFIG ;
80
+ } else if ( configsEnabled . length > 0 ) {
81
+ emoji =
81
82
configEmojis . find (
82
- ( configEmoji ) => configEmoji . config === configsEnabled ?. [ 0 ]
83
+ ( configEmoji ) => configEmoji . config === configsEnabled [ 0 ]
84
+ ) ?. emoji ?? EMOJI_CONFIG ;
85
+ } else if ( configsDisabled . length > 0 ) {
86
+ emoji =
87
+ configEmojis . find (
88
+ ( configEmoji ) => configEmoji . config === configsDisabled [ 0 ]
83
89
) ?. emoji ?? EMOJI_CONFIG ;
84
- return `${ emoji } This rule is enabled in the \`${ configsEnabled ?. [ 0 ] } \` ${ configLinkOrWord } .` ;
85
90
}
91
+
92
+ // List of configs that enable the rule.
93
+ const configsEnabledCSV = configsEnabled
94
+ . map ( ( configEnabled ) => {
95
+ const emoji = configEmojis . find (
96
+ ( configEmoji ) => configEmoji . config === configEnabled
97
+ ) ?. emoji ;
98
+ return `${ emoji ? `${ emoji } ` : '' } \`${ configEnabled } \`` ;
99
+ } )
100
+ . join ( ', ' ) ;
101
+
102
+ // List of configs that disable the rule.
103
+ const configsDisabledCSV = configsDisabled
104
+ . map ( ( configDisabled ) => {
105
+ const emoji = configEmojis . find (
106
+ ( configEmoji ) => configEmoji . config === configDisabled
107
+ ) ?. emoji ;
108
+ return `${ emoji ? `${ emoji } ` : '' } \`${ configDisabled } \`` ;
109
+ } )
110
+ . join ( ', ' ) ;
111
+
112
+ // Complete sentence for configs that enable the rule.
113
+ const SENTENCE_ENABLED =
114
+ configsEnabled . length > 1
115
+ ? `This rule is enabled in the following ${ configsLinkOrWord } : ${ configsEnabledCSV } .`
116
+ : configsEnabled . length === 1
117
+ ? `This rule is enabled in the \`${ configsEnabled ?. [ 0 ] } \` ${ configLinkOrWord } .`
118
+ : '' ;
119
+
120
+ // Complete sentence for configs that disable the rule.
121
+ const SENTENCE_DISABLED =
122
+ configsDisabled . length > 1
123
+ ? `This rule is disabled in the following ${ configsLinkOrWord } : ${ configsDisabledCSV } .`
124
+ : configsDisabled . length === 1
125
+ ? `This rule is disabled in the \`${ configsDisabled ?. [ 0 ] } \` ${ configLinkOrWord } .`
126
+ : '' ;
127
+
128
+ return `${ emoji } ${ SENTENCE_ENABLED } ${
129
+ SENTENCE_ENABLED && SENTENCE_DISABLED ? ' ' : '' // Space if two sentences.
130
+ } ${ SENTENCE_DISABLED } `;
86
131
} ,
87
132
88
133
// Deprecated notice has optional "replaced by" rules list.
@@ -125,13 +170,15 @@ function ruleNamesToList(ruleNames: readonly string[]) {
125
170
function getNoticesForRule (
126
171
rule : RuleModule ,
127
172
configsEnabled : string [ ] ,
173
+ configsDisabled : string [ ] ,
128
174
ruleDocNotices : NOTICE_TYPE [ ]
129
175
) {
130
176
const notices : {
131
177
[ key in NOTICE_TYPE ] : boolean ;
132
178
} = {
133
179
// Alphabetical order.
134
- [ NOTICE_TYPE . CONFIGS ] : configsEnabled . length > 0 ,
180
+ [ NOTICE_TYPE . CONFIGS ] :
181
+ configsEnabled . length > 0 || configsDisabled . length > 0 ,
135
182
[ NOTICE_TYPE . DEPRECATED ] : rule . meta . deprecated || false ,
136
183
137
184
// FIXABLE_AND_HAS_SUGGESTIONS potentially replaces FIXABLE and HAS_SUGGESTIONS.
@@ -188,9 +235,23 @@ function getRuleNoticeLines(
188
235
const configsEnabled = getConfigsForRule (
189
236
ruleName ,
190
237
configsToRules ,
191
- pluginPrefix
192
- ) . filter ( ( config ) => ! ignoreConfig ?. includes ( config ) ) ;
193
- const notices = getNoticesForRule ( rule , configsEnabled , ruleDocNotices ) ;
238
+ pluginPrefix ,
239
+ SEVERITY_ERROR
240
+ ) . filter ( ( configName ) => ! ignoreConfig ?. includes ( configName ) ) ;
241
+
242
+ const configsDisabled = getConfigsForRule (
243
+ ruleName ,
244
+ configsToRules ,
245
+ pluginPrefix ,
246
+ SEVERITY_OFF
247
+ ) . filter ( ( configName ) => ! ignoreConfig ?. includes ( configName ) ) ;
248
+
249
+ const notices = getNoticesForRule (
250
+ rule ,
251
+ configsEnabled ,
252
+ configsDisabled ,
253
+ ruleDocNotices
254
+ ) ;
194
255
let noticeType : keyof typeof notices ;
195
256
196
257
for ( noticeType in notices ) {
@@ -215,6 +276,7 @@ function getRuleNoticeLines(
215
276
typeof ruleNoticeStrOrFn === 'function'
216
277
? ruleNoticeStrOrFn ( {
217
278
configsEnabled,
279
+ configsDisabled,
218
280
configEmojis,
219
281
urlConfigs,
220
282
replacedBy : rule . meta . replacedBy ,
0 commit comments