@@ -6,7 +6,6 @@ use std::fmt;
66
77use crate :: config:: ReportTactic ;
88
9- const TO_DO_CHARS : & [ char ] = & [ 't' , 'o' , 'd' , 'o' ] ;
109const FIX_ME_CHARS : & [ char ] = & [ 'f' , 'i' , 'x' , 'm' , 'e' ] ;
1110
1211// Enabled implementation detail is here because it is
@@ -17,7 +16,7 @@ fn is_enabled(report_tactic: ReportTactic) -> bool {
1716
1817#[ derive( Clone , Copy ) ]
1918enum Seeking {
20- Issue { todo_idx : usize , fixme_idx : usize } ,
19+ Issue { fixme_idx : usize } ,
2120 Number { issue : Issue , part : NumberPart } ,
2221}
2322
@@ -40,7 +39,6 @@ pub struct Issue {
4039impl fmt:: Display for Issue {
4140 fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> Result < ( ) , fmt:: Error > {
4241 let msg = match self . issue_type {
43- IssueType :: Todo => "TODO" ,
4442 IssueType :: Fixme => "FIXME" ,
4543 } ;
4644 let details = if self . missing_number {
@@ -55,7 +53,6 @@ impl fmt::Display for Issue {
5553
5654#[ derive( PartialEq , Eq , Debug , Clone , Copy ) ]
5755enum IssueType {
58- Todo ,
5956 Fixme ,
6057}
6158
@@ -67,35 +64,27 @@ enum IssueClassification {
6764
6865pub ( crate ) struct BadIssueSeeker {
6966 state : Seeking ,
70- report_todo : ReportTactic ,
7167 report_fixme : ReportTactic ,
7268}
7369
7470impl BadIssueSeeker {
75- pub ( crate ) fn new ( report_todo : ReportTactic , report_fixme : ReportTactic ) -> BadIssueSeeker {
71+ pub ( crate ) fn new ( report_fixme : ReportTactic ) -> BadIssueSeeker {
7672 BadIssueSeeker {
77- state : Seeking :: Issue {
78- todo_idx : 0 ,
79- fixme_idx : 0 ,
80- } ,
81- report_todo,
73+ state : Seeking :: Issue { fixme_idx : 0 } ,
8274 report_fixme,
8375 }
8476 }
8577
8678 pub ( crate ) fn is_disabled ( & self ) -> bool {
87- !is_enabled ( self . report_todo ) && ! is_enabled ( self . report_fixme )
79+ !is_enabled ( self . report_fixme )
8880 }
8981
9082 // Check whether or not the current char is conclusive evidence for an
9183 // unnumbered TO-DO or FIX-ME.
9284 pub ( crate ) fn inspect ( & mut self , c : char ) -> Option < Issue > {
9385 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) ;
9988 }
10089 Seeking :: Number { issue, part } => {
10190 let result = self . inspect_number ( c, issue, part) ;
@@ -104,10 +93,7 @@ impl BadIssueSeeker {
10493 return None ;
10594 }
10695
107- self . state = Seeking :: Issue {
108- todo_idx : 0 ,
109- fixme_idx : 0 ,
110- } ;
96+ self . state = Seeking :: Issue { fixme_idx : 0 } ;
11197
11298 if let IssueClassification :: Bad ( issue) = result {
11399 return Some ( issue) ;
@@ -118,21 +104,9 @@ impl BadIssueSeeker {
118104 None
119105 }
120106
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 {
122108 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] {
136110 // Exploit the fact that the character sets of todo and fixme
137111 // are disjoint by adding else.
138112 fixme_idx += 1 ;
@@ -145,17 +119,12 @@ impl BadIssueSeeker {
145119 part : NumberPart :: OpenParen ,
146120 } ;
147121 }
148- todo_idx = 0 ;
149122 } else {
150- todo_idx = 0 ;
151123 fixme_idx = 0 ;
152124 }
153125 }
154126
155- Seeking :: Issue {
156- todo_idx,
157- fixme_idx,
158- }
127+ Seeking :: Issue { fixme_idx }
159128 }
160129
161130 fn inspect_number (
@@ -206,20 +175,18 @@ impl BadIssueSeeker {
206175#[ test]
207176fn find_unnumbered_issue ( ) {
208177 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 ) ;
210179 assert_eq ! (
211180 Some ( failing_pos) ,
212181 text. find( |c| seeker. inspect( c) . is_some( ) )
213182 ) ;
214183 }
215184
216185 fn check_pass ( text : & str ) {
217- let mut seeker = BadIssueSeeker :: new ( ReportTactic :: Unnumbered , ReportTactic :: Unnumbered ) ;
186+ let mut seeker = BadIssueSeeker :: new ( ReportTactic :: Unnumbered ) ;
218187 assert_eq ! ( None , text. find( |c| seeker. inspect( c) . is_some( ) ) ) ;
219188 }
220189
221- check_fail ( "TODO\n " , 4 ) ;
222- check_pass ( " TO FIX DOME\n " ) ;
223190 check_fail ( " \n FIXME\n " , 8 ) ;
224191 check_fail ( "FIXME(\n " , 6 ) ;
225192 check_fail ( "FIXME(#\n " , 7 ) ;
@@ -228,71 +195,28 @@ fn find_unnumbered_issue() {
228195 check_pass ( "FIXME(#1222)\n " ) ;
229196 check_fail ( "FIXME(#12\n 22)\n " , 9 ) ;
230197 check_pass ( "FIXME(@maintainer, #1222, hello)\n " ) ;
231- check_fail ( "TODO(#22) FIXME\n " , 15 ) ;
232198}
233199
234200#[ test]
235201fn 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) ;
238204 text. chars ( ) . any ( |c| seeker. inspect ( c) . is_some ( ) )
239205 }
240206
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 ) ) ;
264208
265209 assert ! ( is_bad_issue(
266210 "This is a FixMe(#1) mixed case\n " ,
267- ReportTactic :: Never ,
268211 ReportTactic :: Always ,
269212 ) ) ;
270213
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 ) ) ;
276215}
277216
278217#[ test]
279218fn 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 ) ;
296220 let expected = Some ( Issue {
297221 issue_type : IssueType :: Fixme ,
298222 missing_number : true ,
0 commit comments