代码提交前(pre-commit)检查
run-pre-commit-checks
在提交代码前运行强制性的 pre-commit 检查,包括 lint(代码规范检查)、类型检查和单元测试。每次提交前都必须运行。
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 147
- Forks
- 83
01 前言 Front Matter
- name
- run-pre-commit-checks
- description
- Run the mandatory pre-commit checks before committing code. Includes lint, type checking, and unit tests. MUST be run before every commit.
- argument-hint
- --fix to auto-fix lint issues
03 SKILL.md 正文
Run Pre-Commit Checks
This skill defines the mandatory checks that must pass before any commit.
When to Use
- ALWAYS before committing code changes
- After fixing reviewer or Copilot review comments
- Before pushing changes
- When the maintainer agent requests pre-commit validation
Required Checks
All three checks must pass before committing:
1. Lint Check (Required)
npm run lint
What it checks:
- ESLint rules defined in
eslint.config.mjs - TypeScript-specific linting rules
- Import ordering and unused imports
- Code style consistency
To auto-fix issues:
npm run lint -- --fix
2. Type Check (Required)
npm run compile-tests
What it checks:
- TypeScript type errors
- Missing imports
- Type mismatches
- Strict null checks
Output location: out/ directory (not used for production)
3. Unit Tests (Required)
npm run unittest
What it checks:
- All unit tests in
src/test/pass - Tests run with Mocha framework
- Uses configuration from
build/.mocha.unittests.json
Full Pre-Commit Workflow
# Run all checks in sequence
npm run lint
npm run compile-tests
npm run unittest
# If all pass, commit
git add -A
git commit -m "feat: your change description (Fixes #N)"
Common Failures and Fixes
ESLint Errors
| Error | Fix |
|---|---|
@typescript-eslint/no-unused-vars |
Remove unused variable or prefix with _ |
import/order |
Run npm run lint -- --fix |
@typescript-eslint/no-explicit-any |
Add proper type annotation |
no-console |
Use traceLog/traceVerbose instead of console.log |
Type Errors
| Error | Fix |
|---|---|
TS2339: Property does not exist |
Check property name or add type guard |
TS2345: Argument type not assignable |
Check function parameter types |
TS2322: Type not assignable |
Add type assertion or fix type mismatch |
TS18048: possibly undefined |
Add null check or use optional chaining |
Test Failures
- Read the test failure message carefully
- Check if you changed behavior that tests depend on
- Update tests if behavior change is intentional
- Fix code if behavior change is unintentional
Integration with Review Process
The maintainer agent workflow requires:
Code Change → Reviewer Agent → Pre-Commit Checks → Commit
↓
Fix Issues → Re-run Reviewer → Pre-Commit Checks
Never skip pre-commit checks. They catch:
- Type errors that would break the extension
- Style inconsistencies
- Regressions in existing functionality
Automation Note
These checks should also be run:
- By CI on every PR (automated)
- After addressing review comments (manual trigger)
- Before merging (automated by CI)
The hooks system can automate running lint after file edits (see .github/hooks/).
04 同仓库更多 Skills
VS Code 设置优先级规则
settings-precedence
VS Code 设置优先级规则及常见陷阱。适用于任何读取或写入设置的代码。涵盖 getConfiguration 作用域、inspect() 与 get() 的区别,以及多工作区处理。
VS Code 扩展冒烟测试
run-smoke-tests
运行冒烟测试,在真实 VS Code 环境中验证扩展功能。在更改后检查基本功能是否正常工作时使用。
扩展组件集成测试运行
run-integration-tests
运行集成测试以验证扩展的各个组件能否正确协同工作。在修改组件交互或事件处理后使用此技能。
E2E 端到端测试运行
run-e2e-tests
运行 E2E 测试以验证完整的用户工作流(如环境的发现、创建和选择)。在发布前或进行重大变更后使用此技能。
Python 环境管理器探测
python-manager-discovery
针对特定环境管理器的探测模式及已知问题。在编写或审查 conda、poetry、pipenv、pyenv 或 venv 的环境探测代码时使用。
代码库健康快照生成
generate-snapshot
生成代码库健康快照,用于技术债务追踪与规划。分析 git 历史、代码复杂度、债务标记和依赖项,以识别热点区域和重构优先级。