File tree Expand file tree Collapse file tree 2 files changed +22
-13
lines changed Expand file tree Collapse file tree 2 files changed +22
-13
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
11
11
12
12
- ` Default ` trait impl for ` PasFmtConfiguration ` .
13
13
14
+ ### Changed
15
+
16
+ - Error message when ` --mode=check ` fails on stdin, now reads ` <stdin> is incorrectly formatted ` .
17
+
14
18
### Added
15
19
16
20
- ` try_create ` and ` validate ` functions to the type generated by the ` pasfmt_config! ` macro.
Original file line number Diff line number Diff line change 1
1
use std:: borrow:: Cow ;
2
2
3
3
use crate :: { command_line:: FormatMode , file_formatter:: FileFormatter } ;
4
- use anyhow:: anyhow;
4
+ use anyhow:: { anyhow, bail } ;
5
5
use log:: LevelFilter ;
6
6
7
7
pub trait FormatterConfiguration {
@@ -30,21 +30,26 @@ fn check<T: FormatterConfiguration>(
30
30
config : & T ,
31
31
file_formatter : & FileFormatter ,
32
32
) -> anyhow:: Result < ( ) > {
33
- let check_results = if config. is_stdin ( ) {
34
- vec ! [ file_formatter. check_stdin( ) ]
33
+ if config. is_stdin ( ) {
34
+ if file_formatter. check_stdin ( ) . is_err ( ) {
35
+ bail ! ( "<stdin> is incorrectly formatted" ) ;
36
+ }
35
37
} else {
36
- file_formatter. check_files ( & config. get_paths ( ) ?)
37
- } ;
38
+ let fail_count = file_formatter
39
+ . check_files ( & config. get_paths ( ) ?)
40
+ . iter ( )
41
+ . filter ( |r| r. is_err ( ) )
42
+ . count ( ) ;
38
43
39
- let fail_count = check_results. iter ( ) . filter ( |r| r. is_err ( ) ) . count ( ) ;
40
- if fail_count > 0 {
41
- Err ( anyhow ! (
42
- "{fail_count} {} incorrectly formatted" ,
43
- plural( fail_count, "file is" , "files are" )
44
- ) )
45
- } else {
46
- Ok ( ( ) )
44
+ if fail_count > 0 {
45
+ bail ! (
46
+ "{fail_count} {} incorrectly formatted" ,
47
+ plural( fail_count, "file is" , "files are" )
48
+ )
49
+ }
47
50
}
51
+
52
+ Ok ( ( ) )
48
53
}
49
54
50
55
pub struct FormattingOrchestrator ;
You can’t perform that action at this time.
0 commit comments