diff options
Diffstat (limited to 'test/lint')
-rw-r--r-- | test/lint/README.md | 8 | ||||
-rwxr-xr-x | test/lint/check-doc.py | 2 | ||||
-rwxr-xr-x | test/lint/lint-assertions.py | 12 | ||||
-rwxr-xr-x | test/lint/lint-circular-dependencies.py | 1 | ||||
-rwxr-xr-x | test/lint/lint-includes.py | 2 | ||||
-rwxr-xr-x | test/lint/lint-python.py | 5 | ||||
-rwxr-xr-x | test/lint/lint-qt-translation.py | 23 | ||||
-rwxr-xr-x | test/lint/lint-shell.py | 8 |
8 files changed, 40 insertions, 21 deletions
diff --git a/test/lint/README.md b/test/lint/README.md index 6ae5fdeb50..484008298b 100644 --- a/test/lint/README.md +++ b/test/lint/README.md @@ -7,13 +7,11 @@ To run linters locally with the same versions as the CI environment, use the inc Dockerfile: ```sh -DOCKER_BUILDKIT=1 docker build -t bitcoin-linter --file "./ci/lint_imagefile" ./ - -docker run --rm -v $(pwd):/bitcoin -it bitcoin-linter +DOCKER_BUILDKIT=1 docker build -t bitcoin-linter --file "./ci/lint_imagefile" ./ && docker run --rm -v $(pwd):/bitcoin -it bitcoin-linter ``` -After building the container once, you can simply run the last command any time you -want to lint. +Building the container can be done every time, because it is fast when the +result is cached and it prevents issues when the image changes. test runner =========== diff --git a/test/lint/check-doc.py b/test/lint/check-doc.py index d22dd9d996..f55d0f8cb7 100755 --- a/test/lint/check-doc.py +++ b/test/lint/check-doc.py @@ -23,7 +23,7 @@ CMD_GREP_WALLET_ARGS = r"git grep --function-context 'void WalletInit::AddWallet CMD_GREP_WALLET_HIDDEN_ARGS = r"git grep --function-context 'void DummyWalletInit::AddWalletOptions' -- {}".format(CMD_ROOT_DIR) CMD_GREP_DOCS = r"git grep --perl-regexp '{}' {}".format(REGEX_DOC, CMD_ROOT_DIR) # list unsupported, deprecated and duplicate args as they need no documentation -SET_DOC_OPTIONAL = set(['-h', '-help', '-dbcrashratio', '-forcecompactdb', '-zapwallettxes']) +SET_DOC_OPTIONAL = set(['-h', '-help', '-dbcrashratio', '-forcecompactdb']) def lint_missing_argument_documentation(): diff --git a/test/lint/lint-assertions.py b/test/lint/lint-assertions.py index 6da59b0d48..d9f86b22b8 100755 --- a/test/lint/lint-assertions.py +++ b/test/lint/lint-assertions.py @@ -23,20 +23,10 @@ def git_grep(params: [], error_msg: ""): def main(): - # PRE31-C (SEI CERT C Coding Standard): - # "Assertions should not contain assignments, increment, or decrement operators." - exit_code = git_grep([ - "-E", - r"[^_]assert\(.*(\+\+|\-\-|[^=!<>]=[^=!<>]).*\);", - "--", - "*.cpp", - "*.h", - ], "Assertions should not have side effects:") - # Aborting the whole process is undesirable for RPC code. So nonfatal # checks should be used over assert. See: src/util/check.h # src/rpc/server.cpp is excluded from this check since it's mostly meta-code. - exit_code |= git_grep([ + exit_code = git_grep([ "-nE", r"\<(A|a)ss(ume|ert) *\(.*\);", "--", diff --git a/test/lint/lint-circular-dependencies.py b/test/lint/lint-circular-dependencies.py index e366a08bd2..6f9a633807 100755 --- a/test/lint/lint-circular-dependencies.py +++ b/test/lint/lint-circular-dependencies.py @@ -21,7 +21,6 @@ EXPECTED_CIRCULAR_DEPENDENCIES = ( "qt/transactiontablemodel -> qt/walletmodel -> qt/transactiontablemodel", "wallet/wallet -> wallet/walletdb -> wallet/wallet", "kernel/coinstats -> validation -> kernel/coinstats", - "kernel/mempool_persist -> validation -> kernel/mempool_persist", # Temporary, removed in followup https://github.com/bitcoin/bitcoin/pull/24230 "index/base -> node/context -> net_processing -> index/blockfilterindex -> index/base", diff --git a/test/lint/lint-includes.py b/test/lint/lint-includes.py index 8e79ba5121..6386a92c0f 100755 --- a/test/lint/lint-includes.py +++ b/test/lint/lint-includes.py @@ -23,6 +23,7 @@ EXCLUDED_DIRS = ["contrib/devtools/bitcoin-tidy/", ] EXPECTED_BOOST_INCLUDES = ["boost/date_time/posix_time/posix_time.hpp", + "boost/multi_index/detail/hash_index_iterator.hpp", "boost/multi_index/hashed_index.hpp", "boost/multi_index/identity.hpp", "boost/multi_index/indexed_by.hpp", @@ -30,6 +31,7 @@ EXPECTED_BOOST_INCLUDES = ["boost/date_time/posix_time/posix_time.hpp", "boost/multi_index/sequenced_index.hpp", "boost/multi_index/tag.hpp", "boost/multi_index_container.hpp", + "boost/operators.hpp", "boost/process.hpp", "boost/signals2/connection.hpp", "boost/signals2/optional_last_value.hpp", diff --git a/test/lint/lint-python.py b/test/lint/lint-python.py index 6010c787cb..eabd13322e 100755 --- a/test/lint/lint-python.py +++ b/test/lint/lint-python.py @@ -9,14 +9,17 @@ Check for specified flake8 and mypy warnings in python files. """ import os +from pathlib import Path import subprocess import sys from importlib.metadata import metadata, PackageNotFoundError +# Customize mypy cache dir via environment variable +cache_dir = Path(__file__).parent.parent / ".mypy_cache" +os.environ["MYPY_CACHE_DIR"] = str(cache_dir) DEPS = ['flake8', 'lief', 'mypy', 'pyzmq'] -MYPY_CACHE_DIR = f"{os.getenv('BASE_ROOT_DIR', '')}/test/.mypy_cache" # All .py files, except those in src/ (to exclude subtrees there) FLAKE_FILES_ARGS = ['git', 'ls-files', '*.py', ':!:src/*.py'] diff --git a/test/lint/lint-qt-translation.py b/test/lint/lint-qt-translation.py new file mode 100755 index 0000000000..47bf96b654 --- /dev/null +++ b/test/lint/lint-qt-translation.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2023-present The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or https://opensource.org/license/mit/. +# +# Check for leading whitespaces in the translatable strings. + +import subprocess +import sys + + +def main(): + tr_strings = subprocess.run(['git', 'grep', '-e', 'tr("[[:space:]]', '--', 'src/qt'], stdout=subprocess.PIPE, text=True).stdout + + if tr_strings.strip(): + print("Avoid leading whitespaces in:") + print(tr_strings) + sys.exit(1) + + +if __name__ == "__main__": + main() diff --git a/test/lint/lint-shell.py b/test/lint/lint-shell.py index 1646bf0d3e..7fb78894af 100755 --- a/test/lint/lint-shell.py +++ b/test/lint/lint-shell.py @@ -67,9 +67,13 @@ def main(): '*.sh', ] files = get_files(files_cmd) - # remove everything that doesn't match this regex reg = re.compile(r'src/[leveldb,secp256k1,minisketch]') - files[:] = [file for file in files if not reg.match(file)] + + def should_exclude(fname: str) -> bool: + return bool(reg.match(fname)) + + # remove everything that doesn't match this regex + files[:] = [file for file in files if not should_exclude(file)] # build the `shellcheck` command shellcheck_cmd = [ |