2
2
#![ warn( missing_docs, unreachable_pub, unused, rust_2021_compatibility) ]
3
3
#![ warn( clippy:: all, clippy:: pedantic, clippy:: cargo, clippy:: nursery) ]
4
4
5
+ use colored:: Colorize ;
5
6
use grep:: {
6
7
matcher:: Matcher ,
7
8
regex:: RegexMatcher ,
@@ -39,8 +40,8 @@ impl Config {
39
40
2 => match args[ 1 ] . as_str ( ) {
40
41
"fmt" => Ok ( Self { mode : Mode :: Format } ) ,
41
42
"check" => Ok ( Self { mode : Mode :: Check } ) ,
42
- "version" => Ok ( Self { mode : Mode :: Version } ) ,
43
- _ => Err ( "Unrecognized mode" ) ,
43
+ "-- version" | "-v " => Ok ( Self { mode : Mode :: Version } ) ,
44
+ _ => Err ( "Unrecognized mode: Must be 'fmt', 'check', or '--version' " ) ,
44
45
} ,
45
46
_ => Err ( "Too many arguments" ) ,
46
47
}
@@ -80,7 +81,12 @@ fn version() {
80
81
81
82
fn fmt ( taplo_opts : taplo:: formatter:: Options ) -> Result < ( ) , Box < dyn Error > > {
82
83
// Format Solidity with forge
83
- process:: Command :: new ( "forge" ) . arg ( "fmt" ) . output ( ) . expect ( "forge fmt failed" ) ;
84
+ let forge_status = process:: Command :: new ( "forge" ) . arg ( "fmt" ) . output ( ) ?;
85
+
86
+ // Print any warnings/errors from `forge fmt`.
87
+ if !forge_status. stderr . is_empty ( ) {
88
+ print ! ( "{}" , String :: from_utf8( forge_status. stderr) ?) ;
89
+ }
84
90
85
91
// Format `foundry.toml` with taplo.
86
92
let config_orig = fs:: read_to_string ( "./foundry.toml" ) ?;
@@ -109,15 +115,22 @@ fn check(taplo_opts: taplo::formatter::Options) -> Result<(), Box<dyn Error>> {
109
115
fn validate_fmt ( taplo_opts : taplo:: formatter:: Options ) -> Result < ( ) , Box < dyn Error > > {
110
116
// Check Solidity with `forge fmt`
111
117
let forge_status = process:: Command :: new ( "forge" ) . arg ( "fmt" ) . arg ( "--check" ) . output ( ) ?;
112
- let forge_ok = forge_status. status . success ( ) ;
118
+
119
+ // Print any warnings/errors from `forge fmt`.
120
+ let stderr = String :: from_utf8 ( forge_status. stderr ) ?;
121
+ let forge_ok = forge_status. status . success ( ) && stderr. is_empty ( ) ;
122
+ print ! ( "{stderr}" ) ; // Prints nothing if stderr is empty.
113
123
114
124
// Check TOML with `taplo fmt`
115
125
let config_orig = fs:: read_to_string ( "./foundry.toml" ) ?;
116
126
let config_fmt = taplo:: formatter:: format ( & config_orig, taplo_opts) ;
117
127
let taplo_ok = config_orig == config_fmt;
118
128
119
129
if !forge_ok || !taplo_ok {
120
- eprintln ! ( "Error: Formatting failed, run `scopelint fmt` to fix" ) ;
130
+ eprintln ! (
131
+ "{}: Formatting validation failed, run `scopelint fmt` to fix" ,
132
+ "error" . bold( ) . red( )
133
+ ) ;
121
134
return Err ( "Invalid fmt found" . into ( ) )
122
135
}
123
136
Ok ( ( ) )
@@ -128,8 +141,8 @@ fn validate_names() -> Result<(), Box<dyn Error>> {
128
141
let results = validate ( paths) ?;
129
142
130
143
if !results. is_valid ( ) {
131
- eprintln ! ( "{results}" ) ;
132
- eprintln ! ( "Error : Naming conventions failed, see details above" ) ;
144
+ eprint ! ( "{results}" ) ;
145
+ eprintln ! ( "{} : Naming conventions failed, see details above" , "error" . bold ( ) . red ( ) ) ;
133
146
return Err ( "Invalid names found" . into ( ) )
134
147
}
135
148
Ok ( ( ) )
@@ -153,18 +166,18 @@ impl InvalidItem {
153
166
fn description ( & self ) -> String {
154
167
match self . kind {
155
168
Validator :: Test => {
156
- format ! ( "Invalid test name in {} on line {}: {}\n " , self . file, self . line, self . text)
169
+ format ! ( "Invalid test name in {} on line {}: {}" , self . file, self . line, self . text)
157
170
}
158
171
Validator :: Constant => {
159
172
format ! (
160
- "Invalid constant or immutable name in {} on line {}: {}\n " ,
173
+ "Invalid constant or immutable name in {} on line {}: {}" ,
161
174
self . file, self . line, self . text
162
175
)
163
176
}
164
- Validator :: Script => format ! ( "Invalid script interface in {}\n " , self . file) ,
177
+ Validator :: Script => format ! ( "Invalid script interface in {}" , self . file) ,
165
178
Validator :: Src => {
166
179
format ! (
167
- "Invalid src method name in {} on line {}: {}\n " ,
180
+ "Invalid src method name in {} on line {}: {}" ,
168
181
self . file, self . line, self . text
169
182
)
170
183
}
@@ -182,16 +195,16 @@ struct ValidationResults {
182
195
impl fmt:: Display for ValidationResults {
183
196
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
184
197
for item in & self . invalid_tests {
185
- write ! ( f, "{}" , item. description( ) ) ?;
198
+ writeln ! ( f, "{}" , item. description( ) ) ?;
186
199
}
187
200
for item in & self . invalid_constants {
188
- write ! ( f, "{}" , item. description( ) ) ?;
201
+ writeln ! ( f, "{}" , item. description( ) ) ?;
189
202
}
190
203
for item in & self . invalid_scripts {
191
- write ! ( f, "{}" , item. description( ) ) ?;
204
+ writeln ! ( f, "{}" , item. description( ) ) ?;
192
205
}
193
206
for item in & self . invalid_src {
194
- write ! ( f, "{}" , item. description( ) ) ?;
207
+ writeln ! ( f, "{}" , item. description( ) ) ?;
195
208
}
196
209
Ok ( ( ) )
197
210
}
0 commit comments