pants-format-check
Runs pants formatting, linting, and type checking on Python code, fixing issues automatically. Use when finishing implementation, before committing code, or when the user asks to format, lint, or check code quality.
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
Pants Format and Lint Check
When to Use
Apply this skill automatically when:
- Finishing implementation of a feature or fix
- User asks to format, lint, or check code
- Before committing changes
- After modifying Python files
Workflow
Follow these steps in order:
Step 1: Remove Unused Imports
Remove unused imports first to prevent common linting errors:
pants --changed-since=HEAD fix ::
This fixes import issues automatically before running full checks.
Step 2: Run Full Format, Lint, and Check
Run the complete pants check suite:
pants fmt lint check ::
This command:
- fmt: Auto-formats code (isort, black, etc.)
- lint: Runs linters (flake8, pylint, etc.)
- check: Runs type checking (mypy)
Step 3: Review and Fix Remaining Issues
If errors remain after Step 2:
- Read the error output - pants provides specific file locations and line numbers
- Fix the issues - address each error reported
-
Re-run:
pants fmt lint check :: - Repeat until all checks pass
Common Issues and Solutions
Import Errors
If you see "unused import" or "import not found":
- Remove unused imports
- Add missing dependencies to BUILD files
- Check import paths are correct
Type Errors
If mypy reports type issues:
- Add type hints where missing
- Fix incorrect type annotations
- Use
# type: ignorecomments only as a last resort
Style Errors
If flake8/pylint reports style issues:
- Most are auto-fixed by
pants fmt - For manual fixes, follow the error message guidance
- Check
.flake8and.isort.cfgfor project conventions
Success Criteria
✅ All checks pass with no errors ✅ No warnings that need attention ✅ Code is properly formatted and typed
Notes
- Run this from the repository root (where
pants.tomlis located) - The
::selector checks all targets in the repo - For faster checks on specific files, use:
pants fmt lint check path/to/file.py - Always run before creating commits to catch issues early
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-03-11
- 索引更新时间
- 2026-03-11
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!