Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for no action passed in argparse rule #396

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion precli/rules/python/stdlib/argparse_sensitive_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def analyze_call(self, context: dict, call: Call) -> Result:
if (
"--password" in [arg0.value_str, arg1.value_str]
or "--api-key" in [arg0.value_str, arg1.value_str]
) and action.value_str == "store":
) and (action.value is None or action.value_str == "store"):
return Result(
rule_id=self.id,
location=Location(node=call.node),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# level: ERROR
# start_line: 13
# end_line: 17
# start_column: 0
# end_column: 1
import argparse


parser = argparse.ArgumentParser(
prog="ProgramName",
description="What the program does",
)
parser.add_argument(
"--api-key",
dest="api_key",
help="API key to connect to the server",
)
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def test_rule_meta(self):
@parameterized.expand(
[
"argparse_add_argument_api_key.py",
"argparse_add_argument_default_action.py",
"argparse_add_argument_password.py",
"argparse_add_argument_password_file.py",
"argparse_add_argument_password_store_true.py",
Expand Down