From 48b4ec0312959f3e6b5ed90f053c007430719f69 Mon Sep 17 00:00:00 2001 From: Musab Abdullah Date: Mon, 4 Nov 2024 11:45:27 -0600 Subject: [PATCH] updated plugin to look for dotenv.load_dotenv also (attribute call vs direct call) --- ci_cd/flake8_forbidden_calls.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/ci_cd/flake8_forbidden_calls.py b/ci_cd/flake8_forbidden_calls.py index 7d44c4daf9..65230356d5 100644 --- a/ci_cd/flake8_forbidden_calls.py +++ b/ci_cd/flake8_forbidden_calls.py @@ -1,10 +1,12 @@ """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" @@ -14,6 +16,18 @@ class ForbiddenCallPlugin: 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 + if isinstance(node, ast.Call): + func_name = ( + node.func.id + if isinstance(node.func, ast.Name) + else ( + node.func.attr if isinstance(node.func, ast.Attribute) else None + ) + ) + if func_name in FORBIDDEN_CALLS: + yield ( + node.lineno, + node.col_offset, + f"{PLUGIN_CODE} `{func_name}` is not allowed.", + type(self), + )