@@ -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/" ,
@@ -283,10 +294,66 @@ fn lint_std_filesystem() -> LintResult {
283
294
. success ( ) ;
284
295
if found {
285
296
Err ( r#"
286
- ^^^
287
297
Direct use of std::filesystem may be dangerous and buggy. Please include <util/fs.h> and use the
288
298
fs:: namespace, which has unsafe filesystem functions marked as deleted.
289
299
"#
300
+ . trim ( )
301
+ . to_string ( ) )
302
+ } else {
303
+ Ok ( ( ) )
304
+ }
305
+ }
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
+ CHECK_NONFATAL(condition) or NONFATAL_UNREACHABLE should be used instead of assert for RPC code.
326
+
327
+ Aborting the whole process is undesirable for RPC code. So nonfatal
328
+ checks should be used over assert. See: src/util/check.h
329
+ "#
330
+ . trim ( )
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
+ BOOST_ASSERT must be replaced with Assert, BOOST_REQUIRE, or BOOST_CHECK to avoid an unnecessary
354
+ include of the boost/assert.hpp dependency.
355
+ "#
356
+ . trim ( )
290
357
. to_string ( ) )
291
358
} else {
292
359
Ok ( ( ) )
@@ -303,17 +370,15 @@ fn lint_doc_release_note_snippets() -> LintResult {
303
370
if non_release_notes. is_empty ( ) {
304
371
Ok ( ( ) )
305
372
} else {
306
- Err ( format ! (
307
- r#"
308
- {}
309
- ^^^
373
+ println ! ( "{non_release_notes}" ) ;
374
+ Err ( r#"
310
375
Release note snippets and other docs must be put into the doc/ folder directly.
311
376
312
377
The doc/release-notes/ folder is for archived release notes of previous releases only. Snippets are
313
378
expected to follow the naming "/doc/release-notes-<PR number>.md".
314
- "# ,
315
- non_release_notes
316
- ) )
379
+ "#
380
+ . trim ( )
381
+ . to_string ( ) )
317
382
}
318
383
}
319
384
@@ -356,7 +421,6 @@ fn lint_trailing_whitespace() -> LintResult {
356
421
. success ( ) ;
357
422
if trailing_space {
358
423
Err ( r#"
359
- ^^^
360
424
Trailing whitespace (including Windows line endings [CR LF]) is problematic, because git may warn
361
425
about it, or editors may remove it by default, forcing developers in the future to either undo the
362
426
changes manually or spend time on review.
@@ -366,6 +430,7 @@ Thus, it is best to remove the trailing space now.
366
430
Please add any false positives, such as subtrees, Windows-related files, patch files, or externally
367
431
sourced files to the exclude list.
368
432
"#
433
+ . trim ( )
369
434
. to_string ( ) )
370
435
} else {
371
436
Ok ( ( ) )
@@ -382,14 +447,14 @@ fn lint_tabs_whitespace() -> LintResult {
382
447
. success ( ) ;
383
448
if tabs {
384
449
Err ( r#"
385
- ^^^
386
450
Use of tabs in this codebase is problematic, because existing code uses spaces and tabs will cause
387
451
display issues and conflict with editor settings.
388
452
389
453
Please remove the tabs.
390
454
391
455
Please add any false positives, such as subtrees, or externally sourced files to the exclude list.
392
456
"#
457
+ . trim ( )
393
458
. to_string ( ) )
394
459
} else {
395
460
Ok ( ( ) )
@@ -464,7 +529,6 @@ fn lint_includes_build_config() -> LintResult {
464
529
if missing {
465
530
return Err ( format ! (
466
531
r#"
467
- ^^^
468
532
One or more files use a symbol declared in the bitcoin-build-config.h header. However, they are not
469
533
including the header. This is problematic, because the header may or may not be indirectly
470
534
included. If the indirect include were to be intentionally or accidentally removed, the build could
@@ -480,12 +544,13 @@ include again.
480
544
#include <bitcoin-build-config.h> // IWYU pragma: keep
481
545
"# ,
482
546
defines_regex
483
- ) ) ;
547
+ )
548
+ . trim ( )
549
+ . to_string ( ) ) ;
484
550
}
485
551
let redundant = print_affected_files ( false ) ;
486
552
if redundant {
487
553
return Err ( r#"
488
- ^^^
489
554
None of the files use a symbol declared in the bitcoin-build-config.h header. However, they are including
490
555
the header. Consider removing the unused include.
491
556
"#
@@ -538,7 +603,9 @@ Markdown link errors found:
538
603
{}
539
604
"# ,
540
605
stderr
541
- ) )
606
+ )
607
+ . trim ( )
608
+ . to_string ( ) )
542
609
}
543
610
Err ( e) if e. kind ( ) == ErrorKind :: NotFound => {
544
611
println ! ( "`mlc` was not found in $PATH, skipping markdown lint check." ) ;
@@ -590,10 +657,9 @@ fn main() -> ExitCode {
590
657
env:: set_current_dir ( & git_root) . unwrap ( ) ;
591
658
if let Err ( err) = ( linter. lint_fn ) ( ) {
592
659
println ! (
593
- "{err}\n ^---- ⚠️ Failure generated from lint check '{}'! " ,
594
- linter. name
660
+ "^^^ \n {err}\n ^---- ⚠️ Failure generated from lint check '{}' ({})! \n \n " ,
661
+ linter. name, linter . description ,
595
662
) ;
596
- println ! ( "{}" , linter. description) ;
597
663
test_failed = true ;
598
664
}
599
665
}
0 commit comments