Fix: Handle null line/column values in ESLint and Bandit parsers

- Fix TypeError when linters return null instead of missing fields
  - Use 'or' operator to safely convert null to 0
  - Affects only JSON-based parsers (ESLint, Bandit)
  - Line 0 indicates file-level or configuration issues

  Fixes GitHub issue: "TypeError: '<' not supported between instances of 'str' and 'NoneType'"
This commit is contained in:
TheAuditorTool
2025-09-09 17:46:15 +07:00
parent 2520ad8698
commit 4f6729d64c

View File

@@ -67,8 +67,8 @@ def parse_eslint_output(output: str, workset_files: set[str]) -> tuple[list[dict
translated = { translated = {
"tool": "eslint", "tool": "eslint",
"file": file_str, "file": file_str,
"line": int(message.get("line", 0)), "line": int(message.get("line") or 0),
"column": int(message.get("column", 0)), "column": int(message.get("column") or 0),
"rule": message.get("ruleId", ""), # Empty not "unknown" "rule": message.get("ruleId", ""), # Empty not "unknown"
"message": message.get("message", ""), "message": message.get("message", ""),
"severity": standard_severity, # Use standardized severity "severity": standard_severity, # Use standardized severity
@@ -489,8 +489,8 @@ def parse_bandit_output(output: str, workset_files: set[str]) -> list[dict[str,
translated = { translated = {
"tool": "bandit", "tool": "bandit",
"file": matched_file, # Use the matched relative path from workset "file": matched_file, # Use the matched relative path from workset
"line": int(result.get("line_number", 0)), "line": int(result.get("line_number") or 0),
"column": int(result.get("col_offset", 0)), "column": int(result.get("col_offset") or 0),
"rule": result.get("test_id", ""), "rule": result.get("test_id", ""),
"message": result.get("issue_text", ""), "message": result.get("issue_text", ""),
"severity": severity_map.get(result.get("issue_severity", "MEDIUM"), "warning"), "severity": severity_map.get(result.get("issue_severity", "MEDIUM"), "warning"),