Skip to content

Commit

Permalink
new remove breakpoint codemod
Browse files Browse the repository at this point in the history
  • Loading branch information
clavedeluna committed Dec 29, 2023
1 parent bf5cef1 commit 3dd4d73
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 2 deletions.
20 changes: 20 additions & 0 deletions integration_tests/test_remove_debug_breakpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from core_codemods.remove_debug_breakpoint import RemoveDebugBreakpoint
from integration_tests.base_test import (
BaseIntegrationTest,
original_and_expected_from_code_path,
)


class TestRemoveDebugBreakpoint(BaseIntegrationTest):
codemod = RemoveDebugBreakpoint
code_path = "tests/samples/remove_debug_breakpoint.py"
original_code, _ = original_and_expected_from_code_path(code_path, [])
expected_new_code = """
print("hello")
print("world")
""".lstrip()
expected_diff = (
'--- \n+++ \n@@ -1,3 +1,2 @@\n print("hello")\n-breakpoint()\n print("world")\n'
)
expected_line_change = "2"
change_description = RemoveDebugBreakpoint.CHANGE_DESCRIPTION
4 changes: 4 additions & 0 deletions src/codemodder/scripts/generate_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ class DocMetadata:
importance="Low",
guidance_explained="Since literals and new objects have their own identities, comparisons against them using `is` operators are most likely a bug and thus we deem the change safe.",
),
"remove-debug-breakpoint": DocMetadata(
importance="Medium",
guidance_explained="Breakpoints are used for development debugging and can easily be forgotten before deploying code.",
),
}


Expand Down
2 changes: 2 additions & 0 deletions src/core_codemods/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from .sql_parameterization import SQLQueryParameterization
from .exception_without_raise import ExceptionWithoutRaise
from .literal_or_new_object_identity import LiteralOrNewObjectIdentity
from .remove_debug_breakpoint import RemoveDebugBreakpoint

registry = CodemodCollection(
origin="pixee",
Expand Down Expand Up @@ -82,5 +83,6 @@
FlaskJsonResponseType,
ExceptionWithoutRaise,
LiteralOrNewObjectIdentity,
RemoveDebugBreakpoint,
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This codemod removes any calls to `breakpoint()` or `pdb.set_trace()` which should only be used for active debugging and not in production code.

```diff
print("hello")
- breakpoint()
print("world")
```
4 changes: 2 additions & 2 deletions src/core_codemods/remove_debug_breakpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

class RemoveDebugBreakpoint(BaseCodemod, NameResolutionMixin, AncestorPatternsMixin):
NAME = "remove-debug-breakpoint"
SUMMARY = "TODORemove Module-level Global Call"
SUMMARY = "Remove Breakpoint"
REVIEW_GUIDANCE = ReviewGuidance.MERGE_WITHOUT_REVIEW
DESCRIPTION = "TODORemove Lines with `global` keyword at Module Level"
DESCRIPTION = "Remove calls to builtin `breakpoint` or `pdb.set_trace."
REFERENCES: list = []

def leave_Expr(
Expand Down
3 changes: 3 additions & 0 deletions tests/samples/remove_debug_breakpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
print("hello")
breakpoint()
print("world")

0 comments on commit 3dd4d73

Please sign in to comment.