• Stars
    star
    331
  • Rank 127,323 (Top 3 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 6 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

dead simple python dead code detection

build status pre-commit.ci status

dead

dead simple python dead code detection

installation

pip install dead

cli

Consult the help for the latest usage:

$ dead --help
usage: dead [-h] [--files FILES] [--exclude EXCLUDE] [--tests TESTS]

optional arguments:
  -h, --help         show this help message and exit
  --files FILES      regex for file inclusion, default: ''
  --exclude EXCLUDE  regex for file exclusion, default '^$'
  --tests TESTS      regex to mark files as tests, default
                     '(^|/)(tests?|testing)/'

run the dead utility from the root of a git repository.

as a pre-commit hook

See pre-commit for instructions

Sample .pre-commit-config.yaml:

-   repo: https://github.com/asottile/dead
    rev: v1.5.2
    hooks:
    -   id: dead

how it works

  1. find all files in a repository using git ls-files and filtering:
    • only include files matched by the --files regex
    • exclude files matched by the --exclude regex
    • only include files identified as python by identify
    • classify test files by the --tests regex
  2. ast parse each file
    • search for definitions and references
  3. report things which do not have references

false positives

I wrote this in ~15 minutes on an airplane, it's far from perfect but often finds things. Here's a few things it's not good at:

  • functions which implement an interface are often marked as unused
  • metaclass magic is often marked as unused (enums, model classes, etc.)

suppressing dead

The # dead: disable comment will tell dead to ignore any line which has reportedly dead code.

is this project dead?

maybe.

More Repositories

1

pyupgrade

A tool (and pre-commit hook) to automatically upgrade syntax for newer versions of the language.
Python
3,498
star
2

reorder-python-imports

Rewrites source to reorder python imports
Python
731
star
3

git-code-debt

A dashboard for monitoring code debt in a git repository.
Python
573
star
4

all-repos

Clone all your repositories and apply sweeping changes.
Python
534
star
5

babi

a text editor
Python
393
star
6

add-trailing-comma

A tool (and pre-commit hook) to automatically add trailing commas to calls and literals.
Python
338
star
7

yesqa

Automatically remove unnecessary `# noqa` comments
Python
265
star
8

astpretty

Pretty print the output of python stdlib `ast.parse`.
Python
189
star
9

detect-test-pollution

a tool to detect test pollution
Python
173
star
10

setup-cfg-fmt

apply a consistent format to `setup.cfg` files
Python
152
star
11

setup-py-upgrade

upgrade a setup.py to declarative metadata
Python
148
star
12

scratch

Haphazard things.
Python
118
star
13

importtime-waterfall

Generate waterfalls from `-Ximporttime` tracing.
Python
108
star
14

setuptools-golang

A setuptools extension for building cpython extensions written in golang.
Python
98
star
15

dockerfile

Parse a dockerfile into a high-level representation using the official go parser
Go
97
star
16

gh-perf-review

hackety tool to view github PRs for a period
Python
81
star
17

re-assert

show where your regex match assertion failed!
Python
81
star
18

covdefaults

A coverage plugin to provide sensible default settings
Python
63
star
19

tokenize-rt

A wrapper around the stdlib `tokenize` which roundtrips.
Python
50
star
20

flake8-typing-imports

flake8 plugin which checks that typing imports are properly guarded
Python
48
star
21

cfgv

Validate configuration and produce human readable error messages
Python
44
star
22

recipes

One day IoT will catch up and then I can use CI
26
star
23

classify-imports

Utilities for refactoring imports in python-like syntax.
Python
23
star
24

nintendo-microcontrollers

control various nintendo consoles with arduino!
Python
22
star
25

awshelp

awshelp forwards arguments to `aws` unless `-h` or `--help` are present
Python
20
star
26

setuptools-golang-examples

Example extensions written for https://github.com/asottile/setuptools-golang
Go
19
star
27

watch-plz

Ensure all of your repositories are watched.
Python
17
star
28

workflows

reusable github workflows / actions
17
star
29

ukkonen

Implementation of bounded Levenshtein distance (Ukkonen)
C++
16
star
30

onigurumacffi

python cffi bindings for the oniguruma regex engine
Python
16
star
31

color-code

Encodes files as color
Python
16
star
32

wat

my brain is full of wat
Python
11
star
33

personal-puppet

serverless puppet to manage my machines
Puppet
11
star
34

shiny-pokemon-scraper

automatically detect tera raid events with guaranteed shiny pokemon
Python
10
star
35

set-delete-branch-on-merge

github does not provide a way to set the `delete_branch_on_merge` as a default
Python
9
star
36

babi-grammars

pip installable package to provide syntax grammars for babi
Python
7
star
37

rubyvenv

Create no-hassle ruby "virtualenvs". No .bashrc, no shims, no cd-magic.
Python
7
star
38

tessdata

pip installable versions of tesseract-ocr data
Python
6
star
39

setuptools-download

setuptools plugin to download external files
Python
6
star
40

pygments-pre-commit

A pygments lexer for pre-commit output.
Python
6
star
41

t

haphazard code snippets
Python
4
star
42

markdown-code-blocks

Generate html from markdown with code-block highlighting
Python
4
star
43

asottile.github.io

Python
4
star
44

hiera-eyaml-sshagent

A hiera-eyaml plugin which uses the ssh agent connected to `SSH_AUTH_SOCK` to encrypt / decrypt values.
Ruby
4
star
45

kensquared

Kotlin
2
star
46

.github

centralized github metadata for asottile
2
star
47

itl

Python
2
star
48

asottile

2
star
49

gnome-terminal-broken

rip
1
star