jendrikseipp / vulture

Find dead Python code
MIT License
3.29k stars 145 forks source link

Vulture not finding code that it should be #334

Closed HenryBridges closed 9 months ago

HenryBridges commented 9 months ago

I have a project with a folder structure with folders: app, sql, tests, utils etc. all at the same level.

Currently, running vulture --min-confidence 90 sql --exclude "*/.venv/*" does not result in anything. However, running vulture --min-confidence 90 sql/v2/setup.py --exclude "*/.venv/*" will find some unused imports.

Assuming this is due to the ast method of traversing the files, I'm not sure why it wouldn't find these from just the sql parent folder.

Furthermore, using:
find . -name "*.py" -not -path "./.venv/*" -exec vulture --min-confidence 90 {} \; which executes the vulture on each .py file found in the directory returns everything I would expect - which would be fine.

But, then I cannot, seemingly, use the whitelist with this method, meaning I must resort to one of the unrecommended ways.

It could be useful to have a --whitelist flag that could result in: find . -name "*.py" -not -path "./.venv/*" -exec vulture --whitelist whitelist.py --min-confidence 90 {} \; working, and allowing the whitelist to be checked against for each file that vulture is running on, as --exclude doesn't seem to work given a whitelist.

jendrikseipp commented 9 months ago

Vulture only checks the defined names against the used names. So if an import is used in one file, it will not detect it as unused in any other file.

For detecting unused imports, flake8 does a more fine-grained analysis.