PHPCS Git Check
PHPCS Git Check is a smart VS Code extension that runs PHPCS only on Git-changed lines (staged and unstaged), avoiding unnecessary warnings and noise. Ideal for teams working with large or legacy PHP codebases.
📦 Features
- Runs PHPCS only on changed lines from Git diff (staged + unstaged)
- Supports on save, on open, on focus, and on startup
- Debounced checks to avoid rapid duplicate runs
- Custom diagnostics colors (Warnings = yellow, Info = blue)
- Only checks
.php
files inside a Git repo
🚀 Commands
Command Palette → PHPCS Git Check: Run PHPCS on Changed Lines
⚙️ Settings
Setting |
Type |
Default |
Description |
phpcsGitCheck.checkOnStartup |
boolean |
true |
Automatically run on all changed files on startup |
phpcsGitCheck.checkOnSave |
boolean |
true |
Automatically run on save for PHP files |
phpcsGitCheck.checkOnOpen |
boolean |
true |
Run PHPCS when a file is opened |
phpcsGitCheck.checkOnFocus |
boolean |
true |
Run PHPCS when the editor gains focus |
🧪 Example
If you change lines 10–12 in a PHP file, the extension will:
- Use
git diff
and git diff --cached
to detect modified lines
- Run PHPCS on the file
- Show only errors/warnings that apply to those lines
📁 Files Used
phpcs.xml.dist
or phpcs.xml
(optional PHPCS config)
- Git commands:
git diff -U0 <file>
(unstaged changes)
git diff --cached -U0 <file>
(staged changes)
🧬 Diagnostics Behavior
PHPCS Severity |
Shown As |
VS Code Color |
ERROR |
⚠️ Warning |
Yellow |
WARNING |
ℹ️ Info |
Blue |
📦 Requirements
phpcs
must be installed globally and available in PATH
- Git repository must be initialized
🧩 Extension Author
Developed with ❤️ by Rohit Rasela
📌 Limitations
- Only works inside initialized Git repositories
- Only supports
.php
files
- Only checks Git-diffed lines — not the entire file
✅ Summary
PHPCS Git Check is the perfect linter for working on modern or legacy codebases, focusing only on what you’ve changed.
PHPCS Git Check gives you focused, efficient linting:
✅ Prevents noise from legacy code
✅ Checks what you actually changed
✅ Integrates cleanly into your Git workflow
🧪 Test Case Suggestions
1. Staged + Unstaged Changes
<?php
// Line 5: staged
echo "Hello, World!" ;
// Line 15: unstaged
if($foo==true){
echo 'bar';
}
Run:
git add yourfile.php
# Modify line 15 after adding
# Save in VS Code
→ The extension should report both line 5 and 15 issues.
Happy Coding! 🎉