jendrikseipp / vulture

Find dead Python code
MIT License
3.38k stars 148 forks source link

Add violation codes that can be ignored #265

Open jamilraichouni opened 2 years ago

jamilraichouni commented 2 years ago

I combine flake8 and vulture and want to use vulture for stuff that is not being found by flake8. The issue is that there are cases where I get two problems reported for one and the same issue in the code.

Example:

def main(a: int):
    """Do something useful."""
    b: int = 2 * CONST
    return b

Here flake8 including the plugin (flake8-unused-arguments) reports an unused argument and vulture also reports the same unused variable with 100% confidence.

It would be great to be able to fine-tune that like it is possible for flake8 (e. g. in the tox.ini) via stuff like that:

[flake8]
ignore =
    D211,  ; ignore "No blank lines allowed before class docstring" AND prefer D203 "1 blank line required before class docstring"
    D213,  ; ignore "Multi-line docstring summary should start at the second line"
    D402,  ; ignore "First line should not be the function’s “signature”"
    D415,  ; ignore "First line should end with a period, question mark, or exclamation point" AND prefer D400 "First line should end with a period"
    F721,  ; ignore "syntax error in doctest"
    W503,  ; ignore "line break before binary operator" according to black formatting

Hence, you may want to introduce violation codes that can be ignored in the pyproject.toml. For instance:

[tool.vulture]
ignore = ["V123",]

Many thanks! Jamil

dsuch commented 2 years ago

Yes, this is a very good idea. For serious purposes, one uses at least several static checkers, each good in its own way, and what you suggest would be truly helpful.

RJ722 commented 2 years ago

Seeing that we already support # noqa for some particular flake8 codes (like F401: module imported but unused and F841: local variable is assigned to but never used), I don't see a reason why we shouldn't support this.

I'll be happy to work out a pull request once we get a confirmation from @jendrikseipp.

jendrikseipp commented 2 years ago

I'm not opposed to adding such functionality. However, I'm not yet convinced that such a feature is useful. Your example @jamilraichouni would ignore unused arguments for all functions (assuming that V123 is the code for unused arguments). At the same time, you explicitly add flake8-unused-arguments to catch them. Isn't that a contradiction? Can you post an example where ignoring Vulture error codes would be helpful for you?

songololo commented 2 years ago

In my case I have a python package with functions made available to end-users, but which I don't necessarily use in my own code. I'd like to be able to ignore unused-function errors and just catch unused-variable errors.