File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -36,7 +36,11 @@ impl Runner for LintRunner {
3636 fn run ( self ) -> CliRunResult {
3737 if self . options . list_rules {
3838 let mut stdout = BufWriter :: new ( std:: io:: stdout ( ) ) ;
39- Linter :: print_rules ( & mut stdout) ;
39+ if self . options . output_options . format == OutputFormat :: Json {
40+ Linter :: print_rules_json ( & mut stdout) ;
41+ } else {
42+ Linter :: print_rules ( & mut stdout) ;
43+ }
4044 return CliRunResult :: None ;
4145 }
4246
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ pub mod table;
2626use std:: { io:: Write , path:: Path , rc:: Rc , sync:: Arc } ;
2727
2828use oxc_semantic:: { AstNode , Semantic } ;
29+ use rules:: RULES ;
2930
3031pub use crate :: {
3132 builder:: { LinterBuilder , LinterBuilderError } ,
@@ -211,6 +212,30 @@ impl Linter {
211212 writeln ! ( writer, "Default: {}" , table. turned_on_by_default_count) . unwrap ( ) ;
212213 writeln ! ( writer, "Total: {}" , table. total) . unwrap ( ) ;
213214 }
215+
216+ /// # Panics
217+ pub fn print_rules_json < W : Write > ( writer : & mut W ) {
218+ #[ derive( Debug , serde:: Serialize ) ]
219+ struct RuleInfoJson < ' a > {
220+ scope : & ' a str ,
221+ value : & ' a str ,
222+ category : RuleCategory ,
223+ }
224+
225+ let rules_info = RULES . iter ( ) . map ( |rule| RuleInfoJson {
226+ scope : rule. plugin_name ( ) ,
227+ value : rule. name ( ) ,
228+ category : rule. category ( ) ,
229+ } ) ;
230+
231+ writer
232+ . write_all (
233+ serde_json:: to_string_pretty ( & rules_info. collect :: < Vec < _ > > ( ) )
234+ . expect ( "Failed to serialize" )
235+ . as_bytes ( ) ,
236+ )
237+ . unwrap ( ) ;
238+ }
214239}
215240
216241#[ cfg( test) ]
You can’t perform that action at this time.
0 commit comments