feat: add ast-grep code quality checker framework#176
Open
suyiiyii wants to merge 8 commits into
Open
Conversation
Add ast-grep based Python code quality checker with 5 rules: - Type annotation upgrade (Optional[Type] → Type | None) - Walrus operator optimization (:= simplification) - Print statement detection (should use logger) - Empty except block detection - Broad exception catch detection Also include automated fix script for applying type hint updates. Files added: - scripts/ast_grep_check.py: Main checker script (374 lines) - apply-ast-grep-fixes.sh: Automated type hint upgrade script Co-authored-by: Claude Code <claude@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
🚀 Lint & Format Check Results: ❌ FAILEDWhat was checked:
❌ Some checks failed!How to fix:
uv run python scripts/lint.py
git add .
git commit -m "fix: apply lint and format fixes"
git push
Individual fix commands:Code Quality (ast-grep): uv run python scripts/ast_grep_check.py
# Review reported issues and fix manuallyBackend (Ruff): uv run ruff check --fix
uv run ruff formatFrontend: cd frontend
pnpm lint --fix
pnpm format
cd ..This is an automated check. For questions, ask in the PR discussion. |
Remove apply-ast-grep-fixes.sh to maintain check-only approach. The ast-grep checker scripts/ast_grep_check.py is designed for code quality checking only, without auto-fix capability. Users should manually review and fix issues reported by the checker.
Add ast-grep code quality check to CI/CD pipeline: Changes: - Install ast-grep CLI tool - Run ast-grep checker (non-blocking) - Update PR comment to include ast-grep results The ast-grep check is informational (non-blocking) to avoid failing PRs for style improvements, while still alerting developers to potential code quality issues. Co-authored-by: Claude Code <claude@anthropic.com>
Remove the non-blocking `|| echo` wrapper from ast-grep check to align with other lint checks (ruff, eslint, etc.). The ast-grep check should fail the PR if code quality issues are found, consistent with the blocking nature of all other lint checks. Co-authored-by: Claude Code <claude@anthropic.com>
Remove complex YAML-based rules that don't work with ast-grep CLI. Keep only the no-print rule which uses a simple expression pattern. Changes: - Simplify RULES to only include no-print check - Fix check_rule to use direct -p parameter - Remove tempfile and os imports (no longer needed) - Fix pattern extraction logic This makes the checker functional but limited. We can add more rules later with correct ast-grep syntax. Co-authored-by: Claude Code <claude@anthropic.com>
- Fix pattern from `print($_)` to `print($$$)` to properly match print calls - `$_` only matches a single node, causing ERROR nodes in ast-grep - `$$$` matches zero or more arguments, which is correct for print() - Fix JSON field from `path` to `file` to match ast-grep's output format - This allows the checker to correctly identify print() statements in codebase
- AutoGLM_GUI/__main__.py: - Add logger import - Replace startup banner print statements with logger.info - Replace browser error print with logger.warning - Replace port detection/error prints with logger.info/error - AutoGLM_GUI/adb/connection.py: - Add logger import - Replace error print with logger.error - AutoGLM_GUI/agents/glm/agent.py: - Replace verbose mode prints with logger.info - Replace print_chunk function to use logger.info - AutoGLM_GUI/agents/mai/agent.py: - Replace verbose mode prints with logger.info - Replace traceback.print_exc() with logger.exception() - Replace performance stats prints with logger.info All changes ensure proper logging through the project's logger instead of using print() statements, which improves log management and consistency.
- Format command list with proper indentation for better readability - Add trailing commas to RuleResult initialization calls for consistency - Simplify JSON decode error handling by keeping all parameters on single line when appropriate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📋 Summary
添加基于 ast-grep 的 Python 代码质量检查脚本框架。
当前版本实现了一个可用的检查规则:
print()的地方,应使用 logger✨ 新增功能
ast-grep 代码质量检查脚本 (
scripts/ast_grep_check.py)当前规则:
特性:
lint.py设计模式一致)技术细节:
sg run -p参数传递简单表达式🔧 使用方法
运行检查
本地测试结果
当前版本发现了 47 处使用
print()的代码:🔮 未来改进
这是一个框架性质的 PR,当前实现了:
未来规划:
📝 技术细节
依赖:
.github/workflows/pr-lint.yml限制:
📚 相关文档
Co-authored-by: Claude Code claude@anthropic.com