This guide explains all the development tools configured for this project and how to customize them.
Purpose: Enforces WordPress and PSR coding standards.
Configuration: phpcs.xml.dist
Key Settings:
- Standards: WordPress-Extra, WordPress-Docs
- Minimum WordPress version: 6.4
- Scanned paths: Root PHP files and
src/directory only - Excluded:
vendor/,node_modules/,tests/,assets/, minified files
Usage:
# Check code
composer run lint:php
# Auto-fix issues
composer run fix:php
# Check specific file
./vendor/bin/phpcs src/core/SparxstarGluonCore.phpCustomization:
To change text domain:
<property name="text_domain" type="array">
<element value="your-text-domain"/>
</property>To change prefix:
<property name="prefixes" type="array">
<element value="your_prefix"/>
</property>Purpose: Finds bugs and type errors without running code.
Configuration: phpstan.neon.dist
Key Settings:
- Level: 5 (moderate strictness)
- PHP Version: 8.2
- Scanned paths:
src/only - Baseline:
phpstan-baseline.neon(existing errors)
Usage:
# Run analysis
composer run analyze:php
# Generate new baseline (to accept current errors)
./vendor/bin/phpstan analyse --generate-baseline
# Check specific file
./vendor/bin/phpstan analyse src/core/SparxstarGluonCore.phpCustomization:
Increase strictness:
parameters:
level: 8 # Max levelAdd custom ignores:
ignoreErrors:
- '#Your custom error pattern#'Purpose: Automatically modernizes PHP code and applies best practices.
Configuration: rector.php
Key Settings:
- PHP version: 8.2
- Scanned:
src/only - Sets enabled: dead code removal, code quality, type declarations
Usage:
# Preview changes
composer run refactor:php
# Apply changes
composer run refactor:php:fix
# Process specific file
./vendor/bin/rector process src/core/SparxstarGluonCore.phpCustomization:
Skip specific rules:
->withSkip([
YourRuleClass::class,
])Add custom paths:
->withPaths([
__DIR__ . '/src',
__DIR__ . '/includes',
])Purpose: Unit testing framework for PHP.
Configuration: phpunit.xml.dist
Usage:
# Run all tests
composer run test:php
# Run specific test
./vendor/bin/phpunit tests/phpunit/ExampleTest.php
# With coverage (requires Xdebug)
./vendor/bin/phpunit --coverage-html coverage/Customization:
Add test suites:
<testsuite name="Integration Tests">
<directory>tests/integration</directory>
</testsuite>Purpose: Lints JavaScript code for errors and style issues.
Configuration: eslint.config.js
Key Settings:
- ECMAScript version: 2021 (ES12)
- Environment: Browser + Node
- Extends: @eslint/js recommended, Prettier
- Ignores: node_modules, vendor, assets, tests
Usage:
# Lint JS files
npm run lint:js
# Auto-fix
npx eslint src/js --fix
# Check specific file
npx eslint src/js/admin.jsCustomization:
Add custom rules:
rules: {
'no-console': 'warn',
'prefer-const': 'error',
}Add TypeScript support:
// Install: npm install --save-dev @typescript-eslint/parser @typescript-eslint/eslint-plugin
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],Purpose: JavaScript unit testing framework.
Configuration: jest.config.js
Usage:
# Run tests
npm test
# Watch mode
npm test -- --watch
# Coverage
npm test -- --coverage
# Specific file
npm test -- src/js/__tests__/example.test.jsCustomization:
Configure in jest.config.js:
module.exports = {
testEnvironment: 'jsdom', // For DOM testing
coverageThreshold: {
global: {
statements: 80,
branches: 80,
functions: 80,
lines: 80,
},
},
};Purpose: Lints CSS for errors and enforces style conventions.
Configuration: .stylelintrc.json
Key Settings:
- Extends: stylelint-config-standard
- Ignored:
.stylelintignore(vendor, node_modules, assets, minified files)
Usage:
# Lint CSS
npm run lint:css
# Auto-fix
npx stylelint "src/css/**/*.css" --fix
# Specific file
npx stylelint src/css/admin.cssCustomization:
Add rules in .stylelintrc.json:
{
"extends": "stylelint-config-standard",
"rules": {
"color-hex-length": "short",
"max-nesting-depth": 3
}
}Purpose: End-to-end browser testing.
Configuration: playwright.config.js
Key Settings:
- Test directory:
tests/e2e - Base URL: Environment variable or localhost:8080
- Browsers: Chromium, Firefox, WebKit
Usage:
# Run all tests
npm run test:e2e
# Specific browser
npx playwright test --project=chromium
# Headed mode (see browser)
npx playwright test --headed
# Debug
npx playwright test --debug
# Generate tests interactively
npx playwright codegen http://localhost:8080Customization:
export default defineConfig({
retries: 3, // Retry failed tests
workers: 4, // Parallel workers
timeout: 30000, // Test timeout
});Purpose: Headless Chrome automation (alternative to Playwright).
Usage:
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('http://localhost:8080');
// Your automation code
await browser.close();
})();Purpose: Minifies JavaScript files.
Configuration: scripts/build-js.js
Settings:
- Source:
src/js/**/*.js - Output:
assets/js/**/*.min.js - Source maps: Generated
- Compression: 2 passes, keeps console.error
Customization:
Edit scripts/build-js.js:
const result = await minify(code, {
compress: {
drop_console: true, // Remove all console
drop_debugger: true,
passes: 3,
},
mangle: {
toplevel: true,
},
});Purpose: Minifies CSS files.
Configuration: scripts/build-css.js
Settings:
- Source:
src/css/**/*.css - Output:
assets/css/**/*.min.css
Customization:
Edit scripts/build-css.js to add options:
const cmd = `npx cleancss -o "${destFile}" --compatibility ie9 --level 2 "${srcFile}"`;Purpose: Generates translation POT files.
Usage:
# Generate POT file
npm run makepot
# Or directly
wp i18n make-pot . languages/plugin-textdomain.pot --domain=plugin-textdomainPurpose: Runs scripts before Git commits.
Configuration: .husky/ directory
Setup:
npm run preparePurpose: Runs linters only on staged files.
Configuration: package.json
Settings:
- JS/TS files: ESLint + Prettier
- CSS files: Stylelint + Prettier
- PHP files: PHPCS + PHPStan
- JSON/MD/YML: Prettier
Customization:
Edit package.json:
"lint-staged": {
"*.{js,ts}": ["eslint --fix", "prettier --write"],
"*.php": ["phpcs", "phpstan analyse"],
}Located in .github/workflows/:
- ci.yml: Continuous integration (linting, testing, building)
- release.yml: Automated releases from tags
- security.yml: Security scanning
- accessibility.yml: Accessibility testing
- code-quality.yml: HTML/CSS/JS validation
Each workflow is documented in the file with comments.
Create .env file (based on example.env):
# WordPress Test Environment
WP_BASE_URL=http://localhost:8080
WP_ADMIN_USER=admin
WP_ADMIN_PASSWORD=password
# Testing
PLAYWRIGHT_HEADLESS=true# Reinstall dependencies
rm -rf node_modules vendor
composer install
npm installcomposer run analyze:php -- --generate-baselinenpx playwright install --with-deps- Run linters before committing: Use git hooks (automatically set up)
- Keep baselines minimal: Fix issues rather than ignoring them
- Update dependencies regularly: Check for security updates
- Write tests: Maintain high code coverage
- Document custom rules: Explain why rules are disabled