@@ -257,74 +257,74 @@ pub struct PreviewOptions {
257257#[ cfg( feature = "schemars" ) ]
258258mod schema {
259259 use itertools:: Itertools ;
260- use schemars:: _serde_json:: Value ;
261- use schemars:: JsonSchema ;
262- use schemars:: schema:: { InstanceType , Schema , SchemaObject } ;
260+ use schemars:: { JsonSchema , Schema , SchemaGenerator } ;
261+ use serde_json:: Value ;
263262 use strum:: IntoEnumIterator ;
264263
265264 use crate :: RuleSelector ;
266265 use crate :: registry:: RuleNamespace ;
267266 use crate :: rule_selector:: { Linter , RuleCodePrefix } ;
268267
269268 impl JsonSchema for RuleSelector {
270- fn schema_name ( ) -> String {
271- "RuleSelector" . to_string ( )
269+ fn schema_name ( ) -> std :: borrow :: Cow < ' static , str > {
270+ std :: borrow :: Cow :: Borrowed ( "RuleSelector" )
272271 }
273272
274- fn json_schema ( _gen : & mut schemars:: r#gen:: SchemaGenerator ) -> Schema {
275- Schema :: Object ( SchemaObject {
276- instance_type : Some ( InstanceType :: String . into ( ) ) ,
277- enum_values : Some (
278- [
279- // Include the non-standard "ALL" selectors.
280- "ALL" . to_string ( ) ,
281- // Include the legacy "C" and "T" selectors.
282- "C" . to_string ( ) ,
283- "T" . to_string ( ) ,
284- // Include some common redirect targets for those legacy selectors.
285- "C9" . to_string ( ) ,
286- "T1" . to_string ( ) ,
287- "T2" . to_string ( ) ,
288- ]
289- . into_iter ( )
290- . chain (
291- RuleCodePrefix :: iter ( )
292- . map ( |p| {
293- let prefix = p. linter ( ) . common_prefix ( ) ;
294- let code = p. short_code ( ) ;
295- format ! ( "{prefix}{code}" )
296- } )
297- . chain ( Linter :: iter ( ) . filter_map ( |l| {
298- let prefix = l. common_prefix ( ) ;
299- ( !prefix. is_empty ( ) ) . then ( || prefix. to_string ( ) )
300- } ) ) ,
301- )
302- . filter ( |p| {
303- // Exclude any prefixes where all of the rules are removed
304- if let Ok ( Self :: Rule { prefix, .. } | Self :: Prefix { prefix, .. } ) =
305- RuleSelector :: parse_no_redirect ( p)
306- {
307- !prefix. rules ( ) . all ( |rule| rule. is_removed ( ) )
308- } else {
309- true
310- }
273+ fn json_schema ( _gen : & mut SchemaGenerator ) -> Schema {
274+ let enum_values: Vec < String > = [
275+ // Include the non-standard "ALL" selectors.
276+ "ALL" . to_string ( ) ,
277+ // Include the legacy "C" and "T" selectors.
278+ "C" . to_string ( ) ,
279+ "T" . to_string ( ) ,
280+ // Include some common redirect targets for those legacy selectors.
281+ "C9" . to_string ( ) ,
282+ "T1" . to_string ( ) ,
283+ "T2" . to_string ( ) ,
284+ ]
285+ . into_iter ( )
286+ . chain (
287+ RuleCodePrefix :: iter ( )
288+ . map ( |p| {
289+ let prefix = p. linter ( ) . common_prefix ( ) ;
290+ let code = p. short_code ( ) ;
291+ format ! ( "{prefix}{code}" )
311292 } )
312- . filter ( |_rule| {
313- // Filter out all test-only rules
314- #[ cfg( any( feature = "test-rules" , test) ) ]
315- #[ expect( clippy:: used_underscore_binding) ]
316- if _rule. starts_with ( "RUF9" ) || _rule == "PLW0101" {
317- return false ;
318- }
319-
320- true
321- } )
322- . sorted ( )
323- . map ( Value :: String )
324- . collect ( ) ,
325- ) ,
326- ..SchemaObject :: default ( )
293+ . chain ( Linter :: iter ( ) . filter_map ( |l| {
294+ let prefix = l. common_prefix ( ) ;
295+ ( !prefix. is_empty ( ) ) . then ( || prefix. to_string ( ) )
296+ } ) ) ,
297+ )
298+ . filter ( |p| {
299+ // Exclude any prefixes where all of the rules are removed
300+ if let Ok ( Self :: Rule { prefix, .. } | Self :: Prefix { prefix, .. } ) =
301+ RuleSelector :: parse_no_redirect ( p)
302+ {
303+ !prefix. rules ( ) . all ( |rule| rule. is_removed ( ) )
304+ } else {
305+ true
306+ }
327307 } )
308+ . filter ( |_rule| {
309+ // Filter out all test-only rules
310+ #[ cfg( any( feature = "test-rules" , test) ) ]
311+ #[ expect( clippy:: used_underscore_binding) ]
312+ if _rule. starts_with ( "RUF9" ) || _rule == "PLW0101" {
313+ return false ;
314+ }
315+
316+ true
317+ } )
318+ . sorted ( )
319+ . collect ( ) ;
320+
321+ let mut schema = schemars:: json_schema!( { "type" : "string" } ) ;
322+ schema. ensure_object ( ) . insert (
323+ "enum" . to_string ( ) ,
324+ Value :: Array ( enum_values. into_iter ( ) . map ( Value :: String ) . collect ( ) ) ,
325+ ) ;
326+
327+ schema
328328 }
329329 }
330330}
0 commit comments