harper_core/linting/to_two_too/
mod.rs

1mod to_too_adjective_end;
2mod to_too_adjective_punct;
3mod to_too_adjverb_ed_punct;
4mod to_too_adverb;
5mod to_too_chunk_start_comma;
6mod to_too_degree_words;
7mod to_too_eos;
8mod to_too_pronoun_end;
9mod too_to;
10
11use super::merge_linters::merge_linters;
12use super::{ExprLinter, Lint, LintKind, Suggestion};
13use to_too_adjective_end::ToTooAdjectiveEnd;
14use to_too_adjective_punct::ToTooAdjectivePunct;
15use to_too_adjverb_ed_punct::ToTooAdjVerbEdPunct;
16use to_too_adverb::ToTooAdverb;
17use to_too_chunk_start_comma::ToTooChunkStartComma;
18use to_too_degree_words::ToTooDegreeWords;
19use to_too_eos::ToTooEos;
20use to_too_pronoun_end::ToTooPronounEnd;
21use too_to::TooTo;
22
23merge_linters!(
24    ToTwoToo =>
25        ToTooAdjectiveEnd,
26        ToTooAdjectivePunct,
27        ToTooAdverb,
28        ToTooAdjVerbEdPunct,
29        ToTooChunkStartComma,
30        ToTooDegreeWords,
31        ToTooPronounEnd,
32        ToTooEos,
33        TooTo
34    => "Corrects homophone confusion between `to` and `too`."
35);
36
37#[cfg(test)]
38mod tests {
39    use crate::linting::tests::{assert_lint_count, assert_no_lints, assert_suggestion_result};
40
41    use super::ToTwoToo;
42
43    #[test]
44    fn fixes_to_ambitious() {
45        assert_suggestion_result(
46            "The project scope is to ambitious",
47            ToTwoToo::default(),
48            "The project scope is too ambitious",
49        );
50    }
51
52    #[test]
53    fn fixes_end_of_sent() {
54        assert_suggestion_result(
55            "She wants ice cream, to.",
56            ToTwoToo::default(),
57            "She wants ice cream, too.",
58        );
59    }
60
61    #[test]
62    fn flags_to_hungry() {
63        assert_lint_count("I am to hungry.", ToTwoToo::default(), 1);
64    }
65
66    #[test]
67    fn no_lint_on_proper_too() {
68        assert_no_lints("I am too hungry.", ToTwoToo::default());
69    }
70
71    #[test]
72    fn flags_to_with_irregular_whitespace() {
73        assert_lint_count("She was to\t   tired.", ToTwoToo::default(), 1);
74        assert_lint_count("He felt it was\nto cold.", ToTwoToo::default(), 1);
75    }
76
77    #[test]
78    fn flags_to_with_trailing_punct() {
79        assert_lint_count("He spoke to loud!", ToTwoToo::default(), 1);
80        assert_lint_count("He spoke to loud?", ToTwoToo::default(), 1);
81        assert_lint_count("He spoke to loud.", ToTwoToo::default(), 1);
82    }
83
84    #[test]
85    fn no_lint_to_eat() {
86        assert_no_lints(
87            "Please remember to eat your vegetables.",
88            ToTwoToo::default(),
89        );
90    }
91
92    #[test]
93    fn no_lint_to_nashville_or_you() {
94        assert_no_lints("I’m going to Nashville next week.", ToTwoToo::default());
95        assert_no_lints("Talk to you later.", ToTwoToo::default());
96    }
97
98    #[test]
99    fn no_lint_distance_from_center() {
100        assert_no_lints("Distance from the center to any face", ToTwoToo::default());
101    }
102
103    #[test]
104    fn fixes_too_go() {
105        assert_suggestion_result(
106            "I want too go abroad.",
107            ToTwoToo::default(),
108            "I want to go abroad.",
109        );
110    }
111
112    #[test]
113    fn fixes_too_him() {
114        assert_suggestion_result(
115            "Give it too him as a gift",
116            ToTwoToo::default(),
117            "Give it to him as a gift",
118        );
119    }
120
121    #[test]
122    fn fixes_too_the() {
123        assert_suggestion_result(
124            "We're going too the conference.",
125            ToTwoToo::default(),
126            "We're going to the conference.",
127        );
128    }
129
130    #[test]
131    fn fixes_too_a() {
132        assert_suggestion_result(
133            "We're going too a concert.",
134            ToTwoToo::default(),
135            "We're going to a concert.",
136        );
137    }
138
139    #[test]
140    fn fixes_to_hard() {
141        assert_suggestion_result(
142            "It's not to hard, is it?",
143            ToTwoToo::default(),
144            "It's not too hard, is it?",
145        );
146    }
147
148    #[test]
149    fn no_lint_too_hot() {
150        assert_no_lints("The coffee is too hot to drink.", ToTwoToo::default());
151    }
152
153    #[test]
154    fn no_lint_too_loud() {
155        assert_no_lints(
156            "The music was too loud, making it hard to hear.",
157            ToTwoToo::default(),
158        );
159    }
160
161    #[test]
162    fn no_lint_too_shy() {
163        assert_no_lints("He's too shy to speak in public.", ToTwoToo::default());
164    }
165
166    #[test]
167    fn no_lint_too_sweet() {
168        assert_no_lints("The cake is too sweet for my taste.", ToTwoToo::default());
169    }
170
171    #[test]
172    fn no_lint_too_expensive() {
173        assert_no_lints(
174            "It's too expensive for me to buy right now.",
175            ToTwoToo::default(),
176        );
177    }
178
179    #[test]
180    fn no_lint_too_hard() {
181        assert_no_lints(
182            "She worked too hard and ended up getting sick.",
183            ToTwoToo::default(),
184        );
185    }
186
187    #[test]
188    fn no_lint_too_complicated() {
189        assert_no_lints(
190            "The instructions were too complicated to understand.",
191            ToTwoToo::default(),
192        );
193    }
194
195    #[test]
196    fn no_lint_too_too() {
197        assert_no_lints(
198            "I like apples, and my brother does too.",
199            ToTwoToo::default(),
200        );
201    }
202
203    #[test]
204    fn no_lint_too_too_2() {
205        assert_no_lints(
206            "She's coming to the party, and he is too.",
207            ToTwoToo::default(),
208        );
209    }
210
211    #[test]
212    fn no_lint_too_too_3() {
213        assert_no_lints(
214            "I want to go to the beach, and you do too?",
215            ToTwoToo::default(),
216        );
217    }
218
219    #[test]
220    fn no_lint_too_too_4() {
221        assert_no_lints(
222            "He's a talented musician, and a great friend too.",
223            ToTwoToo::default(),
224        );
225    }
226
227    #[test]
228    fn no_lint_too_too_5() {
229        assert_no_lints(
230            "The movie was good, and the popcorn was delicious too.",
231            ToTwoToo::default(),
232        );
233    }
234
235    #[test]
236    fn no_lint_too_difficult_too_close() {
237        assert_no_lints(
238            "The problem is too difficult, and the deadline is too close.",
239            ToTwoToo::default(),
240        );
241    }
242
243    #[test]
244    fn no_lint_too_good_too_nice() {
245        assert_no_lints(
246            "He's too good at the game, and he's too nice to win.",
247            ToTwoToo::default(),
248        );
249    }
250
251    #[test]
252    fn allow_young_musicians() {
253        assert_no_lints(
254            "Bringing Hope and Opportunity to Young Musicians",
255            ToTwoToo::default(),
256        );
257    }
258
259    #[test]
260    fn allow_semicolon() {
261        assert_no_lints("Attendees can look forward to:", ToTwoToo::default());
262    }
263
264    #[test]
265    fn allow_build_brighter() {
266        assert_no_lints(
267            "We're empowering them to build brighter futures.",
268            ToTwoToo::default(),
269        );
270    }
271
272    #[test]
273    fn allow_delegate() {
274        assert_no_lints(
275            "I’d like you to consciously delegate one task",
276            ToTwoToo::default(),
277        );
278    }
279
280    #[test]
281    fn no_lint_soundscapes() {
282        assert_no_lints(
283            "Soundscapes are not merely environmental features; they are integral to human identity and cultural expression.",
284            ToTwoToo::default(),
285        );
286    }
287
288    #[test]
289    fn no_lint_speed_flexibility() {
290        assert_no_lints(
291            "Its speed, flexibility, and seamless integration with FZF make it a compelling alternative to traditional fuzzy finding solutions.",
292            ToTwoToo::default(),
293        );
294    }
295
296    #[test]
297    fn no_lint_explicitly_cast() {
298        assert_no_lints(
299            "Attempted to explicitly cast the result back to a string",
300            ToTwoToo::default(),
301        );
302    }
303
304    #[test]
305    fn no_lint_buried_under_data() {
306        assert_no_lints(
307            "They felt buried under the data, unable to proactively address emerging threats.",
308            ToTwoToo::default(),
309        );
310    }
311
312    #[test]
313    fn no_lint_familiarize() {
314        assert_no_lints(
315            "Familiarize yourself with these resources to learn how to effectively utilize the plugin’s features.",
316            ToTwoToo::default(),
317        );
318    }
319
320    #[test]
321    fn no_lint_great_deal_of_energy() {
322        assert_no_lints(
323            "It takes a great deal of energy to consistently operate under that kind of pressure.",
324            ToTwoToo::default(),
325        );
326    }
327
328    #[test]
329    fn no_lint_occasionally_troubleshoot() {
330        assert_no_lints(
331            "Just be prepared to occasionally troubleshoot the debugger itself.",
332            ToTwoToo::default(),
333        );
334    }
335
336    #[test]
337    fn ccoveille_suggestion() {
338        assert_no_lints("He goes too far with bets.", ToTwoToo::default());
339    }
340
341    #[test]
342    fn no_lint_auto_detect_debuggers() {
343        assert_no_lints(
344            "Daprio attempts to auto-detect debugger servers and configurations, which can save significant time, especially for common languages.",
345            ToTwoToo::default(),
346        );
347    }
348
349    #[test]
350    fn no_lint_commitment_open_source() {
351        assert_no_lints(
352            "I believe a commitment to open-source solutions and internal skill development would ultimately yield a more sustainable and ethical approach.",
353            ToTwoToo::default(),
354        );
355    }
356
357    #[test]
358    fn no_lint_feeling_confident_dominate() {
359        assert_no_lints(
360            "I'm feeling confident, and I suspect you all should be too – because I’m about to dominate.",
361            ToTwoToo::default(),
362        );
363    }
364
365    #[test]
366    fn no_lint_egyptian_smiling_faces_commentary() {
367        assert_no_lints(
368            "Today I learned that the ubiquitous, seemingly cheerful faces carved into ancient Egyptian relief sculptures – often referred to as “smiling faces” – weren’t simply a stylistic choice reflecting happiness. Recent scholarship suggests they functioned as a subtle, often satirical, form of social commentary, particularly targeting individuals who were arrogant, boastful, or otherwise deserving of ridicule.",
369            ToTwoToo::default(),
370        );
371    }
372
373    #[test]
374    fn no_lint_intended_to_leave_it_to() {
375        assert_no_lints(
376            "Beatrice never explicitly said who she intended to leave it to.",
377            ToTwoToo::default(),
378        );
379    }
380
381    #[test]
382    fn no_lint_time_for_good_girl_to_bed() {
383        assert_no_lints("Time for this good girl to go to bed.", ToTwoToo::default());
384    }
385
386    #[test]
387    fn no_lint_connected_to_many_other_fields() {
388        assert_no_lints(
389            "The study is connected to many other fields.",
390            ToTwoToo::default(),
391        );
392    }
393
394    #[test]
395    fn no_lint_till_she_too_began_dreaming() {
396        assert_no_lints(
397            "till she too began dreaming after a fashion",
398            ToTwoToo::default(),
399        );
400    }
401
402    #[test]
403    fn no_lint_to_quickly_find_a_factory() {
404        assert_no_lints(
405            "To quickly find a factory, look for a map.",
406            ToTwoToo::default(),
407        );
408    }
409
410    #[test]
411    fn no_lint_llm_as_judge_to_automatically_score() {
412        assert_no_lints(
413            "We used an LLM-as-judge to automatically score agent trajectories.",
414            ToTwoToo::default(),
415        );
416    }
417
418    #[test]
419    fn no_lint_all_the_way_to_advanced_usage() {
420        assert_no_lints(
421            "All the way to advanced usage, like an expert.",
422            ToTwoToo::default(),
423        );
424    }
425
426    #[test]
427    fn no_lint_access_to_over_400_integrations() {
428        assert_no_lints(
429            "You'll have access to over 400 integrations.",
430            ToTwoToo::default(),
431        );
432    }
433
434    #[test]
435    fn no_lint_accustomed_to_precision() {
436        assert_no_lints("I’m rather accustomed to precision.", ToTwoToo::default());
437    }
438
439    #[test]
440    fn no_lint_prone_to_melancholy() {
441        assert_no_lints("He wasn’t a man prone to melancholy.", ToTwoToo::default());
442    }
443}