Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from vulture import Vulture, noqa
from vulture.utils import VultureInputException, sanitize_code
from .base import PythonTool, Issue, ParseIssue, AccessIssue
from ..util import parse_python_file
class VultureIssue(Issue):
tool = 'vulture'
pylint_type = 'R'
class TidyPyVulture(Vulture):
ISSUE_TYPES = (
('unused-class', 'Unused class {entity}', 'unused_classes'),
('unused-function', 'Unused function {entity}', 'unused_funcs'),
('unused-import', 'Unused import {entity}', 'unused_imports'),
('unused-property', 'Unused property {entity}', 'unused_props'),
('unused-variable', 'Unused variable {entity}', 'unused_vars'),
('unused-attribute', 'Unused attribute {entity}', 'unused_attrs')
)
def __init__(self, config):
ignore_names = config['options']['ignore-names']
if isinstance(ignore_names, str):
ignore_names = ignore_names.split(',')
ignore_decorators = config['options']['ignore-decorators']
if isinstance(ignore_decorators, str):
def run(files):
"""Run vulture over the given files."""
with tempfile.NamedTemporaryFile(mode='w', delete=False) as whitelist_file:
for line in whitelist_generator():
whitelist_file.write(line + '\n')
whitelist_file.close()
vult = vulture.Vulture(verbose=False)
vult.scavenge(files + [whitelist_file.name])
os.remove(whitelist_file.name)
filters = {
'unused_funcs': filter_func,
'unused_props': lambda item: False,
'unused_vars': lambda item: False,
'unused_attrs': lambda item: False,
}
items = []
for attr, func in filters.items():
sub_items = getattr(vult, attr)
for item in sub_items:
# Vulture sometimes incorrectly classifies code as unused. You can use
# a separate python file to signal that the code is actually used and
# pass it to vulture:
#
# vulture vulture.py whitelist.py
from vulture import Vulture
v = Vulture()
v.visit_arg
v.visit_alias
v.visit_Assign
v.visit_Attribute
v.visit_ClassDef
v.visit_comprehension
v.visit_For
v.visit_FunctionDef
v.visit_Import
v.visit_ImportFrom
v.visit_Name
v.visit_Str
# -*- coding: utf-8 -*-
from vulture import Vulture
from prospector.encoding import CouldNotHandleEncoding, read_py_file
from prospector.message import Location, Message, make_tool_error_message
from prospector.tools.base import ToolBase
class ProspectorVulture(Vulture):
def __init__(self, found_files):
Vulture.__init__(self, exclude=None, verbose=False)
self._files = found_files
self._internal_messages = []
def scavenge(self, _=None):
# The argument is a list of paths, but we don't care
# about that as we use the found_files object. The
# argument is here to explicitly acknowledge that we
# are overriding the Vulture.scavenge method.
for module in self._files.iter_module_paths():
try:
module_string = read_py_file(module)
except CouldNotHandleEncoding as err:
self._internal_messages.append(make_tool_error_message(