@@ -130,6 +130,9 @@ impl MakeSuggestions for TidyAdvice {
130130 }
131131}
132132
133+ /// A regex pattern to capture the clang-tidy note header.
134+ const NOTE_HEADER : & str = r"^(.+):(\d+):(\d+):\s(\w+):(.*)\[([a-zA-Z\d\-\.]+),?[^\]]*\]$" ;
135+
133136/// Parses clang-tidy stdout.
134137///
135138/// Here it helps to have the JSON database deserialized for normalizing paths present
@@ -138,7 +141,7 @@ fn parse_tidy_output(
138141 tidy_stdout : & [ u8 ] ,
139142 database_json : & Option < Vec < CompilationUnit > > ,
140143) -> Result < TidyAdvice > {
141- let note_header = Regex :: new ( r"^(.+):(\d+):(\d+):\s(\w+):(.*)\[([a-zA-Z\d\-\.]+)\]$" ) . unwrap ( ) ;
144+ let note_header = Regex :: new ( NOTE_HEADER ) . unwrap ( ) ;
142145 let fixed_note =
143146 Regex :: new ( r"^.+:(\d+):\d+:\snote: FIX-IT applied suggested code changes$" ) . unwrap ( ) ;
144147 let mut found_fix = false ;
@@ -354,8 +357,7 @@ mod test {
354357 common_fs:: FileObj ,
355358 } ;
356359
357- use super :: run_clang_tidy;
358- use super :: TidyNotification ;
360+ use super :: { run_clang_tidy, TidyNotification , NOTE_HEADER } ;
359361
360362 #[ test]
361363 fn clang_diagnostic_link ( ) {
@@ -397,13 +399,15 @@ mod test {
397399
398400 #[ test]
399401 fn test_capture ( ) {
400- let src = "tests/demo/demo.hpp:11:11: warning: use a trailing return type for this function [modernize-use-trailing-return-type]" ;
401- let pat = Regex :: new ( r"^(.+):(\d+):(\d+):\s(\w+):(.*)\[([a-zA-Z\d\-\.]+)\]$" ) . unwrap ( ) ;
402+ let src = "tests/demo/demo.hpp:11:11: \
403+ warning: use a trailing return type for this function \
404+ [modernize-use-trailing-return-type,-warnings-as-errors]";
405+ let pat = Regex :: new ( NOTE_HEADER ) . unwrap ( ) ;
402406 let cap = pat. captures ( src) . unwrap ( ) ;
403407 assert_eq ! (
404408 cap. get( 0 ) . unwrap( ) . as_str( ) ,
405409 format!(
406- "{}:{}:{}: {}:{}[{}]" ,
410+ "{}:{}:{}: {}:{}[{},-warnings-as-errors ]" ,
407411 cap. get( 1 ) . unwrap( ) . as_str( ) ,
408412 cap. get( 2 ) . unwrap( ) . as_str( ) ,
409413 cap. get( 3 ) . unwrap( ) . as_str( ) ,
0 commit comments