fix: auto-fix code issues (cron)

- 修复重复导入/字段
- 修复异常处理
- 修复PEP8格式问题
- 添加类型注解
This commit is contained in:
AutoFix Bot
2026-03-03 06:03:38 +08:00
parent 2a0ed6af4d
commit 9fd1da8fb7
41 changed files with 901 additions and 768 deletions

View File

@@ -41,7 +41,7 @@ def check_duplicate_imports(content: str, file_path: Path) -> list[dict]:
"type": "duplicate_import",
"content": line_stripped,
"original_line": imports[line_stripped],
}
},
)
else:
imports[line_stripped] = i
@@ -74,7 +74,7 @@ def check_line_length(content: str, file_path: Path) -> list[dict]:
"type": "line_too_long",
"length": len(line),
"content": line[:80] + "...",
}
},
)
return issues
@@ -102,7 +102,7 @@ def check_unused_imports(content: str, file_path: Path) -> list[dict]:
for name, node in imports.items():
if name not in used_names and not name.startswith("_"):
issues.append(
{"line": node.lineno, "type": "unused_import", "name": name}
{"line": node.lineno, "type": "unused_import", "name": name},
)
except SyntaxError:
pass
@@ -123,13 +123,13 @@ def check_string_formatting(content: str, file_path: Path) -> list[dict]:
"line": i,
"type": "percent_formatting",
"content": line.strip()[:60],
}
},
)
# 检查 .format()
if ".format(" in line:
if not line.strip().startswith("#"):
issues.append(
{"line": i, "type": "format_method", "content": line.strip()[:60]}
{"line": i, "type": "format_method", "content": line.strip()[:60]},
)
return issues
@@ -172,7 +172,7 @@ def check_magic_numbers(content: str, file_path: Path) -> list[dict]:
"type": "magic_number",
"value": match,
"content": line.strip()[:60],
}
},
)
return issues
@@ -199,7 +199,7 @@ def check_sql_injection(content: str, file_path: Path) -> list[dict]:
"type": "sql_injection_risk",
"content": line.strip()[:80],
"severity": "high",
}
},
)
return issues
@@ -217,7 +217,7 @@ def check_cors_config(content: str, file_path: Path) -> list[dict]:
"type": "cors_wildcard",
"content": line.strip(),
"severity": "medium",
}
},
)
return issues
@@ -339,7 +339,7 @@ def generate_report(all_issues: dict) -> str:
lines.append(f"### {file_path}")
for issue in manual_issues:
lines.append(
f"- **{issue['type']}** (第 {issue['line']} 行): {issue.get('content', '')}"
f"- **{issue['type']}** (第 {issue['line']} 行): {issue.get('content', '')}",
)
total_manual += len(manual_issues)
@@ -376,7 +376,7 @@ def git_commit_and_push() -> None:
# 检查是否有修改
result = subprocess.run(
["git", "status", "--porcelain"], capture_output=True, text=True
["git", "status", "--porcelain"], capture_output=True, text=True,
)
if not result.stdout.strip():