@@ -7,6 +7,7 @@ use std::path::Path;
77
88use regex:: Regex ;
99
10+ use crate :: diagnostics:: { CheckId , DiagCtx , RunningCheck } ;
1011use crate :: walk:: { filter_dirs, walk} ;
1112
1213fn message ( ) -> & ' static Regex {
@@ -20,33 +21,30 @@ fn is_fluent(path: &Path) -> bool {
2021fn check_alphabetic (
2122 filename : & str ,
2223 fluent : & str ,
23- bad : & mut bool ,
24+ check : & mut RunningCheck ,
2425 all_defined_msgs : & mut HashMap < String , String > ,
2526) {
2627 let mut matches = message ( ) . captures_iter ( fluent) . peekable ( ) ;
2728 while let Some ( m) = matches. next ( ) {
2829 let name = m. get ( 1 ) . unwrap ( ) ;
2930 if let Some ( defined_filename) = all_defined_msgs. get ( name. as_str ( ) ) {
30- tidy_error ! (
31- bad,
32- "{filename}: message `{}` is already defined in {}" ,
31+ check. error ( format ! (
32+ "{filename}: message `{}` is already defined in {defined_filename}" ,
3333 name. as_str( ) ,
34- defined_filename,
35- ) ;
34+ ) ) ;
3635 }
3736
3837 all_defined_msgs. insert ( name. as_str ( ) . to_owned ( ) , filename. to_owned ( ) ) ;
3938
4039 if let Some ( next) = matches. peek ( ) {
4140 let next = next. get ( 1 ) . unwrap ( ) ;
4241 if name. as_str ( ) > next. as_str ( ) {
43- tidy_error ! (
44- bad,
42+ check. error ( format ! (
4543 "{filename}: message `{}` appears before `{}`, but is alphabetically later than it
4644run `./x.py test tidy --bless` to sort the file correctly" ,
4745 name. as_str( ) ,
4846 next. as_str( )
49- ) ;
47+ ) ) ;
5048 }
5149 } else {
5250 break ;
@@ -57,20 +55,18 @@ run `./x.py test tidy --bless` to sort the file correctly",
5755fn sort_messages (
5856 filename : & str ,
5957 fluent : & str ,
60- bad : & mut bool ,
58+ check : & mut RunningCheck ,
6159 all_defined_msgs : & mut HashMap < String , String > ,
6260) -> String {
6361 let mut chunks = vec ! [ ] ;
6462 let mut cur = String :: new ( ) ;
6563 for line in fluent. lines ( ) {
6664 if let Some ( name) = message ( ) . find ( line) {
6765 if let Some ( defined_filename) = all_defined_msgs. get ( name. as_str ( ) ) {
68- tidy_error ! (
69- bad,
70- "{filename}: message `{}` is already defined in {}" ,
66+ check. error ( format ! (
67+ "{filename}: message `{}` is already defined in {defined_filename}" ,
7168 name. as_str( ) ,
72- defined_filename,
73- ) ;
69+ ) ) ;
7470 }
7571
7672 all_defined_msgs. insert ( name. as_str ( ) . to_owned ( ) , filename. to_owned ( ) ) ;
@@ -88,7 +84,9 @@ fn sort_messages(
8884 out
8985}
9086
91- pub fn check ( path : & Path , bless : bool , bad : & mut bool ) {
87+ pub fn check ( path : & Path , bless : bool , diag_ctx : DiagCtx ) {
88+ let mut check = diag_ctx. start_check ( CheckId :: new ( "fluent_alphabetical" ) . path ( path) ) ;
89+
9290 let mut all_defined_msgs = HashMap :: new ( ) ;
9391 walk (
9492 path,
@@ -98,7 +96,7 @@ pub fn check(path: &Path, bless: bool, bad: &mut bool) {
9896 let sorted = sort_messages (
9997 ent. path ( ) . to_str ( ) . unwrap ( ) ,
10098 contents,
101- bad ,
99+ & mut check ,
102100 & mut all_defined_msgs,
103101 ) ;
104102 if sorted != contents {
@@ -110,12 +108,12 @@ pub fn check(path: &Path, bless: bool, bad: &mut bool) {
110108 check_alphabetic (
111109 ent. path ( ) . to_str ( ) . unwrap ( ) ,
112110 contents,
113- bad ,
111+ & mut check ,
114112 & mut all_defined_msgs,
115113 ) ;
116114 }
117115 } ,
118116 ) ;
119117
120- crate :: fluent_used:: check ( path, all_defined_msgs, bad ) ;
118+ crate :: fluent_used:: check ( path, all_defined_msgs, diag_ctx ) ;
121119}
0 commit comments