Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vulture to CI #398

Open
jelly opened this issue Jan 17, 2022 · 7 comments
Open

Add vulture to CI #398

jelly opened this issue Jan 17, 2022 · 7 comments

Comments

@jelly
Copy link
Member

jelly commented Jan 17, 2022

Add vulture (dead code detector to CI)

@just1602
Copy link
Contributor

just1602 commented Apr 7, 2022

Hello !

I run the following command :

vulture --exclude=*/migrations/*.py --min-confidence 65 devel/**/*.py main/**/*.py mirrors/**/*.py news/**/*.py packages/**/*.py planet/**/*.py public/**/*.py releng/**/*.py todolists/**/*.py visualize/**/*.py

and it gives me the following results :

archweb/devel/management/commands/reporead.py:215: unused variable 'package_sigs' (100% confidence)
archweb/mirrors/admin.py:77: unused variable 'change' (100% confidence)
archweb/mirrors/fields.py:46: unused variable 'expression' (100% confidence)
archweb/packages/tests/test_flag_packages.py:37: unused variable 'denylist' (100% confidence)
archweb/packages/tests/test_search.py:1: unused variable 'db' (100% confidence)
archweb/packages/tests/test_views.py:1: unused variable 'db' (100% confidence)
archweb/packages/tests/test_views.py:6: unused variable 'db' (100% confidence)
archweb/packages/tests/test_views.py:63: unused variable 'db' (100% confidence)
archweb/planet/tests/test_command.py:17: unused variable 'db' (100% confidence)
archweb/planet/tests/test_views.py:9: unused variable 'db' (100% confidence)
archweb/planet/tests/test_views.py:16: unused variable 'db' (100% confidence)
archweb/planet/tests/test_views.py:29: unused variable 'db' (100% confidence)
archweb/releng/tests/conftest.py:15: unused variable 'db' (100% confidence)
archweb/releng/tests/test_views.py:18: unused variable 'db' (100% confidence)
archweb/releng/tests/test_views.py:26: unused variable 'db' (100% confidence)
archweb/releng/tests/test_views.py:31: unused variable 'db' (100% confidence)

If I don't set the --min-confidence attribute, I get a lot of false positive (models attributes, Meta class, etc) so I raise it just a little bit to have more accurate results, but even there, almost all results are false positive since the unused variable 'db' is always in the tests functions signature.

Do you think it's worth it to find a way to "whitelist" the warnings related to the test files and implement this in a pipeline or we should simply fix the three unused variables and leave it like that?

@MashyBasker
Copy link

Hey,
I was thinking maybe using vulture in a pre-commit hook would be better than directly adding it to the CI pipeline.

@jelly
Copy link
Member Author

jelly commented Jan 21, 2024

Hello !

I run the following command :

vulture --exclude=*/migrations/*.py --min-confidence 65 devel/**/*.py main/**/*.py mirrors/**/*.py news/**/*.py packages/**/*.py planet/**/*.py public/**/*.py releng/**/*.py todolists/**/*.py visualize/**/*.py

and it gives me the following results :

archweb/devel/management/commands/reporead.py:215: unused variable 'package_sigs' (100% confidence)
archweb/mirrors/admin.py:77: unused variable 'change' (100% confidence)
archweb/mirrors/fields.py:46: unused variable 'expression' (100% confidence)
archweb/packages/tests/test_flag_packages.py:37: unused variable 'denylist' (100% confidence)
archweb/packages/tests/test_search.py:1: unused variable 'db' (100% confidence)
archweb/packages/tests/test_views.py:1: unused variable 'db' (100% confidence)
archweb/packages/tests/test_views.py:6: unused variable 'db' (100% confidence)
archweb/packages/tests/test_views.py:63: unused variable 'db' (100% confidence)
archweb/planet/tests/test_command.py:17: unused variable 'db' (100% confidence)
archweb/planet/tests/test_views.py:9: unused variable 'db' (100% confidence)
archweb/planet/tests/test_views.py:16: unused variable 'db' (100% confidence)
archweb/planet/tests/test_views.py:29: unused variable 'db' (100% confidence)
archweb/releng/tests/conftest.py:15: unused variable 'db' (100% confidence)
archweb/releng/tests/test_views.py:18: unused variable 'db' (100% confidence)
archweb/releng/tests/test_views.py:26: unused variable 'db' (100% confidence)
archweb/releng/tests/test_views.py:31: unused variable 'db' (100% confidence)

If I don't set the --min-confidence attribute, I get a lot of false positive (models attributes, Meta class, etc) so I raise it just a little bit to have more accurate results, but even there, almost all results are false positive since the unused variable 'db' is always in the tests functions signature.

Do you think it's worth it to find a way to "whitelist" the warnings related to the test files and implement this in a pipeline or we should simply fix the three unused variables and leave it like that?

Yes, we should whitelist python fixtures as they are detected as false positives

@just1602
Copy link
Contributor

@MashyBasker if you want to go forward and make a PR to run it as a pre-commit hook, go ahead. It has been two years since I comment this issue, and I've change workstation since then, so the work I had for this issue is gone.

If you don't have time, I'll try to get at it when I got some free time ! :)

@MashyBasker
Copy link

Thanks! I'll work on creating the pre-commit hook PR.

@jelly
Copy link
Member Author

jelly commented Jan 22, 2024

Thanks! I'll work on creating the pre-commit hook PR.

pre-commit hook is the not super interesting. Getting the code to run fine with vulture be a good start.

@MashyBasker
Copy link

Okay, I'll work on it. @jelly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants