@@ -219,12 +219,7 @@ fn to_diagnostic(map: &mut BTreeMap<String, Vec<Warning>>, args: Vec<String>) {
219
219
let json_filename = format ! ( "{diagnostics_folder}/diagnostics.json" ) ;
220
220
let p = std:: path:: Path :: new ( json_filename. as_str ( ) ) ;
221
221
if !p. exists ( ) {
222
- let mut cargo = "cargo" ;
223
- if std:: path:: Path :: new ( "x.py" ) . exists ( ) {
224
- cargo = "./x.py" ;
225
- } else if std:: path:: Path :: new ( "miri" ) . exists ( ) {
226
- cargo = "./miri" ;
227
- }
222
+ let cargo = get_cargo ( ) ;
228
223
if let Ok ( mut command) = Command :: new ( cargo)
229
224
. args ( args)
230
225
. stdout ( Stdio :: piped ( ) )
@@ -289,6 +284,16 @@ fn to_diagnostic(map: &mut BTreeMap<String, Vec<Warning>>, args: Vec<String>) {
289
284
}
290
285
}
291
286
287
+ fn get_cargo ( ) -> & ' static str {
288
+ let mut cargo = "cargo" ;
289
+ if std:: path:: Path :: new ( "x.py" ) . exists ( ) {
290
+ cargo = "./x.py" ;
291
+ } else if std:: path:: Path :: new ( "miri" ) . exists ( ) {
292
+ cargo = "./miri" ;
293
+ }
294
+ cargo
295
+ }
296
+
292
297
fn get_folder ( ) -> String {
293
298
let mut folder = "." . to_string ( ) ;
294
299
let v = get_args ( ) ;
@@ -389,6 +394,35 @@ fn diagnose_all_warnings(flags: Vec<String>) -> BTreeMap<String, Vec<Warning>> {
389
394
map
390
395
}
391
396
397
+ fn count ( map : BTreeMap < String , Vec < Warning > > ) -> usize
398
+ {
399
+ let mut sum: usize = 0 ;
400
+ map. iter ( ) . for_each ( |( k, v) |{
401
+ sum = sum. saturating_add ( v. len ( ) ) ;
402
+ } ) ;
403
+ sum
404
+ }
405
+
406
+ fn clippy_fix ( ) -> usize
407
+ {
408
+ let folder = get_folder ( ) ;
409
+ let manifest = format ! ( "{folder}/Cargo.toml" ) ;
410
+ let args = vec ! [
411
+ "clippy" . to_string( ) ,
412
+ "--message-format=json" . to_string( ) ,
413
+ "--manifest-path" . to_string( ) ,
414
+ manifest,
415
+ "--fix" . to_string( ) ,
416
+ "--allow-dirty" . to_string( ) ,
417
+ "--allow-no-vcs" . to_string( ) ,
418
+ "--broken-code" . to_string( ) ,
419
+ "--" . to_string( ) ,
420
+ ] ;
421
+ let mut map: BTreeMap < String , Vec < Warning > > = BTreeMap :: new ( ) ;
422
+ to_diagnostic ( & mut map, args) ;
423
+ count ( map)
424
+ }
425
+
392
426
// run the following bash commands
393
427
// ```bash
394
428
// git checkout $commit_id
@@ -502,8 +536,10 @@ fn fprint_warning_count(file: String, all_warnings: BTreeMap<String, Vec<Warning
502
536
all_warnings. iter ( ) . for_each ( |( _k, v) | {
503
537
count = count. saturating_add ( v. len ( ) ) ;
504
538
} ) ;
539
+ let remained = clippy_fix ( ) ;
505
540
if let Ok ( mut file) = open_file_to_write ( file) {
506
- file. write_all ( format ! ( "There are {} warnings in {} files.\n " , count, all_warnings. len( ) ) . as_bytes ( ) ) . ok ( ) ;
541
+ file. write_all ( format ! ( "There are {} warnings in {} files, {} has been fixed.\n " ,
542
+ count, all_warnings. len( ) , count. saturating_sub( remained) ) . as_bytes ( ) ) . ok ( ) ;
507
543
}
508
544
}
509
545
@@ -1177,7 +1213,7 @@ fn main() {
1177
1213
let diagnostics_folder = get_diagnostics_folder ( ) ;
1178
1214
if let Ok ( s) = read_to_string ( format ! ( "{diagnostics_folder}/diagnostics.log" ) ) {
1179
1215
assert_eq ! ( s,
1180
- r###"There are 1 warnings in 1 files.
1216
+ r###"There are 1 warnings in 1 files, 0 has been fixed .
1181
1217
##[Warning(clippy::unwrap_used)
1182
1218
@@ -3,2 +3,3 @@ fn main() {
1183
1219
- let s = std::fs::read_to_string("Cargo.toml").unwrap();
@@ -1240,7 +1276,7 @@ fn main() {
1240
1276
if let Ok ( s) = read_to_string ( format ! ( "{diagnostics_folder}/diagnostics.log" ) ) {
1241
1277
assert_eq ! (
1242
1278
s,
1243
- r###"There are 1 warnings in 1 files.
1279
+ r###"There are 1 warnings in 1 files, 0 has been fixed .
1244
1280
##[Warning(clippy::unwrap_used)
1245
1281
@@ -3,2 +3,3 @@ fn main() {
1246
1282
let s = std::fs::read_to_string("Cargo.toml").unwrap();
@@ -1386,7 +1422,7 @@ fn main() {
1386
1422
}
1387
1423
}
1388
1424
"# ,
1389
- r###"There are 1 warnings in 1 files.
1425
+ r###"There are 1 warnings in 1 files, 0 has been fixed .
1390
1426
##[Warning(clippy::unwrap_used)
1391
1427
fn main() {
1392
1428
@@ -1430,7 +1466,7 @@ fn main() {
1430
1466
}
1431
1467
}
1432
1468
"# ,
1433
- r###"There are 1 warnings in 1 files.
1469
+ r###"There are 1 warnings in 1 files, 0 has been fixed .
1434
1470
##[Warning(clippy::unwrap_used)
1435
1471
fn main() {
1436
1472
@@ -1470,7 +1506,7 @@ fn main() {
1470
1506
}
1471
1507
}
1472
1508
"# ,
1473
- r###"There are 1 warnings in 1 files.
1509
+ r###"There are 1 warnings in 1 files, 0 has been fixed .
1474
1510
##[Warning(clippy::unwrap_used)
1475
1511
fn main() {
1476
1512
@@ -1511,7 +1547,7 @@ fn main() {
1511
1547
}
1512
1548
}
1513
1549
"# ,
1514
- r###"There are 1 warnings in 1 files.
1550
+ r###"There are 1 warnings in 1 files, 0 has been fixed .
1515
1551
##[Warning(clippy::unwrap_used)
1516
1552
fn main() {
1517
1553
@@ -1576,7 +1612,7 @@ fn main() {
1576
1612
if let Ok ( s) = read_to_string ( format ! ( "{diagnostics_folder}/diagnostics.log" ) ) {
1577
1613
assert_eq ! (
1578
1614
s,
1579
- r###"There are 1 warnings in 1 files.
1615
+ r###"There are 1 warnings in 1 files, 0 has been fixed .
1580
1616
"###
1581
1617
) ;
1582
1618
}
@@ -1699,7 +1735,7 @@ fn main() {
1699
1735
"2468ad1e3c0183f4a94859bcc5cea04ee3fc4ab1" ,
1700
1736
rd_run
1701
1737
) ,
1702
- "There are 30 warnings in 1 files.\n "
1738
+ "There are 30 warnings in 1 files, 0 has been fixed .\n "
1703
1739
) ;
1704
1740
}
1705
1741
@@ -1711,7 +1747,7 @@ fn main() {
1711
1747
patch: Some ( "375981bb06cf819332c202cdd09d5a8c48e296db" . to_string( ) ) ,
1712
1748
flags: vec![ ] , confirm: true , pair: false , function: false , single: true , location: false , mixed: false } ,
1713
1749
"512236bac29f09ca798c93020ce377c30a4ed2a5" , rd_run) , @r###"
1714
- There are 30 warnings in 1 files.
1750
+ There are 30 warnings in 1 files, 0 has been fixed .
1715
1751
##[Warning(clippy::len_zero)
1716
1752
@@ -107 +107 @@ fn remove_previously_generated_files() {
1717
1753
- if output.len() != 0 {
@@ -1721,7 +1757,7 @@ fn main() {
1721
1757
patch: Some ( "375981bb06cf819332c202cdd09d5a8c48e296db" . to_string( ) ) ,
1722
1758
flags: vec![ ] , confirm: true , pair: true , function: false , single: true , location: false , mixed: false } ,
1723
1759
"512236bac29f09ca798c93020ce377c30a4ed2a5" , rd_run) , @r###"
1724
- There are 30 warnings in 1 files.
1760
+ There are 30 warnings in 1 files, 0 has been fixed .
1725
1761
##[Warning(clippy::len_zero)
1726
1762
@@ -107 +107 @@ fn remove_previously_generated_files() {
1727
1763
if output.len() != 0 {
@@ -1732,7 +1768,7 @@ fn main() {
1732
1768
patch: Some ( "375981bb06cf819332c202cdd09d5a8c48e296db" . to_string( ) ) ,
1733
1769
flags: vec![ ] , confirm: true , pair: true , function: true , single: true , location: false , mixed: false } ,
1734
1770
"512236bac29f09ca798c93020ce377c30a4ed2a5" , rd_run) , @r###"
1735
- There are 30 warnings in 1 files.
1771
+ There are 30 warnings in 1 files, 0 has been fixed .
1736
1772
##[Warning(clippy::len_zero)
1737
1773
fn remove_previously_generated_files() {
1738
1774
let command = Command::new("find")
@@ -1788,7 +1824,7 @@ fn main() {
1788
1824
patch: Some ( "375981bb06cf819332c202cdd09d5a8c48e296db" . to_string( ) ) ,
1789
1825
flags: vec![ ] , confirm: true , pair: false , function: false , single: true , location: false , mixed: false } ,
1790
1826
"512236bac29f09ca798c93020ce377c30a4ed2a5" , rd_run) , @r###"
1791
- There are 30 warnings in 1 files.
1827
+ There are 30 warnings in 1 files, 0 has been fixed .
1792
1828
##[Warning(clippy::len_zero)
1793
1829
@@ -107 +107 @@ fn remove_previously_generated_files() {
1794
1830
- if output.len() != 0 {
@@ -1798,7 +1834,7 @@ fn main() {
1798
1834
patch: Some ( "375981bb06cf819332c202cdd09d5a8c48e296db" . to_string( ) ) ,
1799
1835
flags: vec![ ] , confirm: true , pair: true , function: false , single: true , location: false , mixed: false } ,
1800
1836
"512236bac29f09ca798c93020ce377c30a4ed2a5" , rd_run) , @r###"
1801
- There are 30 warnings in 1 files.
1837
+ There are 30 warnings in 1 files, 0 has been fixed .
1802
1838
##[Warning(clippy::len_zero)
1803
1839
@@ -107 +107 @@ fn remove_previously_generated_files() {
1804
1840
if output.len() != 0 {
@@ -1809,7 +1845,7 @@ fn main() {
1809
1845
patch: Some ( "375981bb06cf819332c202cdd09d5a8c48e296db" . to_string( ) ) ,
1810
1846
flags: vec![ ] , confirm: true , pair: true , function: true , single: true , location: false , mixed: false } ,
1811
1847
"512236bac29f09ca798c93020ce377c30a4ed2a5" , rd_run) , @r###"
1812
- There are 30 warnings in 1 files.
1848
+ There are 30 warnings in 1 files, 0 has been fixed .
1813
1849
##[Warning(clippy::len_zero)
1814
1850
fn remove_previously_generated_files() {
1815
1851
let command = Command::new("find")
@@ -1866,13 +1902,13 @@ fn main() {
1866
1902
patch: Some ( "035ef892fa57fe644ef76065849ebd025869614d" . to_string( ) ) ,
1867
1903
flags: vec![ ] , confirm: false , pair: false , function: false , single: true , location: false , mixed: false } ,
1868
1904
"375981bb06cf819332c202cdd09d5a8c48e296db" , rd_run) , @r###"
1869
- There are 27 warnings in 1 files.
1905
+ There are 27 warnings in 1 files, 0 has been fixed .
1870
1906
"### ) ;
1871
1907
insta:: assert_snapshot!( rd_setup( temp_dir. clone( ) , Args { folder: Some ( temp_dir) ,
1872
1908
patch: Some ( "035ef892fa57fe644ef76065849ebd025869614d" . to_string( ) ) ,
1873
1909
flags: vec![ ] , confirm: true , pair: true , function: true , single: true , location: false , mixed: false } ,
1874
1910
"375981bb06cf819332c202cdd09d5a8c48e296db" , rd_run) , @r###"
1875
- There are 27 warnings in 1 files.
1911
+ There are 27 warnings in 1 files, 0 has been fixed .
1876
1912
"### ) ;
1877
1913
}
1878
1914
0 commit comments