@@ -29,18 +29,29 @@ fn is_close_bracket(c: char) -> bool {
2929 matches ! ( c, ')' | ']' | '}' )
3030}
3131
32+ const START_COMMENT : & str = "// tidy-alphabetical-start" ;
33+ const END_COMMENT : & str = "// tidy-alphabetical-end" ;
34+
3235fn check_section < ' a > (
3336 file : impl Display ,
3437 lines : impl Iterator < Item = ( usize , & ' a str ) > ,
3538 bad : & mut bool ,
3639) {
37- let content_lines = lines. take_while ( |( _, line) | !line. contains ( "// tidy-alphabetical-end" ) ) ;
40+ let content_lines = lines. take_while ( |( _, line) | !line. contains ( END_COMMENT ) ) ;
3841
3942 let mut prev_line = String :: new ( ) ;
4043 let mut first_indent = None ;
4144 let mut in_split_line = None ;
4245
4346 for ( line_idx, line) in content_lines {
47+ if line. contains ( START_COMMENT ) {
48+ tidy_error ! (
49+ bad,
50+ "{file}:{} found `// tidy-alphabetical-start` expecting `// tidy-alphabetical-end`" ,
51+ line_idx
52+ )
53+ }
54+
4455 let indent = first_indent. unwrap_or_else ( || {
4556 let indent = indentation ( line) ;
4657 first_indent = Some ( indent) ;
@@ -82,16 +93,20 @@ fn check_section<'a>(
8293 }
8394}
8495
85- const START_COMMENT : & str = "// tidy-alphabetical-start" ;
86-
8796pub fn check ( path : & Path , bad : & mut bool ) {
8897 walk ( path, & mut filter_dirs, & mut |entry, contents| {
8998 let file = & entry. path ( ) . display ( ) ;
9099
91- let mut lines = contents. lines ( ) . enumerate ( ) ;
100+ let mut lines = contents. lines ( ) . enumerate ( ) . peekable ( ) ;
92101 while let Some ( ( _, line) ) = lines. next ( ) {
93102 if line. contains ( START_COMMENT ) {
94103 check_section ( file, & mut lines, bad) ;
104+ if lines. peek ( ) . is_none ( ) {
105+ tidy_error ! (
106+ bad,
107+ "{file}: reached end of file expecting `// tidy-alphabetical-end`"
108+ )
109+ }
95110 }
96111 }
97112 } ) ;
0 commit comments