Skip to content

Commit

Permalink
rule: no monkey patching
Browse files Browse the repository at this point in the history
  • Loading branch information
ankush committed Mar 7, 2024
1 parent d527a56 commit 92e1241
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
17 changes: 17 additions & 0 deletions rules/frappe_correctness.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,20 @@ def good_cache():

# ruleid: frappe-no-functional-code
map(lambda x: x, filter(lambda x: x, []))


# ruleid: frappe-monkey-patching-not-allowed
from frappe import permissions

permissions.has_permission = lambda : True


# ruleid: frappe-monkey-patching-not-allowed
from frappe import permissions

permissions.has_permission.xyz = lambda : True

# ruleid: frappe-monkey-patching-not-allowed
from frappe.permissions import has_permission

has_permission.xyz = lambda : True
35 changes: 35 additions & 0 deletions rules/frappe_correctness.yml
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,38 @@ rules:
This call will publish message to everyone on site, do you really want that? Specify doctype, docname, room or user.
languages: [python]
severity: ERROR

- id: frappe-monkey-patching-not-allowed
patterns:
- pattern-either:
- pattern: |
from $X import $Y
...
$Y.$PROPERTY = ...
- pattern: |
from $X import $Y
...
$Y.$Z.$PROPERTY = ...
- pattern: |
from $X import $Y
...
$Y.$Z.$F.$PROPERTY = ...
- pattern: |
from $X import $Y
...
$Y.$Z.$F.$K.$PROPERTY = ...
- pattern: |
from $X import $Y
...
$Y.$Z.$F.$K.$J.$PROPERTY = ...
- pattern: |
from $X import $Y
...
$Y.$Z.$F.$K.$J.$L.$PROPERTY = ...
message: |
$PROPERTY being monkey patched by app. Use hooks provided by framework instead of patching behaviour at runtime.
paths:
exclude:
- "**/test_*.py"
languages: [python]
severity: ERROR

0 comments on commit 92e1241

Please sign in to comment.