.ai/skills/woocommerce-dev-cycle/code-quality.md
When making changes to the WooCommerce codebase, run these commands to ensure code quality and adherence to coding standards.
For detailed PHP linting patterns and common issues, see php-linting-patterns.md.
For markdown linting rules and workflow, see markdown-linting.md.
pnpm run lint:changes:branch:php
Checks changed files for WordPress Coding Standards violations (read-only).
# Automatically fix PHP code style issues
pnpm run lint:php:fix
This command:
If you need more control, you can use phpcs and phpcbf directly:
# Check specific file or directory
vendor/bin/phpcs path/to/file.php
# Check with specific standard
vendor/bin/phpcs --standard=WordPress path/to/file.php
# Fix specific file
vendor/bin/phpcbf path/to/file.php
# Show all violations (including warnings)
vendor/bin/phpcs -s path/to/file.php
# Run JS linting on changes in your branch
pnpm run lint:changes:branch:js
This command:
Important: The plugin-level .eslintignore excludes client/blocks/, so lint:changes:branch:js will not catch eslint or prettier issues in blocks code. For blocks changes, also run the blocks package lint:
# Check blocks JS/TS (includes prettier via eslint plugin)
pnpm --filter=@woocommerce/block-library lint:js
# Auto-fix blocks JS/TS issues
pnpm --filter=@woocommerce/block-library lint:js-fix
For detailed JavaScript/TypeScript linting configuration and patterns, see client/admin/CLAUDE.md.
Always lint markdown files after making changes. See markdown-linting.md for complete details.
Quick commands:
# Auto-fix most issues
markdownlint --fix path/to/file.md
# Check for remaining errors
markdownlint path/to/file.md
Important: Only fix linting errors for code that has been added or modified in the branch you are working on.
Do not fix linting errors in unrelated code unless specifically asked to do so.
Why?
# 1. Make your code changes
# ... edit files ...
# 2. Check what you've changed
git status
git diff
# 3. Run linting on your changes
pnpm run lint:changes:branch:php
# 4. Fix issues automatically
pnpm run lint:php:fix
# 5. Review the fixes
git diff
# 6. If needed, check JavaScript changes
pnpm run lint:changes:branch:js
# 7. Commit your changes
git add .
git commit -m "Your commit message"
FILE: /path/to/file.php
----------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
----------------------------------------------------------------------
12 | ERROR | [x] Expected 1 space after opening parenthesis;
| | 0 found
25 | ERROR | [ ] Variable "$orderID" is not in valid snake_case
| | format
----------------------------------------------------------------------
Legend:
[x] - Can be fixed automatically with phpcbf/lint:php:fix[ ] - Requires manual fixingSpacing issues - Usually auto-fixable
// Wrong
if($condition){
// Right
if ( $condition ) {
Naming conventions - Requires manual fix
// Wrong
$orderID
// Right
$order_id
Yoda conditions - Requires manual fix
// Wrong
if ( $value === 'active' )
// Right
if ( 'active' === $value )
Before committing your changes:
pnpm run lint:changes:branch:phppnpm run lint:php:fix if issues foundpnpm run lint:changes:branch:js if you modified JS filespnpm --filter=@woocommerce/block-library lint:js-fix if you modified blocks JS/TS filesgit diffCode quality checks fit into the overall development workflow:
WooCommerce may have additional linting scripts. Check available scripts:
# See all available scripts
pnpm run
# Common additional scripts may include:
pnpm run lint # Lint all files
pnpm run lint:fix # Fix all auto-fixable issues
pnpm run lint:php # PHP linting only
pnpm run lint:js # JavaScript linting only
Problem: Command fails with "command not found"
Solution: Install dependencies:
pnpm install
Problem: Linting reports issues in files you didn't change
Solution: Make sure you're using the branch-specific commands:
# Good - only checks your changes
pnpm run lint:changes:branch:php
# Avoid - checks entire codebase
pnpm run lint:php
Problem: Git conflicts after running lint:php:fix
Solution:
git diffgit checkout -- path/to/file.php