@@ -154,3 +154,67 @@ fn test_rust_struct() {
154154 assert_eq ! ( result. locations, expect. locations) ;
155155 }
156156}
157+
158+ #[ test]
159+ fn test_rust_trait_impl_function_names_not_checked ( ) {
160+ // https://github.com/blopker/codebook/issues/225
161+ // Function names in `impl Trait for Type` blocks should not be spell-checked
162+ // because the names are dictated by the trait, not the implementor.
163+ utils:: init_logging ( ) ;
164+ let processor = utils:: get_processor ( ) ;
165+ let sample_text = r#"
166+ struct MyType;
167+
168+ impl SomeTrait for MyType {
169+ fn spelling_erorr(self) {
170+ // This comment has a typo: tset
171+ }
172+ }
173+ "# ;
174+ let binding = processor
175+ . spell_check ( sample_text, Some ( LanguageType :: Rust ) , None )
176+ . to_vec ( ) ;
177+ let misspelled: Vec < & str > = binding. iter ( ) . map ( |r| r. word . as_str ( ) ) . collect ( ) ;
178+ println ! ( "Misspelled words: {misspelled:?}" ) ;
179+ // "erorr" in the function name should NOT be flagged (name dictated by trait)
180+ assert ! (
181+ !misspelled. contains( & "erorr" ) ,
182+ "Function names in trait impl blocks should not be spell-checked"
183+ ) ;
184+ // But comments inside the impl block should still be checked
185+ assert ! (
186+ misspelled. contains( & "tset" ) ,
187+ "Comments inside trait impl blocks should still be spell-checked"
188+ ) ;
189+ }
190+
191+ #[ test]
192+ fn test_rust_regular_impl_function_names_checked ( ) {
193+ // Regular impl blocks (not trait implementations) should still be spell-checked
194+ utils:: init_logging ( ) ;
195+ let processor = utils:: get_processor ( ) ;
196+ let sample_text = r#"
197+ struct MyType;
198+
199+ impl MyType {
200+ fn spelling_erorr(self) {}
201+ }
202+
203+ fn top_level_erorr() {}
204+ "# ;
205+ let binding = processor
206+ . spell_check ( sample_text, Some ( LanguageType :: Rust ) , None )
207+ . to_vec ( ) ;
208+ let misspelled: Vec < & str > = binding. iter ( ) . map ( |r| r. word . as_str ( ) ) . collect ( ) ;
209+ println ! ( "Misspelled words: {misspelled:?}" ) ;
210+ assert ! (
211+ misspelled. contains( & "erorr" ) ,
212+ "Expected 'erorr' to be flagged in regular impl and top-level functions"
213+ ) ;
214+ let erorr = binding. iter ( ) . find ( |r| r. word == "erorr" ) . unwrap ( ) ;
215+ assert_eq ! (
216+ erorr. locations. len( ) ,
217+ 2 ,
218+ "Expected 'erorr' flagged in both regular impl and top-level function"
219+ ) ;
220+ }
0 commit comments