mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-03-29 10:16:52 +00:00
check for print debug statement
This commit is contained in:
parent
f4e025486b
commit
7c3f665ba8
2 changed files with 12 additions and 1 deletions
|
|
@ -20,6 +20,11 @@ DEBUG_STATEMENTS = {
|
|||
'wdb',
|
||||
}
|
||||
|
||||
DEBUG_CALL_STATEMENTS = {
|
||||
'breakpoint',
|
||||
'print'
|
||||
}
|
||||
|
||||
|
||||
class Debug(NamedTuple):
|
||||
line: int
|
||||
|
|
@ -45,7 +50,7 @@ class DebugStatementParser(ast.NodeVisitor):
|
|||
|
||||
def visit_Call(self, node: ast.Call) -> None:
|
||||
"""python3.7+ breakpoint()"""
|
||||
if isinstance(node.func, ast.Name) and node.func.id == 'breakpoint':
|
||||
if isinstance(node.func, ast.Name) and node.func.id in DEBUG_CALL_STATEMENTS:
|
||||
st = Debug(node.lineno, node.col_offset, node.func.id, 'called')
|
||||
self.breakpoints.append(st)
|
||||
self.generic_visit(node)
|
||||
|
|
|
|||
|
|
@ -30,6 +30,12 @@ def test_finds_breakpoint():
|
|||
visitor = DebugStatementParser()
|
||||
visitor.visit(ast.parse('breakpoint()'))
|
||||
assert visitor.breakpoints == [Debug(1, 0, 'breakpoint', 'called')]
|
||||
|
||||
|
||||
def test_finds_print():
|
||||
visitor = DebugStatementParser()
|
||||
visitor.visit(ast.parse('print()'))
|
||||
assert visitor.breakpoints == [Debug(1, 0, 'print', 'called')]
|
||||
|
||||
|
||||
def test_returns_one_for_failing_file(tmpdir):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue