diff --git a/.flake8 b/.flake8 index afd4596076..d8a484e0c5 100644 --- a/.flake8 +++ b/.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 \ No newline at end of file diff --git a/ci_cd/flake8_forbidden_calls.py b/ci_cd/flake8_forbidden_calls.py new file mode 100644 index 0000000000..7d44c4daf9 --- /dev/null +++ b/ci_cd/flake8_forbidden_calls.py @@ -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)) \ No newline at end of file