@@ -304,39 +304,85 @@ WooCommerce Blocks checkout requires testing in WordPress with WooCommerce Block
304304
305305### Overview
306306
307- The project uses static analysis and code style tools to catch bugs before runtime and maintain consistent code style :
307+ The project uses automated linting and static analysis tools with git hooks for an optimized developer workflow :
308308
309- - ** PHPStan** - Static analysis to catch type errors, undefined methods, and bugs
310- - ** PHPCS** - WordPress Coding Standards enforcement
311- - ** PHPCBF** - Automatic code style fixer
312- - ** Pre-commit hooks** - Automated checks before committing code
309+ - ** JavaScript/CSS** : ESLint + Stylelint (via ` @wordpress/scripts ` )
310+ - ** PHP Code Style** : PHPCS (WordPress Coding Standards) + PHPCBF (auto-fixer)
311+ - ** PHP Static Analysis** : PHPStan Level 4 (type checking, bug detection)
312+ - ** Git Hooks** : Husky + lint-staged for automatic fixing on commit
313+ - ** Commit Messages** : Commitlint (conventional commits validation)
313314
314- ### Running Linters
315+ ### Automated Workflow (Git Hooks)
315316
316- ``` bash
317- # Run all linters (PHP + JS + CSS)
318- yarn lint
317+ ** Pre-commit Hook** (~ 0.9s - fast!):
318+ - Runs ` lint-staged ` to auto-fix only staged files
319+ - PHP: ` phpcbf ` (auto-fixes WordPress coding standards)
320+ - JavaScript: ` eslint --fix ` (auto-fixes linting errors)
321+ - CSS: ` stylelint --fix ` (auto-fixes style errors)
322+ - ** Result** : All fixable issues are automatically corrected before commit
319323
320- # PHP Static Analysis (PHPStan)
321- yarn lint:php:phpstan
322- composer phpstan
324+ ** Commit-msg Hook** (instant):
325+ - Validates commit message follows conventional commits format
326+ - Types: ` feat: ` , ` fix: ` , ` docs: ` , ` refactor: ` , ` chore: ` , etc.
327+ - ** Result** : Invalid commit messages are rejected
323328
324- # PHP Code Style (PHPCS)
325- yarn lint:php:phpcs
326- composer phpcs
329+ ** Pre-push Hook** (~ 1s):
330+ - ** Branch Protection** : Blocks direct pushes to ` master ` /` main `
331+ - ** PHPStan** : Runs static analysis (moved from pre-commit for speed)
332+ - ** Result** : Type errors are caught before pushing to remote
327333
328- # Auto-fix PHP code style issues
329- yarn lint:php:fix
330- composer phpcbf
331-
332- # JavaScript linting
333- yarn lint:js
334- yarn lint:js-fix
334+ ### Running Linters Manually
335335
336- # CSS linting
337- yarn lint:css
336+ ``` bash
337+ # Auto-fix all issues at once (recommended workflow)
338+ yarn lint:fix
339+
340+ # Individual auto-fixers
341+ yarn lint:js-fix # Fix JavaScript
342+ yarn lint:css-fix # Fix CSS
343+ yarn lint:php:fix # Fix PHP code style (phpcbf)
344+
345+ # Linters only (no auto-fix)
346+ yarn lint # Check all (JS + CSS + PHP + PHPStan)
347+ yarn lint:js # Check JavaScript
348+ yarn lint:css # Check CSS
349+ yarn lint:php # Check PHP (PHPCS + PHPStan)
350+ yarn lint:php:phpcs # Check PHP code style only
351+ yarn lint:php:phpstan # Check PHP static analysis only
338352```
339353
354+ ### Developer Workflow
355+
356+ ** Recommended workflow for best experience:**
357+
358+ 1 . ** Make your changes** in the codebase
359+ 2 . ** Before staging** : Run ` yarn lint:fix ` to auto-fix all issues
360+ 3 . ** Stage your files** : ` git add <files> `
361+ 4 . ** Commit** : ` git commit -m "feat: your message" `
362+ - Pre-commit hook auto-fixes staged files (~ 0.9s)
363+ - Commit-msg hook validates message format
364+ 5 . ** Push** : ` git push `
365+ - Pre-push hook runs PHPStan (~ 1s)
366+ - Branch protection prevents pushing to master
367+
368+ ** If pre-push fails (PHPStan errors)** :
369+ - Fix the type errors reported by PHPStan
370+ - Commit the fixes
371+ - Push again
372+
373+ ### Configuration Files
374+
375+ - ** ` .lintstagedrc.json ` ** - Auto-fix configuration for staged files
376+ - ** ` .husky/pre-commit ` ** - Runs lint-staged on commit
377+ - ** ` .husky/commit-msg ` ** - Validates commit messages
378+ - ** ` .husky/pre-push ` ** - Runs PHPStan + branch protection
379+ - ** ` .eslintrc.js ` ** - JavaScript linting rules
380+ - ** ` .eslintignore ` ** - Excludes ` public/ ` from JS linting
381+ - ** ` .stylelintignore ` ** - Excludes ` public/ ` from CSS linting
382+ - ** ` phpcs.xml ` ** - PHP code style rules (WordPress standards)
383+ - ** ` phpstan.neon ` ** - PHP static analysis configuration (Level 4)
384+ - ** ` commitlint.config.js ` ** - Commit message validation
385+
340386### PHPStan Configuration
341387
342388** Configuration** : ` phpstan.neon `
@@ -357,11 +403,13 @@ composer phpstan -- src/Gateways/PaymentMethods/WCGatewayMoneiCC.php
357403
358404### PHPCS WordPress Coding Standards
359405
360- ** Configuration** : ` . phpcs.xml.dist `
406+ ** Configuration** : ` phpcs.xml `
361407- WordPress-Core ruleset
362408- PSR-4 autoloading compatibility
363409- Tabs for indentation (WordPress standard)
364410- File naming follows WordPress conventions
411+ - Files checked: ` src/ ` and ` includes/ `
412+ - Ignores warnings (only errors fail the build)
365413
366414** Auto-fixing issues** :
367415``` bash
@@ -372,16 +420,23 @@ composer phpcbf
372420composer phpcbf -- src/Gateways/PaymentMethods/WCGatewayMoneiCC.php
373421```
374422
375- ### Pre-commit Hooks
423+ ### Git Hooks Best Practices
376424
377- ** File** : ` .husky/pre-commit `
425+ ** CRITICAL** : NEVER use ` --no-verify ` to bypass git hooks!
426+ - Git hooks auto-fix issues and catch errors before they reach the repository
427+ - If a hook fails, fix the actual errors instead of bypassing the check
428+ - Using ` --no-verify ` can introduce bugs and break the build
429+ - Pre-commit is fast (~ 0.9s) and only checks/fixes staged files
378430
379- Automatically runs PHPStan on staged PHP files before each commit. This prevents committing code with type errors.
431+ ** Branch Protection** :
432+ - Direct pushes to ` master ` /` main ` are automatically blocked
433+ - Always work in feature branches: ` git checkout -b feat/my-feature `
434+ - Create pull requests for code review before merging to master
380435
381- ** CRITICAL ** : NEVER use ` --no-verify ` to bypass pre-commit hooks!
382- - Pre-commit hooks are there to catch errors before they reach the repository
383- - If the hook fails, fix the actual errors instead of bypassing the check
384- - Using ` --no-verify ` can introduce bugs and break the build
436+ ** Performance ** :
437+ - Pre-commit hook is optimized for speed ( ~ 0.9s)
438+ - PHPStan runs only on pre-push ( ~ 1s) to keep commits fast
439+ - lint-staged only processes staged files, not the entire codebase
385440
386441### Common PHPStan Errors & Fixes
387442
0 commit comments