@@ -48,6 +48,16 @@ fn get_linter_list() -> Vec<&'static Linter> {
4848 name: "std_filesystem" ,
4949 lint_fn: lint_std_filesystem
5050 } ,
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+ } ,
5161 & Linter {
5262 description: "Check that release note snippets are in the right folder" ,
5363 name: "doc_release_note_snippets" ,
@@ -237,7 +247,7 @@ fn lint_py_lint() -> LintResult {
237247 "F822" , // undefined name name in __all__
238248 "F823" , // local variable name … referenced before assignment
239249 "F841" , // local variable 'foo' is assigned to but never used
240- "PLE" , // Pylint errors
250+ "PLE" , // Pylint errors
241251 "W191" , // indentation contains tabs
242252 "W291" , // trailing whitespace
243253 "W292" , // no newline at end of file
@@ -273,6 +283,7 @@ fn lint_std_filesystem() -> LintResult {
273283 let found = git ( )
274284 . args ( [
275285 "grep" ,
286+ "--line-number" ,
276287 "std::filesystem" ,
277288 "--" ,
278289 "./src/" ,
@@ -283,10 +294,66 @@ fn lint_std_filesystem() -> LintResult {
283294 . success ( ) ;
284295 if found {
285296 Err ( r#"
286- ^^^
287297Direct use of std::filesystem may be dangerous and buggy. Please include <util/fs.h> and use the
288298fs:: namespace, which has unsafe filesystem functions marked as deleted.
289299 "#
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 ( )
290357 . to_string ( ) )
291358 } else {
292359 Ok ( ( ) )
@@ -303,17 +370,15 @@ fn lint_doc_release_note_snippets() -> LintResult {
303370 if non_release_notes. is_empty ( ) {
304371 Ok ( ( ) )
305372 } else {
306- Err ( format ! (
307- r#"
308- {}
309- ^^^
373+ println ! ( "{non_release_notes}" ) ;
374+ Err ( r#"
310375Release note snippets and other docs must be put into the doc/ folder directly.
311376
312377The doc/release-notes/ folder is for archived release notes of previous releases only. Snippets are
313378expected to follow the naming "/doc/release-notes-<PR number>.md".
314- "# ,
315- non_release_notes
316- ) )
379+ "#
380+ . trim ( )
381+ . to_string ( ) )
317382 }
318383}
319384
@@ -356,7 +421,6 @@ fn lint_trailing_whitespace() -> LintResult {
356421 . success ( ) ;
357422 if trailing_space {
358423 Err ( r#"
359- ^^^
360424Trailing whitespace (including Windows line endings [CR LF]) is problematic, because git may warn
361425about it, or editors may remove it by default, forcing developers in the future to either undo the
362426changes manually or spend time on review.
@@ -366,6 +430,7 @@ Thus, it is best to remove the trailing space now.
366430Please add any false positives, such as subtrees, Windows-related files, patch files, or externally
367431sourced files to the exclude list.
368432 "#
433+ . trim ( )
369434 . to_string ( ) )
370435 } else {
371436 Ok ( ( ) )
@@ -382,14 +447,14 @@ fn lint_tabs_whitespace() -> LintResult {
382447 . success ( ) ;
383448 if tabs {
384449 Err ( r#"
385- ^^^
386450Use of tabs in this codebase is problematic, because existing code uses spaces and tabs will cause
387451display issues and conflict with editor settings.
388452
389453Please remove the tabs.
390454
391455Please add any false positives, such as subtrees, or externally sourced files to the exclude list.
392456 "#
457+ . trim ( )
393458 . to_string ( ) )
394459 } else {
395460 Ok ( ( ) )
@@ -464,7 +529,6 @@ fn lint_includes_build_config() -> LintResult {
464529 if missing {
465530 return Err ( format ! (
466531 r#"
467- ^^^
468532One or more files use a symbol declared in the bitcoin-build-config.h header. However, they are not
469533including the header. This is problematic, because the header may or may not be indirectly
470534included. If the indirect include were to be intentionally or accidentally removed, the build could
@@ -480,12 +544,13 @@ include again.
480544#include <bitcoin-build-config.h> // IWYU pragma: keep
481545 "# ,
482546 defines_regex
483- ) ) ;
547+ )
548+ . trim ( )
549+ . to_string ( ) ) ;
484550 }
485551 let redundant = print_affected_files ( false ) ;
486552 if redundant {
487553 return Err ( r#"
488- ^^^
489554None of the files use a symbol declared in the bitcoin-build-config.h header. However, they are including
490555the header. Consider removing the unused include.
491556 "#
@@ -538,7 +603,9 @@ Markdown link errors found:
538603{}
539604 "# ,
540605 stderr
541- ) )
606+ )
607+ . trim ( )
608+ . to_string ( ) )
542609 }
543610 Err ( e) if e. kind ( ) == ErrorKind :: NotFound => {
544611 println ! ( "`mlc` was not found in $PATH, skipping markdown lint check." ) ;
@@ -590,10 +657,9 @@ fn main() -> ExitCode {
590657 env:: set_current_dir ( & git_root) . unwrap ( ) ;
591658 if let Err ( err) = ( linter. lint_fn ) ( ) {
592659 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 ,
595662 ) ;
596- println ! ( "{}" , linter. description) ;
597663 test_failed = true ;
598664 }
599665 }
0 commit comments