@@ -107,6 +107,34 @@ function createRulesMeta(rules) {
107107 } , { } ) ;
108108}
109109
110+ /**
111+ * Gets the replacement rule names from a deprecated rule's metadata.
112+ * @param {RulesMeta } meta The rule metadata.
113+ * @returns {string[] } Replacement rule names.
114+ */
115+ function getDeprecatedRuleReplacements ( meta ) {
116+ if ( typeof meta . deprecated !== "object" ) {
117+ return meta . replacedBy || [ ] ;
118+ }
119+
120+ const { replacedBy } = meta . deprecated ;
121+
122+ if ( ! Array . isArray ( replacedBy ) ) {
123+ return [ ] ;
124+ }
125+
126+ return replacedBy . map ( replacement => {
127+ if ( typeof replacement !== "object" || replacement === null ) {
128+ return "" ;
129+ }
130+
131+ const pluginName = replacement . plugin ?. name ;
132+ const ruleName = replacement . rule ?. name ;
133+
134+ return `${ typeof pluginName === "string" ? `${ getShorthandName ( pluginName , "eslint-plugin" ) } /` : "" } ${ typeof ruleName === "string" ? ruleName : "" } ` ;
135+ } ) ;
136+ }
137+
110138/** @type {WeakMap<CalculatedConfig, DeprecatedRuleInfo[]> } */
111139const usedDeprecatedRulesCache = new WeakMap ( ) ;
112140
@@ -144,12 +172,7 @@ function getOrFindUsedDeprecatedRules(eslint, maybeFilePath) {
144172
145173 retv . push ( {
146174 ruleId,
147- replacedBy : usesNewFormat
148- ? ( meta . deprecated . replacedBy ?. map (
149- replacement =>
150- `${ replacement . plugin ?. name !== void 0 ? `${ getShorthandName ( replacement . plugin . name , "eslint-plugin" ) } /` : "" } ${ replacement . rule ?. name ?? "" } ` ,
151- ) ?? [ ] )
152- : meta . replacedBy || [ ] ,
175+ replacedBy : getDeprecatedRuleReplacements ( meta ) ,
153176 info : usesNewFormat ? meta . deprecated : void 0 ,
154177 } ) ;
155178 }
0 commit comments