1- use crate :: expr:: Expr ;
2- use crate :: expr:: SequenceExpr ;
3- use crate :: { Token , TokenKind } ;
1+ use crate :: Token ;
2+ use crate :: expr:: { Expr , SequenceExpr } ;
43
54use super :: { ExprLinter , Lint , LintKind , Suggestion } ;
65
@@ -12,15 +11,17 @@ impl Default for ProgressiveNeedsBe {
1211 fn default ( ) -> Self {
1312 // Support both contracted (I've/We've/You've/They've) and non-contracted
1413 // (I have/We have/You have/They have) forms before a progressive verb.
15- let contracted = SequenceExpr :: word_set ( & [ "I've" , "We've" , "You've" , "They've" ] )
16- . t_ws ( )
17- . then_kind_both ( TokenKind :: is_verb, TokenKind :: is_verb_progressive_form) ;
14+ let contracted = SequenceExpr :: word_set ( & [
15+ "I've" , "We've" , "You've" , "They've" , "Ive" , "Weve" , "Youve" , "Theyve" ,
16+ ] )
17+ . t_ws ( )
18+ . then_verb_progressive_form ( ) ;
1819
1920 let non_contracted = SequenceExpr :: word_set ( & [ "I" , "We" , "You" , "They" ] )
2021 . t_ws ( )
2122 . then_any_capitalization_of ( "have" )
2223 . t_ws ( )
23- . then_kind_both ( TokenKind :: is_verb , TokenKind :: is_verb_progressive_form ) ;
24+ . then_verb_progressive_form ( ) ;
2425
2526 let expr = SequenceExpr :: any_of ( vec ! [ Box :: new( contracted) , Box :: new( non_contracted) ] ) ;
2627
@@ -55,15 +56,14 @@ impl ExprLinter for ProgressiveNeedsBe {
5556 } ;
5657
5758 // Choose the correct "be" contraction based on the pronoun
58- let pronoun_str: String = first_word. span . get_content ( src) . iter ( ) . copied ( ) . collect ( ) ;
59- let lower = pronoun_str. to_lowercase ( ) ;
60- let progressive_replacement = if lower. starts_with ( "i" ) {
59+ let pronoun = first_word. span . get_content ( src) ;
60+ let progressive_replacement = if pronoun. starts_with_ignore_ascii_case_str ( "i" ) {
6161 "I'm"
62- } else if lower . starts_with ( "we" ) {
62+ } else if pronoun . starts_with_ignore_ascii_case_str ( "we" ) {
6363 "We're"
64- } else if lower . starts_with ( "you" ) {
64+ } else if pronoun . starts_with_ignore_ascii_case_str ( "you" ) {
6565 "You're"
66- } else if lower . starts_with ( "they" ) {
66+ } else if pronoun . starts_with_ignore_ascii_case_str ( "they" ) {
6767 "They're"
6868 } else {
6969 "I'm"
@@ -854,4 +854,57 @@ mod tests {
854854 "We're\n working on it today." ,
855855 ) ;
856856 }
857+
858+ //////////
859+
860+ #[ test]
861+ #[ ignore = "Handling the progressive `being` will need a special case" ]
862+ fn test_ive_being ( ) {
863+ assert_good_and_bad_suggestions (
864+ "I've being playing with languages.toml" ,
865+ ProgressiveNeedsBe :: default ( ) ,
866+ & [
867+ "I've been playing with languages.toml" ,
868+ "I'm playing with languages.toml" ,
869+ ] ,
870+ & [ ] ,
871+ ) ;
872+ }
873+
874+ #[ test]
875+ fn test_ive_doing_no_apostrophe ( ) {
876+ assert_suggestion_result (
877+ "Ive always seen the variables and debug into it, and thats what ive doing." ,
878+ ProgressiveNeedsBe :: default ( ) ,
879+ "Ive always seen the variables and debug into it, and thats what i'm doing." ,
880+ ) ;
881+ }
882+
883+ #[ test]
884+ fn test_ive_looking_no_apostrophe ( ) {
885+ assert_suggestion_result (
886+ "Ive looking for a way to get temperature and humidity for all of our rooms within for a reasonable price in Germany." ,
887+ ProgressiveNeedsBe :: default ( ) ,
888+ "I'm looking for a way to get temperature and humidity for all of our rooms within for a reasonable price in Germany." ,
889+ ) ;
890+ }
891+
892+ #[ test]
893+ #[ ignore = "Handling the progressive `being` will need a special case" ]
894+ fn test_youve_being ( ) {
895+ assert_suggestion_result (
896+ "Thanks for all the work you've being doing for this project btw!" ,
897+ ProgressiveNeedsBe :: default ( ) ,
898+ "Thanks for all the work you're doing for this project btw!" ,
899+ ) ;
900+ }
901+
902+ #[ test]
903+ fn test_theyve_doing ( ) {
904+ assert_suggestion_result (
905+ "it’s also kind of implied users read the documentation or generally have a sense of what they’ve doing and what could go wrong" ,
906+ ProgressiveNeedsBe :: default ( ) ,
907+ "it’s also kind of implied users read the documentation or generally have a sense of what they're doing and what could go wrong" ,
908+ ) ;
909+ }
857910}
0 commit comments