Skip to content

Commit d19639d

Browse files
author
MarcoFalke
committed
Merge #21096: Re-add dead code detection
3f8776a Re-add dead code detection (flack) Pull request description: This re-adds unreachable code detection for Python based on `vulture`. Effectively, this reverts f4beb49. The difference to the previous version is that this runs with the `--min-confidence 100` setting. From https://pypi.org/project/vulture/: > Use `--min-confidence 100` to only report code that is guaranteed to be unused within the analyzed files. So this should avoid the previous issues where static analysis had wrong positives due to the dynamic nature of Python code by only reporting things that are unambiguous (such as code after a `return` statement). As such, there is not suppressions list. My motivation was mainly #21081 which would have been caught by this (as can be seen by the CI run failing). This is still marked as draft because #21081 is needed to get the linter to pass. Also, there is a second problem that this found (see https://github.com/bitcoin/bitcoin/pull/19509/files#r571454691). From what I can tell, this is a spurious type comment that could just be removed (or if that line has no side effects it could also be deleted altogether?). I could add a commit here to fix it, but I wanted to see if there is interest in having this linter again in the first place ACKs for top commit: practicalswift: ACK 3f8776a Tree-SHA512: 52314ad4f627d969de1eb15375ca677ed86a2e816fe773756a1ce22421214ba407b5a09a4bf701a3aab1a10c7b336f548e4cef3327edf154acba55e987db21f6
2 parents 8d6994f + 3f8776a commit d19639d

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

ci/lint/04_install.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ ${CI_RETRY_EXE} pip3 install codespell==2.0.0
1515
${CI_RETRY_EXE} pip3 install flake8==3.8.3
1616
${CI_RETRY_EXE} pip3 install yq
1717
${CI_RETRY_EXE} pip3 install mypy==0.781
18+
${CI_RETRY_EXE} pip3 install vulture==2.3
1819

1920
SHELLCHECK_VERSION=v0.7.1
2021
curl -sL "https://github.com/koalaman/shellcheck/releases/download/${SHELLCHECK_VERSION}/shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz" | tar --xz -xf - --directory /tmp/

test/lint/lint-python-dead-code.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright (c) 2021 The Bitcoin Core developers
4+
# Distributed under the MIT software license, see the accompanying
5+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
6+
#
7+
# Find dead Python code.
8+
9+
export LC_ALL=C
10+
11+
if ! command -v vulture > /dev/null; then
12+
echo "Skipping Python dead code linting since vulture is not installed. Install by running \"pip3 install vulture\""
13+
exit 0
14+
fi
15+
16+
# --min-confidence 100 will only report code that is guaranteed to be unused within the analyzed files.
17+
# Any value below 100 introduces the risk of false positives, which would create an unacceptable maintenance burden.
18+
if ! vulture \
19+
--min-confidence 100 \
20+
$(git ls-files -- "*.py"); then
21+
echo "Python dead code detection found some issues"
22+
exit 1
23+
fi

0 commit comments

Comments
 (0)