@@ -6,7 +6,6 @@ use std::fmt;
6
6
7
7
use crate :: config:: ReportTactic ;
8
8
9
- const TO_DO_CHARS : & [ char ] = & [ 't' , 'o' , 'd' , 'o' ] ;
10
9
const FIX_ME_CHARS : & [ char ] = & [ 'f' , 'i' , 'x' , 'm' , 'e' ] ;
11
10
12
11
// Enabled implementation detail is here because it is
@@ -17,7 +16,7 @@ fn is_enabled(report_tactic: ReportTactic) -> bool {
17
16
18
17
#[ derive( Clone , Copy ) ]
19
18
enum Seeking {
20
- Issue { todo_idx : usize , fixme_idx : usize } ,
19
+ Issue { fixme_idx : usize } ,
21
20
Number { issue : Issue , part : NumberPart } ,
22
21
}
23
22
@@ -40,7 +39,6 @@ pub struct Issue {
40
39
impl fmt:: Display for Issue {
41
40
fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> Result < ( ) , fmt:: Error > {
42
41
let msg = match self . issue_type {
43
- IssueType :: Todo => "TODO" ,
44
42
IssueType :: Fixme => "FIXME" ,
45
43
} ;
46
44
let details = if self . missing_number {
@@ -55,7 +53,6 @@ impl fmt::Display for Issue {
55
53
56
54
#[ derive( PartialEq , Eq , Debug , Clone , Copy ) ]
57
55
enum IssueType {
58
- Todo ,
59
56
Fixme ,
60
57
}
61
58
@@ -67,35 +64,27 @@ enum IssueClassification {
67
64
68
65
pub ( crate ) struct BadIssueSeeker {
69
66
state : Seeking ,
70
- report_todo : ReportTactic ,
71
67
report_fixme : ReportTactic ,
72
68
}
73
69
74
70
impl BadIssueSeeker {
75
- pub ( crate ) fn new ( report_todo : ReportTactic , report_fixme : ReportTactic ) -> BadIssueSeeker {
71
+ pub ( crate ) fn new ( report_fixme : ReportTactic ) -> BadIssueSeeker {
76
72
BadIssueSeeker {
77
- state : Seeking :: Issue {
78
- todo_idx : 0 ,
79
- fixme_idx : 0 ,
80
- } ,
81
- report_todo,
73
+ state : Seeking :: Issue { fixme_idx : 0 } ,
82
74
report_fixme,
83
75
}
84
76
}
85
77
86
78
pub ( crate ) fn is_disabled ( & self ) -> bool {
87
- !is_enabled ( self . report_todo ) && ! is_enabled ( self . report_fixme )
79
+ !is_enabled ( self . report_fixme )
88
80
}
89
81
90
82
// Check whether or not the current char is conclusive evidence for an
91
83
// unnumbered TO-DO or FIX-ME.
92
84
pub ( crate ) fn inspect ( & mut self , c : char ) -> Option < Issue > {
93
85
match self . state {
94
- Seeking :: Issue {
95
- todo_idx,
96
- fixme_idx,
97
- } => {
98
- self . state = self . inspect_issue ( c, todo_idx, fixme_idx) ;
86
+ Seeking :: Issue { fixme_idx } => {
87
+ self . state = self . inspect_issue ( c, fixme_idx) ;
99
88
}
100
89
Seeking :: Number { issue, part } => {
101
90
let result = self . inspect_number ( c, issue, part) ;
@@ -104,10 +93,7 @@ impl BadIssueSeeker {
104
93
return None ;
105
94
}
106
95
107
- self . state = Seeking :: Issue {
108
- todo_idx : 0 ,
109
- fixme_idx : 0 ,
110
- } ;
96
+ self . state = Seeking :: Issue { fixme_idx : 0 } ;
111
97
112
98
if let IssueClassification :: Bad ( issue) = result {
113
99
return Some ( issue) ;
@@ -118,21 +104,9 @@ impl BadIssueSeeker {
118
104
None
119
105
}
120
106
121
- fn inspect_issue ( & mut self , c : char , mut todo_idx : usize , mut fixme_idx : usize ) -> Seeking {
107
+ fn inspect_issue ( & mut self , c : char , mut fixme_idx : usize ) -> Seeking {
122
108
if let Some ( lower_case_c) = c. to_lowercase ( ) . next ( ) {
123
- if is_enabled ( self . report_todo ) && lower_case_c == TO_DO_CHARS [ todo_idx] {
124
- todo_idx += 1 ;
125
- if todo_idx == TO_DO_CHARS . len ( ) {
126
- return Seeking :: Number {
127
- issue : Issue {
128
- issue_type : IssueType :: Todo ,
129
- missing_number : matches ! ( self . report_todo, ReportTactic :: Unnumbered ) ,
130
- } ,
131
- part : NumberPart :: OpenParen ,
132
- } ;
133
- }
134
- fixme_idx = 0 ;
135
- } else if is_enabled ( self . report_fixme ) && lower_case_c == FIX_ME_CHARS [ fixme_idx] {
109
+ if is_enabled ( self . report_fixme ) && lower_case_c == FIX_ME_CHARS [ fixme_idx] {
136
110
// Exploit the fact that the character sets of todo and fixme
137
111
// are disjoint by adding else.
138
112
fixme_idx += 1 ;
@@ -145,17 +119,12 @@ impl BadIssueSeeker {
145
119
part : NumberPart :: OpenParen ,
146
120
} ;
147
121
}
148
- todo_idx = 0 ;
149
122
} else {
150
- todo_idx = 0 ;
151
123
fixme_idx = 0 ;
152
124
}
153
125
}
154
126
155
- Seeking :: Issue {
156
- todo_idx,
157
- fixme_idx,
158
- }
127
+ Seeking :: Issue { fixme_idx }
159
128
}
160
129
161
130
fn inspect_number (
@@ -206,20 +175,18 @@ impl BadIssueSeeker {
206
175
#[ test]
207
176
fn find_unnumbered_issue ( ) {
208
177
fn check_fail ( text : & str , failing_pos : usize ) {
209
- let mut seeker = BadIssueSeeker :: new ( ReportTactic :: Unnumbered , ReportTactic :: Unnumbered ) ;
178
+ let mut seeker = BadIssueSeeker :: new ( ReportTactic :: Unnumbered ) ;
210
179
assert_eq ! (
211
180
Some ( failing_pos) ,
212
181
text. find( |c| seeker. inspect( c) . is_some( ) )
213
182
) ;
214
183
}
215
184
216
185
fn check_pass ( text : & str ) {
217
- let mut seeker = BadIssueSeeker :: new ( ReportTactic :: Unnumbered , ReportTactic :: Unnumbered ) ;
186
+ let mut seeker = BadIssueSeeker :: new ( ReportTactic :: Unnumbered ) ;
218
187
assert_eq ! ( None , text. find( |c| seeker. inspect( c) . is_some( ) ) ) ;
219
188
}
220
189
221
- check_fail ( "TODO\n " , 4 ) ;
222
- check_pass ( " TO FIX DOME\n " ) ;
223
190
check_fail ( " \n FIXME\n " , 8 ) ;
224
191
check_fail ( "FIXME(\n " , 6 ) ;
225
192
check_fail ( "FIXME(#\n " , 7 ) ;
@@ -228,71 +195,28 @@ fn find_unnumbered_issue() {
228
195
check_pass ( "FIXME(#1222)\n " ) ;
229
196
check_fail ( "FIXME(#12\n 22)\n " , 9 ) ;
230
197
check_pass ( "FIXME(@maintainer, #1222, hello)\n " ) ;
231
- check_fail ( "TODO(#22) FIXME\n " , 15 ) ;
232
198
}
233
199
234
200
#[ test]
235
201
fn find_issue ( ) {
236
- fn is_bad_issue ( text : & str , report_todo : ReportTactic , report_fixme : ReportTactic ) -> bool {
237
- let mut seeker = BadIssueSeeker :: new ( report_todo , report_fixme) ;
202
+ fn is_bad_issue ( text : & str , report_fixme : ReportTactic ) -> bool {
203
+ let mut seeker = BadIssueSeeker :: new ( report_fixme) ;
238
204
text. chars ( ) . any ( |c| seeker. inspect ( c) . is_some ( ) )
239
205
}
240
206
241
- assert ! ( is_bad_issue(
242
- "TODO(@maintainer, #1222, hello)\n " ,
243
- ReportTactic :: Always ,
244
- ReportTactic :: Never ,
245
- ) ) ;
246
-
247
- assert ! ( !is_bad_issue(
248
- "TODO: no number\n " ,
249
- ReportTactic :: Never ,
250
- ReportTactic :: Always ,
251
- ) ) ;
252
-
253
- assert ! ( !is_bad_issue(
254
- "Todo: mixed case\n " ,
255
- ReportTactic :: Never ,
256
- ReportTactic :: Always ,
257
- ) ) ;
258
-
259
- assert ! ( is_bad_issue(
260
- "This is a FIXME(#1)\n " ,
261
- ReportTactic :: Never ,
262
- ReportTactic :: Always ,
263
- ) ) ;
207
+ assert ! ( is_bad_issue( "This is a FIXME(#1)\n " , ReportTactic :: Always ) ) ;
264
208
265
209
assert ! ( is_bad_issue(
266
210
"This is a FixMe(#1) mixed case\n " ,
267
- ReportTactic :: Never ,
268
211
ReportTactic :: Always ,
269
212
) ) ;
270
213
271
- assert ! ( !is_bad_issue(
272
- "bad FIXME\n " ,
273
- ReportTactic :: Always ,
274
- ReportTactic :: Never ,
275
- ) ) ;
214
+ assert ! ( !is_bad_issue( "bad FIXME\n " , ReportTactic :: Never ) ) ;
276
215
}
277
216
278
217
#[ test]
279
218
fn issue_type ( ) {
280
- let mut seeker = BadIssueSeeker :: new ( ReportTactic :: Always , ReportTactic :: Never ) ;
281
- let expected = Some ( Issue {
282
- issue_type : IssueType :: Todo ,
283
- missing_number : false ,
284
- } ) ;
285
-
286
- assert_eq ! (
287
- expected,
288
- "TODO(#100): more awesomeness"
289
- . chars( )
290
- . map( |c| seeker. inspect( c) )
291
- . find( Option :: is_some)
292
- . unwrap( )
293
- ) ;
294
-
295
- let mut seeker = BadIssueSeeker :: new ( ReportTactic :: Never , ReportTactic :: Unnumbered ) ;
219
+ let mut seeker = BadIssueSeeker :: new ( ReportTactic :: Unnumbered ) ;
296
220
let expected = Some ( Issue {
297
221
issue_type : IssueType :: Fixme ,
298
222
missing_number : true ,
0 commit comments