From 40bb0d8c8b20aab700011702bb0edd16249ead09 Mon Sep 17 00:00:00 2001 From: Emaniacinator Date: Mon, 15 Jun 2026 13:58:59 -0600 Subject: [PATCH 1/5] Initial setup and linter fixes --- .gitignore | 4 +++- StandardCheck.py | 4 ++-- checkers/common_nodes.py | 18 +++++++++--------- checkers/imports.py | 8 ++++---- checkers/security.py | 4 ++-- config.py | 2 +- requirements.txt | 2 +- 7 files changed, 22 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index d5e4f15..5ad7957 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -**/__pycache__ \ No newline at end of file +**/__pycache__ +venv +.venv \ No newline at end of file diff --git a/StandardCheck.py b/StandardCheck.py index 7bf9cfe..d3ae647 100644 --- a/StandardCheck.py +++ b/StandardCheck.py @@ -16,7 +16,7 @@ import checkers.complexity as complexity_module -def visit_node(node: ast.AST, file_path: str, ignore_codes: set[str], ignore_names: set[str] = None) -> list[models.StyleError]: +def visit_node(node: ast.AST, file_path: str, ignore_codes: set[str], ignore_names: set[str] = set()) -> list[models.StyleError]: """Visit an AST node and perform checks. Args: @@ -40,7 +40,7 @@ def visit_node(node: ast.AST, file_path: str, ignore_codes: set[str], ignore_nam return [] -def check_file(file_path: Path, ignore_codes: set[str], ignore_names: set[str] = None, config: dict[str, Any] = None) -> list[models.StyleError]: +def check_file(file_path: Path, ignore_codes: set[str], ignore_names: set[str] = set(), config: dict[str, Any] = {}) -> list[models.StyleError]: """Check a single Python file. Args: diff --git a/checkers/common_nodes.py b/checkers/common_nodes.py index 4416386..e976138 100644 --- a/checkers/common_nodes.py +++ b/checkers/common_nodes.py @@ -6,7 +6,7 @@ import utils.patterns as patterns_module import checkers.error_creation as error_creation_module -def check_variable(node: ast.Name, file_path: str, ignore_codes: set[str], ignore_names: set[str] = None) -> list[models.StyleError]: +def check_variable(node: ast.Name, file_path: str, ignore_codes: set[str], ignore_names: set[str] = set()) -> list[models.StyleError]: """Check variable naming. Args: @@ -18,7 +18,7 @@ def check_variable(node: ast.Name, file_path: str, ignore_codes: set[str], ignor Returns: list of style errors found """ - errors = [] + errors: list[models.StyleError] = [] ignore_names = ignore_names or set() # Skip if name should be ignored @@ -38,7 +38,7 @@ def check_variable(node: ast.Name, file_path: str, ignore_codes: set[str], ignor return errors -def check_class(node: ast.ClassDef, file_path: str, ignore_codes: set[str], ignore_names: set[str] = None) -> list[models.StyleError]: +def check_class(node: ast.ClassDef, file_path: str, ignore_codes: set[str], ignore_names: set[str] = set()) -> list[models.StyleError]: """Check class definition. Args: @@ -50,7 +50,7 @@ def check_class(node: ast.ClassDef, file_path: str, ignore_codes: set[str], igno Returns: list of style errors found """ - errors = [] + errors: list[models.StyleError] = [] ignore_names = ignore_names or set() # Skip if name should be ignored @@ -98,7 +98,7 @@ def _is_valid_class_name(name: str) -> bool: return False -def check_function(node: ast.FunctionDef | ast.AsyncFunctionDef, file_path: str, ignore_codes: set[str], ignore_names: set[str] = None) -> list[models.StyleError]: +def check_function(node: ast.FunctionDef | ast.AsyncFunctionDef, file_path: str, ignore_codes: set[str], ignore_names: set[str] = set()) -> list[models.StyleError]: """Check function definition. Args: @@ -110,7 +110,7 @@ def check_function(node: ast.FunctionDef | ast.AsyncFunctionDef, file_path: str, Returns: list of style errors found """ - errors = [] + errors: list[models.StyleError] = [] ignore_names = ignore_names or set() is_test_file = 'test' in file_path.lower() @@ -199,7 +199,7 @@ def _check_function_docstrings(node: ast.FunctionDef | ast.AsyncFunctionDef, fil Returns: list of style errors related to function docstrings """ - errors = [] + errors: list[models.StyleError] = [] # Skip docstring checks for @overload functions if _has_overload_decorator(node): @@ -230,7 +230,7 @@ def _check_docstring_format(node: ast.FunctionDef | ast.AsyncFunctionDef | ast.C Returns: list of style errors found """ - errors = [] + errors: list[models.StyleError] = [] if not docstring: return errors summary = docstring.split('\n\n')[0].strip() @@ -264,7 +264,7 @@ def _check_function_docstring(node: ast.FunctionDef | ast.AsyncFunctionDef, file Returns: list of style errors found """ - errors = [] + errors: list[models.StyleError] = [] docstring = ast.get_docstring(node) if not docstring: diff --git a/checkers/imports.py b/checkers/imports.py index a235921..ca9345e 100644 --- a/checkers/imports.py +++ b/checkers/imports.py @@ -24,7 +24,7 @@ def collect_imports(tree: ast.AST) -> tuple[list[ast.Import | ast.ImportFrom], l return imports + import_froms, import_froms -def check_imports(all_imports: list[ast.AST], import_froms: list[ast.ImportFrom], used_names: set[str], file_path: Path, ignore_codes: set[str]) -> list[models.StyleError]: +def check_imports(all_imports: list[ast.Import | ast.ImportFrom], import_froms: list[ast.ImportFrom], used_names: set[str], file_path: Path, ignore_codes: set[str]) -> list[models.StyleError]: """Run all import-related checks. Args: @@ -56,7 +56,7 @@ def _check_import_order(imports: list[ast.Import | ast.ImportFrom], file_path: s Returns: list of style errors found """ - errors = [] + errors: list[models.StyleError] = [] if not imports: return errors @@ -164,7 +164,7 @@ def _check_unused_imports(imports: list[ast.Import | ast.ImportFrom], names_used try: with open(file_path, 'r', encoding='utf-8') as f: file_content = f.read() - except: + except(Exception): file_content = "" for imp in imports: @@ -217,7 +217,7 @@ def _check_unused_from_import_nodes(imp: ast.ImportFrom, names_used: set[str], f Returns: an unused import error, or None """ - errors = [] + errors: list[models.StyleError] = [] # Never flag __future__ imports as unused if imp.module == '__future__': diff --git a/checkers/security.py b/checkers/security.py index 11990ff..49fc940 100644 --- a/checkers/security.py +++ b/checkers/security.py @@ -115,7 +115,7 @@ def _check_sql_injection_call(node: ast.AST, file_path: str, ignore_codes: set[s Returns: the sql injection errors, if any """ - errors = [] + errors: list[models.StyleError] = [] if not isinstance(node, ast.Call): return errors if not (isinstance(node.func, ast.Attribute) and node.func.attr in ['execute', 'executemany']): @@ -167,7 +167,7 @@ def _check_shell_injection_call(node: ast.AST, file_path: str, ignore_codes: set Returns: the shell injection errors, if any """ - errors = [] + errors: list[models.StyleError] = [] if not isinstance(node, ast.Call): return errors is_bad_attr = isinstance(node.func, ast.Attribute) and node.func.attr in ['system', 'popen', 'spawn', 'exec'] diff --git a/config.py b/config.py index d1a8dcc..d36641b 100644 --- a/config.py +++ b/config.py @@ -48,7 +48,7 @@ def load_ignore_names() -> set[str]: Returns: Set of names to ignore in style checking """ - ignore_names = set() + ignore_names: set = set() ignore_file = Path('.standardignore') if not ignore_file.exists(): diff --git a/requirements.txt b/requirements.txt index 1855cd0..e94e123 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -pathspec==0.12.1 \ No newline at end of file +pathspec ~= 1.1 \ No newline at end of file From 1929fa75e8ad06c0b6aceca86d78be90675c7b3e Mon Sep 17 00:00:00 2001 From: Emaniacinator Date: Mon, 15 Jun 2026 14:11:02 -0600 Subject: [PATCH 2/5] Fixed some odd setting of variables --- StandardCheck.py | 3 --- checkers/common_nodes.py | 3 --- checkers/complexity.py | 2 +- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/StandardCheck.py b/StandardCheck.py index d3ae647..9761558 100644 --- a/StandardCheck.py +++ b/StandardCheck.py @@ -28,7 +28,6 @@ def visit_node(node: ast.AST, file_path: str, ignore_codes: set[str], ignore_nam Returns: list of style errors found """ - ignore_names = ignore_names or set() if isinstance(node, ast.ClassDef): return common_nodes_module.check_class(node, file_path, ignore_codes, ignore_names) @@ -53,8 +52,6 @@ def check_file(file_path: Path, ignore_codes: set[str], ignore_names: set[str] = list of style errors found """ errors = [] - ignore_names = ignore_names or set() - config = config or {} max_complexity = config.get('max_complexity', 15) max_indentation = config.get('max_indentation', 4) diff --git a/checkers/common_nodes.py b/checkers/common_nodes.py index e976138..df5c5d1 100644 --- a/checkers/common_nodes.py +++ b/checkers/common_nodes.py @@ -19,7 +19,6 @@ def check_variable(node: ast.Name, file_path: str, ignore_codes: set[str], ignor list of style errors found """ errors: list[models.StyleError] = [] - ignore_names = ignore_names or set() # Skip if name should be ignored if file_utils_module.should_ignore_name(node.id, ignore_names): @@ -51,7 +50,6 @@ def check_class(node: ast.ClassDef, file_path: str, ignore_codes: set[str], igno list of style errors found """ errors: list[models.StyleError] = [] - ignore_names = ignore_names or set() # Skip if name should be ignored if file_utils_module.should_ignore_name(node.name, ignore_names): @@ -111,7 +109,6 @@ def check_function(node: ast.FunctionDef | ast.AsyncFunctionDef, file_path: str, list of style errors found """ errors: list[models.StyleError] = [] - ignore_names = ignore_names or set() is_test_file = 'test' in file_path.lower() if file_utils_module.should_ignore_name(node.name, ignore_names): diff --git a/checkers/complexity.py b/checkers/complexity.py index 0c79ffe..3bede76 100644 --- a/checkers/complexity.py +++ b/checkers/complexity.py @@ -3,7 +3,7 @@ import models as models -def check_complexity(tree: ast.Module, content: str, file_path: str, ignore_codes: set[str], max_complexity: int = 15, max_indentation: int = 4) -> list[models.StyleError]: +def check_complexity(tree: ast.AST, content: str, file_path: str, ignore_codes: set[str], max_complexity: int = 15, max_indentation: int = 4) -> list[models.StyleError]: """Check cyclomatic complexity and indentation depth for all functions in a file. Args: From 43c876323ccaec875172ba73c5b34eee84736053 Mon Sep 17 00:00:00 2001 From: Emaniacinator Date: Mon, 15 Jun 2026 14:23:48 -0600 Subject: [PATCH 3/5] Fixed the documentation --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9d2b02a..40b3645 100644 --- a/README.md +++ b/README.md @@ -50,12 +50,12 @@ The above entries in a `.standardignore` would have the checker skip over the fo Using the `.standardignore` file specified in the section above, specific function and variable names can be skipped over on the check. -The syntax to do so is the use of the `!` before the name of the variable/function to ignore. +The syntax to do so is the use of the `name:` before the name of the variable/function to ignore. For example ```cmd -!sleep_for_retry +name: sleep_for_retry ``` The above example ignores the sleep_for_retry function when applying standards as the name is required as it is an overwrite of an outside modules functionality. From 9e85c34616e68e70024b89febda81d06079093ed Mon Sep 17 00:00:00 2001 From: Emaniacinator Date: Mon, 15 Jun 2026 14:30:17 -0600 Subject: [PATCH 4/5] Running a quick experiment on the empty brackets --- StandardCheck.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StandardCheck.py b/StandardCheck.py index 9761558..484f2cd 100644 --- a/StandardCheck.py +++ b/StandardCheck.py @@ -39,7 +39,7 @@ def visit_node(node: ast.AST, file_path: str, ignore_codes: set[str], ignore_nam return [] -def check_file(file_path: Path, ignore_codes: set[str], ignore_names: set[str] = set(), config: dict[str, Any] = {}) -> list[models.StyleError]: +def check_file(file_path: Path, ignore_codes: set[str], ignore_names: set[str] = set(), config: dict[str, Any] = None) -> list[models.StyleError]: """Check a single Python file. Args: From 601a13f0da14c0c40dcc4b9d94f33c8067590459 Mon Sep 17 00:00:00 2001 From: Emaniacinator Date: Mon, 15 Jun 2026 14:32:14 -0600 Subject: [PATCH 5/5] Minor type security improvment, standard check fix --- StandardCheck.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/StandardCheck.py b/StandardCheck.py index 484f2cd..538590c 100644 --- a/StandardCheck.py +++ b/StandardCheck.py @@ -39,7 +39,7 @@ def visit_node(node: ast.AST, file_path: str, ignore_codes: set[str], ignore_nam return [] -def check_file(file_path: Path, ignore_codes: set[str], ignore_names: set[str] = set(), config: dict[str, Any] = None) -> list[models.StyleError]: +def check_file(file_path: Path, ignore_codes: set[str], ignore_names: set[str] = set(), config: dict[str, Any] | None = None) -> list[models.StyleError]: """Check a single Python file. Args: @@ -51,6 +51,9 @@ def check_file(file_path: Path, ignore_codes: set[str], ignore_names: set[str] = Returns: list of style errors found """ + if not config: + config = {} + errors = [] max_complexity = config.get('max_complexity', 15) max_indentation = config.get('max_indentation', 4)