-
Notifications
You must be signed in to change notification settings - Fork 581
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VultureBear: Make use of the new vulture API
The new vulture API provides better integration with coala. It natively supports `item.confidence`. Also, it gives precise information about the location of dead code (`first_line, `last_line`)
- Loading branch information
Showing
15 changed files
with
114 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,42 +3,26 @@ | |
from dependency_management.requirements.PipRequirement import PipRequirement | ||
from vulture import Vulture | ||
|
||
CONFIDENCE_MAP = { | ||
'attribute': 70, | ||
'class': 70, | ||
'function': 70, | ||
'import': 95, | ||
'property': 70, | ||
'variable': 70, | ||
} | ||
|
||
|
||
def _find_unused_code(filenames): | ||
""" | ||
:param filenames: List of filenames to check. | ||
:return: Generator of Result objects. | ||
""" | ||
|
||
def file_lineno(item): | ||
return (item.filename.lower(), item.lineno) | ||
|
||
vulture = Vulture() | ||
vulture.scavenge(filenames) | ||
for item in sorted( | ||
vulture.unused_funcs + vulture.unused_imports + | ||
vulture.unused_props + vulture.unused_vars + | ||
vulture.unused_attrs, key=file_lineno): | ||
message = 'Unused {0}: {1}'.format(item.typ, item) | ||
for item in vulture.get_unused_code(): | ||
yield Result.from_values(origin='VultureBear', | ||
message=message, | ||
message=item.message, | ||
file=item.filename, | ||
line=item.lineno, | ||
confidence=CONFIDENCE_MAP[item.typ]) | ||
line=item.first_lineno, | ||
end_line=item.last_lineno, | ||
confidence=item.confidence) | ||
|
||
|
||
class VultureBear(GlobalBear): | ||
LANGUAGES = {'Python', 'Python 3'} | ||
REQUIREMENTS = {PipRequirement('vulture', '0.14.0')} | ||
REQUIREMENTS = {PipRequirement('vulture', '0.25.0')} | ||
AUTHORS = {'The coala developers'} | ||
AUTHORS_EMAILS = {'[email protected]'} | ||
LICENSE = 'AGPL-3.0' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
if True: | ||
print('Reachable') | ||
elif something(): | ||
print('Never executed') | ||
else: | ||
print('Unreachable') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
if False: | ||
print('Unreachable') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
while True: | ||
print('I am reachable.') | ||
break | ||
|
||
while 0: | ||
print('I am unreachable.') | ||
print('I can be detected.') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
def func(a): | ||
pass | ||
|
||
|
||
func(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class Name: | ||
|
||
def __init__(self, name): | ||
self.name = name | ||
self.surname = 'Something' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def hello(name): | ||
print('Hello', name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from os import * | ||
import subprocess |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Bar(object): | ||
|
||
@property | ||
def prop(self): | ||
pass | ||
|
||
|
||
Bar() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
b = 10 | ||
a = 12 | ||
print(a) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
x = 2 | ||
print(x) |