@@ -29,18 +29,29 @@ fn is_close_bracket(c: char) -> bool {
29
29
matches ! ( c, ')' | ']' | '}' )
30
30
}
31
31
32
+ const START_COMMENT : & str = "// tidy-alphabetical-start" ;
33
+ const END_COMMENT : & str = "// tidy-alphabetical-end" ;
34
+
32
35
fn check_section < ' a > (
33
36
file : impl Display ,
34
37
lines : impl Iterator < Item = ( usize , & ' a str ) > ,
35
38
bad : & mut bool ,
36
39
) {
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 ) ) ;
38
41
39
42
let mut prev_line = String :: new ( ) ;
40
43
let mut first_indent = None ;
41
44
let mut in_split_line = None ;
42
45
43
46
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
+
44
55
let indent = first_indent. unwrap_or_else ( || {
45
56
let indent = indentation ( line) ;
46
57
first_indent = Some ( indent) ;
@@ -82,16 +93,20 @@ fn check_section<'a>(
82
93
}
83
94
}
84
95
85
- const START_COMMENT : & str = "// tidy-alphabetical-start" ;
86
-
87
96
pub fn check ( path : & Path , bad : & mut bool ) {
88
97
walk ( path, & mut filter_dirs, & mut |entry, contents| {
89
98
let file = & entry. path ( ) . display ( ) ;
90
99
91
- let mut lines = contents. lines ( ) . enumerate ( ) ;
100
+ let mut lines = contents. lines ( ) . enumerate ( ) . peekable ( ) ;
92
101
while let Some ( ( _, line) ) = lines. next ( ) {
93
102
if line. contains ( START_COMMENT ) {
94
103
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
+ }
95
110
}
96
111
}
97
112
} ) ;
0 commit comments