Skip to content

Commit

Permalink
Reorganize error codes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jendrikseipp committed Jun 2, 2020
1 parent af5e3f7 commit f046066
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ results in the following output:

dead_code.py:1: V104 unused import 'os' (90% confidence)
dead_code.py:4: V103 unused function 'greet' (60% confidence)
dead_code.py:8: V106 unused variable 'message' (60% confidence)
dead_code.py:8: V107 unused variable 'message' (60% confidence)

Vulture correctly reports "os" and "message" as unused, but it fails to
detect that "greet" is actually used. The recommended method to deal
Expand All @@ -181,7 +181,7 @@ Passing both the original program and the whitelist to Vulture
makes Vulture ignore the `greet` method:

dead_code.py:1: V104 unused import 'os' (90% confidence)
dead_code.py:8: V106 unused variable 'message' (60% confidence)
dead_code.py:8: V107 unused variable 'message' (60% confidence)

<!-- Hide noqa docs until we decide whether we want to support it.
**Using "# noqa"**
Expand All @@ -208,7 +208,8 @@ codes.
| V103 | Unused function |
| V104, F401 | Unused import |
| V105 | Unused property |
| V106, F841 | Unused variable |
| V106 | Unused method |
| V107, F841 | Unused variable |
| V201 | Unreachable code |
-->
Expand Down
17 changes: 9 additions & 8 deletions tests/test_noqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ def test_noqa_specific_issue_codes(v):
@underground # noqa: V102
class Cellar:
@property # noqa: V105
@property # noqa: V106
def wine(self):
grapes = True # noqa: V106
grapes = True # noqa: V107
@without_ice # noqa: V103
def serve(self, quantity=50):
Expand All @@ -95,6 +95,7 @@ def serve(self, quantity=50):
check(v.unused_classes, [])
check(v.unused_funcs, [])
check(v.unused_imports, [])
check(v.unused_methods, ["serve"])
check(v.unused_props, [])
check(v.unreachable_code, [])
check(v.unused_vars, [])
Expand All @@ -104,7 +105,7 @@ def test_noqa_attributes(v):
v.scan(
"""\
something.x = 'x' # noqa: V101
something.z = 'z' # noqa: V106 (code for unused variable)
something.z = 'z' # noqa: V107 (code for unused variable)
something.u = 'u' # noqa
"""
)
Expand Down Expand Up @@ -191,15 +192,15 @@ def test_noqa_multiple_decorators(v):
"""\
@bar # noqa: V102
class Foo:
@property # noqa: V105
@property # noqa: V106
@make_it_cool
@log
def something(self):
pass
@coolify
@property
def something_else(self): # noqa: V105
def something_else(self): # noqa: V106
pass
@a
Expand Down Expand Up @@ -235,10 +236,10 @@ def shave_sheep(sheep):
def test_noqa_variables(v):
v.scan(
"""\
mitsi = "Mother" # noqa: V106
mitsi = "Mother" # noqa: V107
harry = "Father" # noqa
shero = "doggy" # noqa: V101, V104 (code for unused import, attr)
shinchan.friend = ['masao'] # noqa: V106 (code for unused variable)
shinchan.friend = ['masao'] # noqa: V107 (code for unused variable)
"""
)
check(v.unused_vars, ["shero"])
Expand All @@ -254,7 +255,7 @@ def world(axis): # noqa: V103, V201
for _ in range(3):
continue
xyz = hello(something, else): # noqa: V201, V106
xyz = hello(something, else): # noqa: V201, V107
"""
)
check(v.get_unused_code(), [])
Expand Down
7 changes: 3 additions & 4 deletions vulture/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,14 @@
if sys.version_info < (3, 4):
IGNORED_VARIABLE_NAMES |= {"True", "False"}

# TODO: reorganize codes.
ERROR_CODES = {
"attribute": "V101",
"class": "V102",
"function": "V103",
"import": "V104",
"method": "V107",
"property": "V105",
"variable": "V106",
"method": "V105",
"property": "V106",
"variable": "V107",
"unreachable_code": "V201",
}

Expand Down
2 changes: 1 addition & 1 deletion vulture/noqa.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
# flake8 F401: module imported but unused.
"F401": "V104",
# flake8 F841: local variable is assigned to but never used.
"F841": "V106",
"F841": "V107",
}


Expand Down

0 comments on commit f046066

Please sign in to comment.