mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-24 18:24:20 +00:00
added a local flake8 plugin to check if load_dotenv is ever called. plugin can be extended to check for calls to other 'forbidden' functions
This commit is contained in:
parent
8413603b98
commit
07f54f9942
2 changed files with 25 additions and 0 deletions
6
.flake8
6
.flake8
|
@ -44,3 +44,9 @@ ignore =
|
|||
|
||||
# https://black.readthedocs.io/en/stable/guides/using_black_with_other_tools.html#flake8
|
||||
extend-ignore = E203
|
||||
|
||||
[flake8:local-plugins]
|
||||
extension =
|
||||
FC1 = flake8_forbidden_calls:ForbiddenCallPlugin
|
||||
paths =
|
||||
./ci_cd
|
19
ci_cd/flake8_forbidden_calls.py
Normal file
19
ci_cd/flake8_forbidden_calls.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
"""Flake8 Extension that finds usage of load_dotenv."""
|
||||
import ast
|
||||
from typing import Generator
|
||||
|
||||
FORBIDDEN_CALLS = ["load_dotenv"]
|
||||
PLUGIN_CODE = "FC1"
|
||||
|
||||
class ForbiddenCallPlugin:
|
||||
name = "flake8_forbidden_calls"
|
||||
version = "1.0.0"
|
||||
|
||||
def __init__(self, tree: ast.AST):
|
||||
self._tree = tree
|
||||
|
||||
def run(self) -> Generator:
|
||||
for node in ast.walk(self._tree):
|
||||
if isinstance(node, ast.Call) and isinstance(node.func, ast.Name):
|
||||
if node.func.id in FORBIDDEN_CALLS:
|
||||
yield (node.lineno, node.col_offset, f"{PLUGIN_CODE} `{node.func.id}` is not allowed.", type(self))
|
Loading…
Add table
Add a link
Reference in a new issue