@@ -48,6 +48,16 @@ fn get_linter_list() -> Vec<&'static Linter> {
48
48
name: "std_filesystem" ,
49
49
lint_fn: lint_std_filesystem
50
50
} ,
51
+ & Linter {
52
+ description: "Check that fatal assertions are not used in RPC code" ,
53
+ name: "rpc_assert" ,
54
+ lint_fn: lint_rpc_assert
55
+ } ,
56
+ & Linter {
57
+ description: "Check that boost assertions are not used" ,
58
+ name: "boost_assert" ,
59
+ lint_fn: lint_boost_assert
60
+ } ,
51
61
& Linter {
52
62
description: "Check that release note snippets are in the right folder" ,
53
63
name: "doc_release_note_snippets" ,
@@ -237,7 +247,7 @@ fn lint_py_lint() -> LintResult {
237
247
"F822" , // undefined name name in __all__
238
248
"F823" , // local variable name … referenced before assignment
239
249
"F841" , // local variable 'foo' is assigned to but never used
240
- "PLE" , // Pylint errors
250
+ "PLE" , // Pylint errors
241
251
"W191" , // indentation contains tabs
242
252
"W291" , // trailing whitespace
243
253
"W292" , // no newline at end of file
@@ -273,6 +283,7 @@ fn lint_std_filesystem() -> LintResult {
273
283
let found = git ( )
274
284
. args ( [
275
285
"grep" ,
286
+ "--line-number" ,
276
287
"std::filesystem" ,
277
288
"--" ,
278
289
"./src/" ,
@@ -293,6 +304,62 @@ fs:: namespace, which has unsafe filesystem functions marked as deleted.
293
304
}
294
305
}
295
306
307
+ fn lint_rpc_assert ( ) -> LintResult {
308
+ let found = git ( )
309
+ . args ( [
310
+ "grep" ,
311
+ "--line-number" ,
312
+ "--extended-regexp" ,
313
+ r"\<(A|a)ss(ume|ert)\(" ,
314
+ "--" ,
315
+ "src/rpc/" ,
316
+ "src/wallet/rpc*" ,
317
+ ":(exclude)src/rpc/server.cpp" ,
318
+ // src/rpc/server.cpp is excluded from this check since it's mostly meta-code.
319
+ ] )
320
+ . status ( )
321
+ . expect ( "command error" )
322
+ . success ( ) ;
323
+ if found {
324
+ Err ( r#"
325
+ ^^^
326
+ CHECK_NONFATAL(condition) or NONFATAL_UNREACHABLE should be used instead of assert for RPC code.
327
+
328
+ Aborting the whole process is undesirable for RPC code. So nonfatal
329
+ checks should be used over assert. See: src/util/check.h
330
+ "#
331
+ . to_string ( ) )
332
+ } else {
333
+ Ok ( ( ) )
334
+ }
335
+ }
336
+
337
+ fn lint_boost_assert ( ) -> LintResult {
338
+ let found = git ( )
339
+ . args ( [
340
+ "grep" ,
341
+ "--line-number" ,
342
+ "--extended-regexp" ,
343
+ r"BOOST_ASSERT\(" ,
344
+ "--" ,
345
+ "*.cpp" ,
346
+ "*.h" ,
347
+ ] )
348
+ . status ( )
349
+ . expect ( "command error" )
350
+ . success ( ) ;
351
+ if found {
352
+ Err ( r#"
353
+ ^^^
354
+ BOOST_ASSERT must be replaced with Assert, BOOST_REQUIRE, or BOOST_CHECK to avoid an unnecessary
355
+ include of the boost/assert.hpp dependency.
356
+ "#
357
+ . to_string ( ) )
358
+ } else {
359
+ Ok ( ( ) )
360
+ }
361
+ }
362
+
296
363
fn lint_doc_release_note_snippets ( ) -> LintResult {
297
364
let non_release_notes = check_output ( git ( ) . args ( [
298
365
"ls-files" ,
@@ -593,7 +660,7 @@ fn main() -> ExitCode {
593
660
"{err}\n ^---- ⚠️ Failure generated from lint check '{}'!" ,
594
661
linter. name
595
662
) ;
596
- println ! ( "{}" , linter. description) ;
663
+ println ! ( "{}\n \n " , linter. description) ;
597
664
test_failed = true ;
598
665
}
599
666
}
0 commit comments