Skip to content

Commit 4964322

Browse files
authored
feat: Update RuleDefinition for frozen and deprecations (#149)
1 parent c91866c commit 4964322

File tree

2 files changed

+103
-3
lines changed

2 files changed

+103
-3
lines changed

packages/core/src/types.ts

+85-3
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ export interface RulesMetaDocs {
129129
* Indicates if the rule is generally recommended for all users.
130130
*/
131131
recommended?: boolean | undefined;
132+
133+
/**
134+
* Indicates if the rule is frozen (no longer accepting feature requests).
135+
*/
136+
frozen?: boolean | undefined;
132137
}
133138

134139
/**
@@ -159,12 +164,13 @@ export interface RulesMeta<
159164
messages?: Record<MessageIds, string>;
160165

161166
/**
162-
* The deprecated rules for the rule.
167+
* Indicates whether the rule has been deprecated or provides additional metadata about the deprecation. Omit if not deprecated.
163168
*/
164-
deprecated?: boolean | undefined;
169+
deprecated?: boolean | DeprecatedInfo | undefined;
165170

166171
/**
167-
* When a rule is deprecated, indicates the rule ID(s) that should be used instead.
172+
* @deprecated Use deprecated.replacedBy instead.
173+
* The name of the rule(s) this rule was replaced by, if it was deprecated.
168174
*/
169175
replacedBy?: readonly string[] | undefined;
170176

@@ -179,6 +185,82 @@ export interface RulesMeta<
179185
hasSuggestions?: boolean | undefined;
180186
}
181187

188+
/**
189+
* Provides additional metadata about a deprecation.
190+
*/
191+
export interface DeprecatedInfo {
192+
/**
193+
* General message presented to the user, e.g. for the key rule why the rule
194+
* is deprecated or for info how to replace the rule.
195+
*/
196+
message?: string;
197+
198+
/**
199+
* URL to more information about this deprecation in general.
200+
*/
201+
url?: string;
202+
203+
/**
204+
* An empty array explicitly states that there is no replacement.
205+
*/
206+
replacedBy?: ReplacedByInfo[];
207+
208+
/**
209+
* The package version since when the rule is deprecated (should use full
210+
* semver without a leading "v").
211+
*/
212+
deprecatedSince?: string;
213+
214+
/**
215+
* The estimated version when the rule is removed (probably the next major
216+
* version). null means the rule is "frozen" (will be available but will not
217+
* be changed).
218+
*/
219+
availableUntil?: string | null;
220+
}
221+
222+
/**
223+
* Provides metadata about a replacement
224+
*/
225+
export interface ReplacedByInfo {
226+
/**
227+
* General message presented to the user, e.g. how to replace the rule
228+
*/
229+
message?: string;
230+
231+
/**
232+
* URL to more information about this replacement in general
233+
*/
234+
url?: string;
235+
236+
/**
237+
* Name should be "eslint" if the replacement is an ESLint core rule. Omit
238+
* the property if the replacement is in the same plugin.
239+
*/
240+
plugin?: ExternalSpecifier;
241+
242+
/**
243+
* Name and documentation of the replacement rule
244+
*/
245+
rule?: ExternalSpecifier;
246+
}
247+
248+
/**
249+
* Specifies the name and url of an external resource. At least one property
250+
* should be set.
251+
*/
252+
export interface ExternalSpecifier {
253+
/**
254+
* Name of the referenced plugin / rule.
255+
*/
256+
name?: string;
257+
258+
/**
259+
* URL pointing to documentation for the plugin / rule.
260+
*/
261+
url?: string;
262+
}
263+
182264
/**
183265
* Generic type for `RuleContext`.
184266
*/

packages/core/tests/types/types.test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,24 @@ const testRule: RuleDefinition<{
199199
meta: {
200200
type: "problem",
201201
fixable: "code",
202+
deprecated: {
203+
message: "use something else",
204+
url: "https://example.com",
205+
replacedBy: [
206+
{
207+
message: "use this instead",
208+
url: "https://example.com",
209+
rule: {
210+
name: "new-rule",
211+
url: "https://example.com/rules/new-rule",
212+
},
213+
plugin: {
214+
name: "new-plugin",
215+
url: "https://example.com/plugins/new-plugin",
216+
},
217+
},
218+
],
219+
},
202220
messages: {
203221
badFoo: "change this foo",
204222
wrongBar: "fix this bar",

0 commit comments

Comments
 (0)