forked from coala/coala-bears
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes coala#2016
- Loading branch information
Showing
1 changed file
with
22 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,16 +4,33 @@ | |
from dependency_management.requirements.PipRequirement import PipRequirement | ||
from coalib.results.Diff import Diff | ||
from coalib.results.Result import Result | ||
|
||
|
||
class PyUnusedCodeBear(LocalBear): | ||
from coalib.bearlib.aspects import map_setting_to_aspect | ||
from coalib.bearlib.aspects.Redundancy import ( | ||
Redundancy, | ||
UnusedImport, | ||
UnusedLocalVariable, | ||
) | ||
|
||
|
||
class PyUnusedCodeBear( | ||
LocalBear, | ||
aspects={ | ||
'fix': [ | ||
UnusedImport, | ||
UnusedLocalVariable, | ||
]}, | ||
languages=['Python'], | ||
): | ||
LANGUAGES = {'Python', 'Python 2', 'Python 3'} | ||
REQUIREMENTS = {PipRequirement('autoflake', '0.6.6')} | ||
AUTHORS = {'The coala developers'} | ||
AUTHORS_EMAILS = {'[email protected]'} | ||
LICENSE = 'AGPL-3.0' | ||
CAN_DETECT = {'Unused Code'} | ||
|
||
@map_setting_to_aspect( | ||
remove_all_unused_imports=UnusedImport.remove_non_standard_import, | ||
remove_unused_variables=UnusedLocalVariable) | ||
def run(self, filename, file, | ||
remove_all_unused_imports: bool=True, | ||
remove_unused_variables: bool=True): | ||
|
@@ -29,7 +46,6 @@ def run(self, filename, file, | |
:param remove_unused_variables: | ||
``False`` keeps unused variables | ||
""" | ||
|
||
corrected = autoflake.fix_code( | ||
''.join(file), | ||
additional_imports=None, | ||
|
@@ -41,4 +57,5 @@ def run(self, filename, file, | |
yield Result(self, | ||
'This file contains unused source code.', | ||
affected_code=(diff.range(filename),), | ||
diffs={filename: diff}) | ||
diffs={filename: diff}, | ||
aspect=Redundancy('py')) |