@@ -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/" ,
@@ -293,6 +304,62 @@ fs:: namespace, which has unsafe filesystem functions marked as deleted.
293304 }
294305}
295306
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+
296363fn lint_doc_release_note_snippets ( ) -> LintResult {
297364 let non_release_notes = check_output ( git ( ) . args ( [
298365 "ls-files" ,
@@ -593,7 +660,7 @@ fn main() -> ExitCode {
593660 "{err}\n ^---- ⚠️ Failure generated from lint check '{}'!" ,
594661 linter. name
595662 ) ;
596- println ! ( "{}" , linter. description) ;
663+ println ! ( "{}\n \n " , linter. description) ;
597664 test_failed = true ;
598665 }
599666 }
0 commit comments