β‘Pre-commit Setup
Based on Codacy analysis, this document outlines the comprehensive improvements made to our pre-commit hooks system.
π― Overview
We've enhanced your existing task-based workflow with proper pre-commit hooks that automatically catch and fix the issues identified by Codacy analysis.
What Was Added
β
Formal pre-commit hooks (.pre-commit-config.yaml)
β
Security scanning (bandit, safety)
β
Dependency vulnerability checks (trivy-style scanning)
β
Dockerfile linting (hadolint)
β
Shell script linting (shellcheck)
β
Custom security checks (shell=True detection)
β
Complexity analysis (radon)
β
Enhanced task commands (security, complexity, hooks management)
π οΈ Quick Setup
# Run the setup script
./scripts/setup-precommit.sh
# Or manual setup:
uv sync --extra dev
task hooks:setupπ Coverage Matrix - Codacy Issues Addressed
π¨ shell=True vulnerabilities
bandit, custom hook
β Active
Critical
π Hardcoded credentials
bandit
β Active
Medium
π Code complexity
radon
β Active
Medium
π¨ Trailing whitespace
trailing-whitespace
β Active
Low
π¨ Dead code
ruff
β Active
Low
π¦ Dependency CVEs
safety
β Active
Critical
π³ Dockerfile issues
hadolint
β Active
Medium
π YAML formatting
yamllint
β Enhanced
Low
π§ Tools Configuration
Security Tools
Bandit (Python Security)
Addresses: Issues #61 (shell=True), #64 (hardcoded credentials)
Safety (Dependency Vulnerabilities)
Addresses: Issue #65 (dependency CVEs)
Custom Shell=True Check
Addresses: Issue #61 (prevents future shell=True usage)
Code Quality Tools
Radon (Complexity Analysis)
Addresses: Issue #62 (method complexity)
Hadolint (Dockerfile)
Addresses: Issue #66 (Dockerfile security)
π Usage Guide
Daily Development Workflow
Commit Workflow
Security-Specific Commands
π Hook Categories
π΄ Critical (Always Run)
black - Code formatting
ruff - Linting and import sorting
mypy - Type checking
bandit - Security scanning
check-subprocess-shell - Prevent shell=True
trailing-whitespace - Fix style issues
π‘ Manual (Run as Needed)
safety - Dependency vulnerabilities
complexity-check - Code complexity analysis
check-test-credentials - Test credential validation
π’ Informational
hadolint - Dockerfile linting
shellcheck - Shell script linting
yamllint - YAML formatting
ποΈ Configuration Files
.pre-commit-config.yaml
.pre-commit-config.yamlMain configuration with all hooks and settings.
pyproject.toml (Enhanced)
pyproject.toml (Enhanced)Taskfile.yml (Enhanced)
Taskfile.yml (Enhanced)Added security, complexity, and hooks management tasks.
π§ Customization
Adjusting Security Rules
Complexity Thresholds
Adding Custom Hooks
π― Next Steps
Immediate Actions
Run setup:
./scripts/setup-precommit.shAddress critical issues: Focus on GitHub issues #61 and #65
Test workflow: Make a test commit to verify hooks work
Ongoing Maintenance
Weekly:
task hooks:updateto update hook versionsMonthly:
pre-commit run safety --hook-stage manualfor dependency checksBefore releases:
task complexityto check code quality trends
Integration with CI/CD
Your existing autofix workflow will work seamlessly with these changes:
Consider adding:
π€ Troubleshooting
Hook Failures
Performance Issues
π Benefits
Security
Automatic detection of shell=True vulnerabilities
Dependency scanning for known CVEs
Credential leak prevention in test files
Code Quality
Complexity monitoring to prevent technical debt
Consistent formatting across all files
Type safety enforcement
Developer Experience
Faster feedback - catch issues before CI
Automatic fixes for many issues
Clear error messages with fix suggestions
Team Consistency
Standardized workflow across all developers
Automated enforcement of coding standards
Reduced code review overhead
π Your pre-commit setup now addresses all Codacy issues while maintaining your existing workflow!
For questions or issues, refer to:
Python Coding Standard
GitHub Issues #61-66 (Codacy issues)
Last updated
Was this helpful?