@@ -5,7 +5,6 @@ use std::{fs, process};
55use anyhow:: Result ;
66use clap:: Parser ;
77use ignore:: Walk ;
8- use imara_diff:: { Algorithm , BasicLineDiffPrinter , Diff , InternedInput , UnifiedDiffConfig } ;
98use regex:: Regex ;
109
1110#[ derive( Parser ) ]
@@ -18,8 +17,6 @@ struct Cli {
1817 /// Applies to lines that are to be split
1918 #[ arg( long, default_value_t = 100 ) ]
2019 line_length_limit : usize ,
21- #[ arg( long) ]
22- show_diff : bool ,
2320}
2421
2522static REGEX_IGNORE_END : LazyLock < Regex > =
@@ -54,10 +51,6 @@ fn main() -> Result<()> {
5451 } else if cli. overwrite {
5552 fs:: write ( & path, new) ?;
5653 made_compliant. push ( path. clone ( ) ) ;
57- } else if cli. show_diff {
58- println ! ( "{}:" , path. display( ) ) ;
59- show_diff ( & old, & new) ;
60- println ! ( "---" ) ;
6154 } else {
6255 not_compliant. push ( path. clone ( ) ) ;
6356 }
@@ -76,16 +69,6 @@ fn main() -> Result<()> {
7669 Ok ( ( ) )
7770}
7871
79- fn show_diff ( old : & str , new : & str ) {
80- let input = InternedInput :: new ( old, new) ;
81- let mut diff = Diff :: compute ( Algorithm :: Histogram , & input) ;
82- diff. postprocess_lines ( & input) ;
83- let diff = diff
84- . unified_diff ( & BasicLineDiffPrinter ( & input. interner ) , UnifiedDiffConfig :: default ( ) , & input)
85- . to_string ( ) ;
86- print ! ( "{diff}" ) ;
87- }
88-
8972fn display ( header : & str , paths : & [ PathBuf ] ) {
9073 println ! ( "{header}:" ) ;
9174 for element in paths {
@@ -96,7 +79,9 @@ fn display(header: &str, paths: &[PathBuf]) {
9679fn ignore ( line : & str , in_code_block : bool ) -> bool {
9780 in_code_block
9881 || line. to_lowercase ( ) . contains ( "e.g." )
82+ || line. to_lowercase ( ) . contains ( "n.b." )
9983 || line. contains ( "i.e." )
84+ || line. contains ( "et. al" )
10085 || line. contains ( '|' )
10186 || line. trim_start ( ) . starts_with ( '>' )
10287 || line. starts_with ( '#' )
@@ -213,6 +198,9 @@ some code. block
213198sentence with *italics* should not be ignored. truly.
214199git log main.. compiler
215200 foo. bar. baz
201+ o? whatever
202+ r? @reviewer
203+ r? @reviewer
216204" ;
217205 let expected = "
218206# some. heading
@@ -238,12 +226,16 @@ git log main.. compiler
238226 foo.
239227 bar.
240228 baz
229+ o?
230+ whatever
231+ r? @reviewer
232+ r? @reviewer
241233" ;
242234 assert_eq ! ( expected, comply( original) ) ;
243235}
244236
245237#[ test]
246- fn test_prettify ( ) {
238+ fn test_lengthen_lines ( ) {
247239 let original = "\
248240 do not split
249241short sentences
@@ -264,6 +256,12 @@ do not mess with code block chars
264256leave the
265257text alone
266258```
259+
260+ handle the
261+ indented well
262+
263+ [a target]: https://example.com
264+ [another target]: https://example.com
267265" ;
268266 let expected = "\
269267 do not split short sentences
@@ -284,43 +282,11 @@ do not mess with code block chars
284282leave the
285283text alone
286284```
287- " ;
288- assert_eq ! ( expected, lengthen_lines( original, 50 ) ) ;
289- }
290285
291- #[ test]
292- fn test_prettify_prefix_spaces ( ) {
293- let original = "\
294- do not split
295- short sentences
296- " ;
297- let expected = "\
298- do not split short sentences
299- " ;
300- assert_eq ! ( expected, lengthen_lines( original, 50 ) ) ;
301- }
286+ handle the indented well
302287
303- #[ test]
304- fn test_prettify_ignore_link_targets ( ) {
305- let original = "\
306288[a target]: https://example.com
307289[another target]: https://example.com
308290" ;
309- assert_eq ! ( original, lengthen_lines( original, 100 ) ) ;
310- }
311-
312- #[ test]
313- fn test_sembr_question_mark ( ) {
314- let original = "
315- o? whatever
316- r? @reviewer
317- r? @reviewer
318- " ;
319- let expected = "
320- o?
321- whatever
322- r? @reviewer
323- r? @reviewer
324- " ;
325- assert_eq ! ( expected, comply( original) ) ;
291+ assert_eq ! ( expected, lengthen_lines( original, 50 ) ) ;
326292}
0 commit comments