This guide explains how to use the VS Code integration with Captain Hook, code quality tools, and Magento 2 coding standards.
- Press
Ctrl+Shift+P(Windows/Linux) orCmd+Shift+P(Mac) - Type "Tasks: Run Task"
- Select from available tasks
- Press
Ctrl+Shift+Bto run build tasks - Configure custom shortcuts in VS Code keybindings
- Menu: Terminal → Run Task...
- Purpose: Install/reinstall git hooks
- How to run:
Ctrl+Shift+P→ "Tasks: Run Task" → "Captain Hook: Install"
- When to use:
- After cloning the repository
- If hooks aren't working properly
- After updating Captain Hook configuration
- Purpose: Manually test pre-commit checks without committing
- How to run:
Ctrl+Shift+P→ "Tasks: Run Task" → "Captain Hook: Run Pre-Commit"
- What it checks:
- PHP syntax (parallel-lint)
- PHP code standards (PHPCS)
- PHPStan static analysis
- Composer lock file validation
- Composer.json normalization
- Purpose: Test commit message validation
- How to run:
Ctrl+Shift+P→ "Tasks: Run Task" → "Captain Hook: Run Commit-Msg"
- Validates:
- Commit message format:
CU-[id]: message - Branch naming:
feature/CU-xxx-descriptionorhotfix/CU-xxx-descriptionorbugfix/CU-xxx-description
- Commit message format:
- Purpose: View current Captain Hook configuration
- How to run:
Ctrl+Shift+P→ "Tasks: Run Task" → "Captain Hook: Config Info"
- Purpose: Run PHP CodeSniffer on the current file
- How to run:
- Open a PHP file
Ctrl+Shift+P→ "Tasks: Run Task" → "PHPCS: Check Staged Files"
- Checks: Magento 2 coding standards
- Purpose: Run static analysis on current PHP file
- How to run:
- Open a PHP file
Ctrl+Shift+P→ "Tasks: Run Task" → "PHPStan: Analyze"
- Level: 1 (configurable in task)
- Purpose: Check PHP syntax errors in current file
- How to run:
- Open a PHP file
Ctrl+Shift+P→ "Tasks: Run Task" → "Parallel Lint: Check PHP Syntax"
Automatically runs when you git commit:
- Composer Lock Validation - Ensures composer.lock is in sync
- PHP Linting - Checks for syntax errors in staged PHP/PHTML files
- Composer.json Validation - For packages in composer/packages/envalo
- PHPStan - Static analysis on staged PHP files
- PHPCS - Coding standards check on staged PHP/PHTML/JS/HTML files
Automatically validates commit messages:
- Format: Must match
CU-[alphanumeric]: message - Example:
CU-2h2h2h: Fix checkout process - Branch: Must match
feature/CU-xxx-descriptionpattern
# Fix a single file
./vendor/bin/phpcbf path/to/file.php
# Fix all staged files
./vendor/bin/phpcbf $(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(php|phtml)$')# From project root
cd /home/goran/sites/SVPMagento2
# Run pre-commit checks
./vendor/bin/phpcs -q --standard=Magento2 -s app/design/frontend/Svp
./vendor/bin/phpcs -q --standard=Magento2 -s composer/packages/envalo- LESS/CSS files are automatically formatted on save
- Uses Stylelint with Magento 2 standards
- 4-space indentation
- Properties in alphabetical order
npx stylelint "**/*.less" --fixInstall these extensions for full functionality:
- PHP Intelephense - PHP intelligence
- PHPCS - PHP CodeSniffer integration
- PHP Sniffer - Additional PHPCS support
- ESLint - JavaScript linting
- Stylelint - LESS/CSS linting
- GitLens - Enhanced Git capabilities
- EditorConfig - Consistent coding styles
- Reinstall hooks: Run "Captain Hook: Install" task
- Check configuration: Run "Captain Hook: Config Info" task
- Verify git hooks exist:
ls -la .git/hooks/
- Ensure Magento coding standards are installed:
composer require magento/magento-coding-standard --dev
- Fix automatically where possible:
./vendor/bin/phpcbf path/to/file.php
- Ensure you're in the project root
- Reload VS Code window:
Ctrl+Shift+P→ "Developer: Reload Window"
- Check the error message for specific validation failure
- For commit message issues: Use format
CU-xxx: message - For code issues: Run the specific failed check manually and fix
- Always run pre-commit checks before committing
- Use the provided tasks to validate your code
- Fix issues immediately when detected
- Keep tools updated with
composer update - Follow branch naming conventions:
feature/CU-xxx-description
- Captain Hook:
tools/code-quality/captainhook/config.json - VS Code Settings:
.vscode/settings.json - VS Code Tasks:
.vscode/tasks.json - Stylelint:
.stylelintrc.json - Extensions:
.vscode/extensions.json
- Review this documentation
- Check the error messages carefully
- Run tasks with verbose output for more details
- Ask your team lead for specific project conventions