code-review
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCode Review Skill
代码审查技能
Automated code review and analysis tools.
自动化代码审查与分析工具。
When to Use
适用场景
- Review code changes before commit
- Check for security vulnerabilities
- Analyze code complexity
- Find bugs and issues
- Enforce coding standards
- 提交前审查代码变更
- 检查安全漏洞
- 分析代码复杂度
- 查找Bug与问题
- 强制执行编码规范
Pre-Commit Review
提交前审查
Git Diff Analysis
Git Diff 分析
bash
undefinedbash
undefinedSee unstaged changes
See unstaged changes
git diff
git diff
See staged changes
See staged changes
git diff --cached
git diff --cached
See changes in specific file
See changes in specific file
git diff path/to/file
git diff path/to/file
See changes since last commit
See changes since last commit
git diff HEAD~1
git diff HEAD~1
Compare branches
Compare branches
git diff main..feature-branch
undefinedgit diff main..feature-branch
undefinedStage Selective Changes
选择性暂存变更
bash
undefinedbash
undefinedInteractive staging
Interactive staging
git add -i
git add -i
Stage specific hunks
Stage specific hunks
git add -p path/to/file
git add -p path/to/file
Stage specific files
Stage specific files
git add -u
undefinedgit add -u
undefinedStatic Analysis
静态分析
Linting
Linting 代码检查
bash
undefinedbash
undefinedESLint (JavaScript/TypeScript)
ESLint (JavaScript/TypeScript)
npm run lint
eslint .
npm run lint
eslint .
ShellCheck (Shell scripts)
ShellCheck (Shell scripts)
shellcheck script.sh
shellcheck script.sh
hadolint (Dockerfiles)
hadolint (Dockerfiles)
hadolint Dockerfile
hadolint Dockerfile
yamllint (YAML files)
yamllint (YAML files)
yamllint .
yamllint .
jsonlint (JSON files)
jsonlint (JSON files)
jsonlint -c .jsonlintrc.json .
undefinedjsonlint -c .jsonlintrc.json .
undefinedCode Quality
代码质量检查
bash
undefinedbash
undefinedSonarQube (if configured)
SonarQube (if configured)
sonar-scanner
sonar-scanner
CodeClimate (if configured)
CodeClimate (if configured)
codeclimate analyze
codeclimate analyze
Complexity analysis
Complexity analysis
cloc --by-file .
undefinedcloc --by-file .
undefinedSecurity Scanning
安全扫描
bash
undefinedbash
undefinednpm audit
npm audit
npm audit
npm audit
Yarn audit
Yarn audit
yarn audit
yarn audit
Dependency check
Dependency check
npm outdated
npm outdated
GitHub security advisories
GitHub security advisories
gh api graphql -F query='{repository(owner:"owner",name:"repo"){vulnerabilityAlerts(first:10){nodes{packageName}}}}'
gh api graphql -F query='{repository(owner:"owner",name:"repo"){vulnerabilityAlerts(first:10){nodes{packageName}}}}'
secrets scanner
secrets scanner
git clone https://github.com/truffi/shellcheck
undefinedgit clone https://github.com/truffi/shellcheck
undefinedCode Review Commands
代码审查命令
Check for Common Issues
检查常见问题
bash
undefinedbash
undefinedFind TODO/FIXME comments
Find TODO/FIXME comments
grep -r "TODO|FIXME|XXX|HACK" --include="*.js" .
grep -r "TODO|FIXME|XXX|HACK" --include="*.js" .
Find console.log
Find console.log
grep -r "console." --include="*.js" .
grep -r "console." --include="*.js" .
Find hardcoded passwords
Find hardcoded passwords
grep -rE "password|secret|api[_-]?key" --include="*.js" . | grep -v node_modules
undefinedgrep -rE "password|secret|api[_-]?key" --include="*.js" . | grep -v node_modules
undefinedFile Statistics
文件统计
bash
undefinedbash
undefinedLines of code by file
Lines of code by file
find . -name "*.js" -exec wc -l {} + | sort -n
find . -name "*.js" -exec wc -l {} + | sort -n
Count functions
Count functions
find . -name "*.js" -exec grep -l "function|=>" {} + | wc -l
undefinedfind . -name "*.js" -exec grep -l "function|=>" {} + | wc -l
undefinedGitHub PR Reviews
GitHub PR 审查
Get PR Information
获取PR信息
bash
undefinedbash
undefinedGet PR diff
Get PR diff
gh pr diff 55 --repo owner/repo
gh pr diff 55 --repo owner/repo
Get PR files
Get PR files
gh pr view 55 --json files --repo owner/repo
gh pr view 55 --json files --repo owner/repo
Get PR reviews
Get PR reviews
gh pr view 55 --json reviews --repo owner/repo
undefinedgh pr view 55 --json reviews --repo owner/repo
undefinedReview Checklist
审查检查清单
bash
#!/bin/bashbash
#!/bin/bashCode review checklist script
Code review checklist script
echo "=== Code Review Checklist ==="
echo ""
echo "=== Code Review Checklist ==="
echo ""
Check for TODO/FIXME
Check for TODO/FIXME
TODOS=$(grep -r "TODO|FIXME" --include="*.js" . | wc -l)
echo "TODO/FIXME comments: $TODOS"
TODOS=$(grep -r "TODO|FIXME" --include="*.js" . | wc -l)
echo "TODO/FIXME comments: $TODOS"
Check for console.log
Check for console.log
LOGS=$(grep -r "console.log" --include="*.js" . | wc -l)
echo "Console logs: $LOGS"
LOGS=$(grep -r "console.log" --include="*.js" . | wc -l)
echo "Console logs: $LOGS"
Check for hardcoded secrets
Check for hardcoded secrets
SECRETS=$(grep -rE "password|secret|api[_-]?key" --include="*.js" . | grep -v node_modules | wc -l)
echo "Potential secrets: $SECRETS"
SECRETS=$(grep -rE "password|secret|api[_-]?key" --include="*.js" . | grep -v node_modules | wc -l)
echo "Potential secrets: $SECRETS"
Check test coverage
Check test coverage
echo ""
echo "Run: npm test -- --coverage"
echo ""
echo "Run: npm test -- --coverage"
Check linting
Check linting
echo ""
echo "Run: npm run lint"
undefinedecho ""
echo "Run: npm run lint"
undefinedAutomated Review Scripts
自动化审查脚本
Pre-commit Hook
提交前钩子(Pre-commit Hook)
bash
undefinedbash
undefined.git/hooks/pre-commit
.git/hooks/pre-commit
#!/bin/bash
#!/bin/bash
Run linting
Run linting
npm run lint
if [ $? -ne 0 ]; then
echo "Linting failed"
exit 1
fi
npm run lint
if [ $? -ne 0 ]; then
echo "Linting failed"
exit 1
fi
Run tests
Run tests
npm test
if [ $? -ne 0 ]; then
echo "Tests failed"
exit 1
fi
undefinednpm test
if [ $? -ne 0 ]; then
echo "Tests failed"
exit 1
fi
undefinedGitHub Actions Review
GitHub Actions 自动化审查
yaml
name: Code Review
on: [pull_request]
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run linter
run: npm run lint
- name: Run tests
run: npm test
- name: Security audit
run: npm audit
- name: Build
run: npm run buildyaml
name: Code Review
on: [pull_request]
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run linter
run: npm run lint
- name: Run tests
run: npm test
- name: Security audit
run: npm audit
- name: Build
run: npm run buildBest Practices
最佳实践
- Review small changes - Large PRs are hard to review thoroughly
- Check tests - Ensure new code has tests
- Look for bugs - Common issues: null checks, error handling, edge cases
- Check security - No secrets, validate inputs, use parameterized queries
- Check performance - N+1 queries, unnecessary loops, memory leaks
- Check readability - Clear naming, comments for complex logic
- Check architecture - Follow project patterns, proper separation
- 审查小型变更 - 大型PR难以全面审查
- 检查测试 - 确保新代码配有测试用例
- 查找Bug - 常见问题:空值检查、错误处理、边界情况
- 检查安全性 - 无硬编码密钥、验证输入、使用参数化查询
- 检查性能 - N+1查询、不必要的循环、内存泄漏
- 检查可读性 - 清晰的命名、复杂逻辑添加注释
- 检查架构 - 遵循项目模式、合理的职责分离
Notes
注意事项
- Use to see what changed in a specific commit
git show - Use to see who changed each line
git blame - Use to save work in progress
git stash - Thepopebot can perform code reviews using LLM analysis
- 使用 查看特定提交的变更内容
git show - 使用 查看每行代码的修改者
git blame - 使用 保存正在进行的工作
git stash - Thepopebot 可通过LLM分析执行代码审查