@@ -130,6 +130,9 @@ impl MakeSuggestions for TidyAdvice {
130
130
}
131
131
}
132
132
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
+
133
136
/// Parses clang-tidy stdout.
134
137
///
135
138
/// Here it helps to have the JSON database deserialized for normalizing paths present
@@ -138,7 +141,7 @@ fn parse_tidy_output(
138
141
tidy_stdout : & [ u8 ] ,
139
142
database_json : & Option < Vec < CompilationUnit > > ,
140
143
) -> 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 ( ) ;
142
145
let fixed_note =
143
146
Regex :: new ( r"^.+:(\d+):\d+:\snote: FIX-IT applied suggested code changes$" ) . unwrap ( ) ;
144
147
let mut found_fix = false ;
@@ -354,8 +357,7 @@ mod test {
354
357
common_fs:: FileObj ,
355
358
} ;
356
359
357
- use super :: run_clang_tidy;
358
- use super :: TidyNotification ;
360
+ use super :: { run_clang_tidy, TidyNotification , NOTE_HEADER } ;
359
361
360
362
#[ test]
361
363
fn clang_diagnostic_link ( ) {
@@ -397,13 +399,15 @@ mod test {
397
399
398
400
#[ test]
399
401
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 ( ) ;
402
406
let cap = pat. captures ( src) . unwrap ( ) ;
403
407
assert_eq ! (
404
408
cap. get( 0 ) . unwrap( ) . as_str( ) ,
405
409
format!(
406
- "{}:{}:{}: {}:{}[{}]" ,
410
+ "{}:{}:{}: {}:{}[{},-warnings-as-errors ]" ,
407
411
cap. get( 1 ) . unwrap( ) . as_str( ) ,
408
412
cap. get( 2 ) . unwrap( ) . as_str( ) ,
409
413
cap. get( 3 ) . unwrap( ) . as_str( ) ,
0 commit comments