22

Sometimes unused class or function manages to slip into code base. Static code checkers like ruff, flake8 does not have rules for detecting such globally unused code.

I tried using vulture, but it has too many false positives to have it as part of CI/CD pipeline.

I have tried to implement my own, more reliable check for global deadcode detection.

Please let me know what you think about it.

you are viewing a single comment's thread
view the rest of the comments
[-] jnovinger@programming.dev 3 points 1 year ago

This is great! I really appreciate that it returns a sensible exit code to the shell so that it can potentially fail a build. I also like the ability to maintain a list of excluded names in pyrpoject.toml so that you don't always have to sort through false positives.

Would love to see some more output options, like maybe --quiet that simply passes/fails and returns the exit code with no output or --count that either just displays a count or includes a count in the regular output. I guess I could always pipe the output to wc -l instead of having --count.

I'll see if I can't get this integrated in our CI system at work this next week.

[-] niekas@programming.dev 2 points 1 year ago

Thank you for your feedback! Its exactly what I was looking for πŸ‘

I have already added --count, --quiet options and regexp pattern support for --ignore-names option. Let me know if anything else pops into your mind πŸ˜ƒ

[-] jnovinger@programming.dev 2 points 1 year ago

Wow, nice. Thank you!

[-] jnovinger@programming.dev 2 points 1 year ago

Just coming back around on the count thing, in order to use wc -l, you need to ensure that stderr is piped too. Like:

deadcode . --exclude=*/tests,conftest.py --ignore-names-in-files=core/settings.py 2>&1 | wc -l

I ran this against a ~8 month old Django project and it turned up 11 unused names, of which 5 were expected and can be whitelisted. Nice!

[-] jnovinger@programming.dev 2 points 1 year ago

Would also be nice if I could use some sort of pattern in the --ignore-names option. Apologies if that's already there and I missed it.

[-] niekas@programming.dev 2 points 1 year ago

Great idea! I will add this feature shortly :)

this post was submitted on 24 Jun 2023
22 points (95.8% liked)

Python

6187 readers
39 users here now

Welcome to the Python community on the programming.dev Lemmy instance!

πŸ“… Events

October 2023

November 2023

PastJuly 2023

August 2023

September 2023

🐍 Python project:
πŸ’“ Python Community:
✨ Python Ecosystem:
🌌 Fediverse
Communities
Projects
Feeds

founded 1 year ago
MODERATORS