@@ -506,6 +506,11 @@ pub(crate) trait Linter {
506506 Severity :: Warning
507507 }
508508
509+ // For CLI, when using the --use-cli-severity flag. It defaults to `severity()`
510+ fn cli_severity ( & self ) -> Severity {
511+ self . severity ( )
512+ }
513+
509514 // Specify if the linter issues can be suppressed via a `% elp:ignore` comment.
510515 fn can_be_suppressed ( & self ) -> bool {
511516 true
@@ -640,11 +645,23 @@ pub(crate) trait SsrPatternsLinter: Linter {
640645// we define a blanket implementation for all the methods using the `Context``,
641646// to keep the code generic while allowing individual linters to specify their own context type.
642647pub ( crate ) trait SsrCheckPatterns : Linter {
643- fn diagnostics ( & self , sema : & Semantic , file_id : FileId , severity : Severity ) -> Vec < Diagnostic > ;
648+ fn diagnostics (
649+ & self ,
650+ sema : & Semantic ,
651+ file_id : FileId ,
652+ severity : Severity ,
653+ cli_severity : Severity ,
654+ ) -> Vec < Diagnostic > ;
644655}
645656
646657impl < T : SsrPatternsLinter > SsrCheckPatterns for T {
647- fn diagnostics ( & self , sema : & Semantic , file_id : FileId , severity : Severity ) -> Vec < Diagnostic > {
658+ fn diagnostics (
659+ & self ,
660+ sema : & Semantic ,
661+ file_id : FileId ,
662+ severity : Severity ,
663+ cli_severity : Severity ,
664+ ) -> Vec < Diagnostic > {
648665 let mut res = Vec :: new ( ) ;
649666 for ( pattern, context) in self . patterns ( ) {
650667 let matches = match_pattern_in_file_functions ( sema, self . strategy ( ) , file_id, & pattern) ;
@@ -656,7 +673,8 @@ impl<T: SsrPatternsLinter> SsrCheckPatterns for T {
656673 let mut d = Diagnostic :: new ( self . id ( ) , message, matched. range . range )
657674 . with_fixes ( fixes)
658675 . add_categories ( categories)
659- . with_severity ( severity) ;
676+ . with_severity ( severity)
677+ . with_cli_severity ( cli_severity) ;
660678 if self . can_be_suppressed ( ) {
661679 d = d. with_ignore_fix ( sema, file_id) ;
662680 }
@@ -1286,12 +1304,20 @@ fn diagnostics_from_linters(
12861304 } else {
12871305 linter. severity ( )
12881306 } ;
1307+ let cli_severity = if let Some ( lint_config) = config. lint_config . as_ref ( ) {
1308+ lint_config
1309+ . get_severity_override ( & linter. id ( ) )
1310+ . unwrap_or_else ( || linter. cli_severity ( ) )
1311+ } else {
1312+ linter. cli_severity ( )
1313+ } ;
12891314 match l {
12901315 DiagnosticLinter :: FunctionCall ( function_linter) => {
12911316 let diagnostic_template = DiagnosticTemplate {
12921317 code,
12931318 message : linter. description ( ) ,
12941319 severity,
1320+ cli_severity,
12951321 with_ignore_fix : linter. can_be_suppressed ( ) ,
12961322 use_range : UseRange :: NameOnly ,
12971323 } ;
@@ -1302,7 +1328,7 @@ fn diagnostics_from_linters(
13021328 specs. extend ( spec) ;
13031329 }
13041330 DiagnosticLinter :: SsrPatterns ( ssr_linter) => {
1305- let diagnostics = ssr_linter. diagnostics ( sema, file_id, severity) ;
1331+ let diagnostics = ssr_linter. diagnostics ( sema, file_id, severity, cli_severity ) ;
13061332 res. extend ( diagnostics) ;
13071333 }
13081334 }
0 commit comments