Coding Standards
Overview
To ensure consistency, security, and maintainability, this project strictly adheres to the WordPress Coding Standards. All contributions must pass linting checks for PHP, JavaScript, and CSS before being merged.
PHP Coding Standards
We use PHP_CodeSniffer (PHPCS) with the WordPress Coding Standards (WPCS) ruleset. This ensures that your PHP code follows the same formatting and best practices as WordPress Core.
Installation
Ensure you have Composer installed, then install the development dependencies:
composer install
Running Checks
To scan your code for errors and warnings, run the following command from the root directory:
composer run lint:php
Automatic Fixing
Many formatting issues (such as indentation, spacing, and brace placement) can be fixed automatically using PHPCBF:
composer run format:php
JavaScript and CSS Standards
For JavaScript and CSS, we follow the WordPress official standards managed via ESLint and Stylelint. We utilize the @wordpress/scripts package to manage these configurations.
Installation
Ensure you have Node.js and npm installed, then install the packages:
npm install
Running Checks
To lint your JavaScript and CSS files, use the following commands:
# Lint JavaScript
npm run lint:js
# Lint CSS/SCSS
npm run lint:css
Automatic Fixing
To automatically resolve fixable linting issues in your scripts and styles:
# Fix JavaScript
npm run format:js
# Fix CSS/SCSS
npm run format:css
Editor Integration (VS Code)
To streamline your workflow, we recommend installing the following extensions for Visual Studio Code. These will highlight errors in real-time as you type.
- phpcs: Set the executable path to
./vendor/bin/phpcs. - ESLint: Automatically detects the project's
.eslintrcfile. - Prettier - Code Formatter: For general formatting.
Workspace Settings
A .vscode/settings.json file is included in the repository to automatically configure these tools for the project environment. Ensure you allow the workspace to apply these settings when prompted.
Pre-commit Hooks
To prevent non-compliant code from being committed, we recommend using a Git pre-commit hook. If you have installed the project dependencies, you can trigger the linting suite manually before every commit:
# Run all linters
composer run lint:php && npm run lint:js && npm run lint:css
Failure to pass these checks will result in a failed Build/CI pipeline.