-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added integration with
eradicate
to highlight dead code
There's an awesome Python project called `eradicate` (https://github.com/PyCQA/eradicate), but it doesn't seem to have a PyLint plugin. This PR adds this integration.
- Loading branch information
Showing
10 changed files
with
73 additions
and
3 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
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
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,32 @@ | ||
import astroid | ||
from eradicate import Eradicator | ||
from pylint.checkers import BaseRawFileChecker | ||
from pylint.interfaces import HIGH | ||
|
||
|
||
class EradicateChecker(BaseRawFileChecker): | ||
name = "eradicate" | ||
|
||
msgs = { | ||
"C8920": ( | ||
"Remove commented out code: %s", | ||
"dead-code", | ||
"Version control helps with keeping track of code changes. There is no need to keep commented out code in " | ||
"the codebase. Remove it to keep the codebase clean.", | ||
), | ||
} | ||
|
||
def open(self) -> None: | ||
self._eradicator = Eradicator() | ||
|
||
def process_module(self, node: astroid.Module): | ||
with node.stream() as stream: | ||
source = stream.read().decode() | ||
lines = source.splitlines() | ||
for line_no in self._eradicator.commented_out_code_line_numbers(source): | ||
src_line = lines[line_no - 1].strip() | ||
self.add_message("dead-code", line=line_no, confidence=HIGH, args=(src_line,)) | ||
|
||
|
||
def register(linter): | ||
linter.register_checker(EradicateChecker(linter)) |
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 @@ | ||
# pylint: disable=missing-module-docstring | ||
print("Hello, world!") | ||
# +1: [dead-code] | ||
# print('Goodbye, world!') | ||
print("...") |
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 @@ | ||
dead-code:4:0:None:None::"Remove commented out code: # print('Goodbye, world!')":HIGH |
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