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

pre-commit hook run only on staged/committed files on current branch? #259

Open
natarajanc-prodigygame opened this issue May 13, 2021 · 4 comments

Comments

@natarajanc-prodigygame
Copy link

vulture seems like a very useful tool, yet I can't configure it quite right. Perhaps it's a bug - or a configuration issue that could be explained slightly better.

i want to use the vulture pre-commit hook to only run on the staged/committed files in my branch individually and not run it based on directories specified in paths under the pyproject.toml

If i use the pyproject.toml config and specify the directories - the unused imported lib in 1 file can be used in another file in the same directory and hence the detection of unused imports does not happen

is it possible to only run on staged/committed files individually?

@RJ722
Copy link
Contributor

RJ722 commented May 15, 2021

If Vulture is run on staged/committed files only, it will report false "unused import" results.

I'm not sure how pre-commit works under the hood, but I'm wondering if it can be configured to do the following: Run Vulture on all your files, and then grep the results to show only the ones for staged/committed files.

@natarajanc-prodigygame
Copy link
Author

natarajanc-prodigygame commented May 18, 2021

@RJ722 taking a simple example - assuming 2 files in same directory

file a.py
import lib_a # unused in this file

file b.py
import lib_a # actually used in the file

if i run vulture on all files , the unused import for file a.py wont be surfaced (even with grep solution you indicated)

the unused import for file a.py only happens when i run vulture a.py which is what i want to happen - but unfortunately vulture is running on pre-commit hook on all files together

see below - running on single file gives a unused import , while running vulture on files in the parent folder and grepping for file gives nothing

$ vulture --min-confidence=90 dags/locations_nces_to_snowflake.py
dags/locations_nces_to_snowflake.py:10: unused import 'time' (90% confidence)

$ vulture --min-confidence=90 dags/ | grep locations_nces_to_snowflake.py
$  

@anita-clement
Copy link

Hi, is there an update on this issue?

I'm running into the same issue. vulture is running on all files when I'm running pre-commit while the expected behaviour from pre-commit is for it to run on staged files only. Thanks

@jendrikseipp
Copy link
Owner

I agree with @RJ722 : it's important to run Vulture on all files. Otherwise, if you edit a file containing name definitions but these names are not used in the file, you'll get many false positives.

As @RJ722 says: if it's possible to only report the unused code from changed files, that would be a useful change, though. PRs welcome :-)

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

4 participants