@@ -46,6 +46,9 @@ pub struct LintCommand {
46
46
#[ bpaf( switch, hide_usage) ]
47
47
pub disable_nested_config : bool ,
48
48
49
+ #[ bpaf( external) ]
50
+ pub inline_config_options : InlineConfigOptions ,
51
+
49
52
/// Single file, single path or list of paths
50
53
#[ bpaf( positional( "PATH" ) , many, guard( validate_paths, PATHS_ERROR_MESSAGE ) ) ]
51
54
pub paths : Vec < PathBuf > ,
@@ -349,6 +352,36 @@ impl EnablePlugins {
349
352
}
350
353
}
351
354
355
+ #[ derive( Debug , Clone , PartialEq , Eq , Bpaf ) ]
356
+ pub enum ReportUnusedDirectives {
357
+ WithoutSeverity (
358
+ /// Report directive comments like `// eslint-disable-line` when no errors would have been reported on that line anyway.
359
+ // More information at <https://eslint.org/docs/latest/use/command-line-interface#--report-unused-disable-directives>
360
+ #[ bpaf( long( "report-unused-disable-directives" ) , switch, hide_usage) ]
361
+ bool ,
362
+ ) ,
363
+ WithSeverity (
364
+ /// Same as `--report-unused-disable-directives`, but allows you to specify the severity level of the reported errors.
365
+ /// Only one of these two options can be used at a time.
366
+ #[ bpaf(
367
+ long( "report-unused-disable-directives-severity" ) ,
368
+ argument:: <String >( "SEVERITY" ) ,
369
+ guard( |s| AllowWarnDeny :: try_from( s. as_str( ) ) . is_ok( ) , "Invalid severity value" ) ,
370
+ map( |s| AllowWarnDeny :: try_from( s. as_str( ) ) . unwrap( ) ) , // guard ensures try_from will be Ok
371
+ optional,
372
+ hide_usage
373
+ ) ]
374
+ Option < AllowWarnDeny > ,
375
+ ) ,
376
+ }
377
+
378
+ /// Inline Configuration Comments
379
+ #[ derive( Debug , Clone , Bpaf ) ]
380
+ pub struct InlineConfigOptions {
381
+ #[ bpaf( external) ]
382
+ pub report_unused_directives : ReportUnusedDirectives ,
383
+ }
384
+
352
385
#[ cfg( test) ]
353
386
mod plugins {
354
387
use oxc_linter:: LintPlugins ;
@@ -526,3 +559,51 @@ mod lint_options {
526
559
assert ! ( !options. disable_nested_config) ;
527
560
}
528
561
}
562
+
563
+ #[ cfg( test) ]
564
+ mod inline_config_options {
565
+ use oxc_linter:: AllowWarnDeny ;
566
+
567
+ use super :: { LintCommand , ReportUnusedDirectives , lint_command} ;
568
+
569
+ fn get_lint_options ( arg : & str ) -> LintCommand {
570
+ let args = arg. split ( ' ' ) . map ( std:: string:: ToString :: to_string) . collect :: < Vec < _ > > ( ) ;
571
+ lint_command ( ) . run_inner ( args. as_slice ( ) ) . unwrap ( )
572
+ }
573
+
574
+ #[ test]
575
+ fn default ( ) {
576
+ let options = get_lint_options ( "." ) ;
577
+ assert_eq ! (
578
+ options. inline_config_options. report_unused_directives,
579
+ ReportUnusedDirectives :: WithoutSeverity ( false )
580
+ ) ;
581
+ }
582
+
583
+ #[ test]
584
+ fn without_severity ( ) {
585
+ let options = get_lint_options ( "--report-unused-disable-directives" ) ;
586
+ assert_eq ! (
587
+ options. inline_config_options. report_unused_directives,
588
+ ReportUnusedDirectives :: WithoutSeverity ( true )
589
+ ) ;
590
+ }
591
+
592
+ #[ test]
593
+ fn with_severity_warn ( ) {
594
+ let options = get_lint_options ( "--report-unused-disable-directives-severity=warn" ) ;
595
+ assert_eq ! (
596
+ options. inline_config_options. report_unused_directives,
597
+ ReportUnusedDirectives :: WithSeverity ( Some ( AllowWarnDeny :: Warn ) )
598
+ ) ;
599
+ }
600
+
601
+ #[ test]
602
+ fn with_severity_error ( ) {
603
+ let options = get_lint_options ( "--report-unused-disable-directives-severity error" ) ;
604
+ assert_eq ! (
605
+ options. inline_config_options. report_unused_directives,
606
+ ReportUnusedDirectives :: WithSeverity ( Some ( AllowWarnDeny :: Deny ) )
607
+ ) ;
608
+ }
609
+ }
0 commit comments