Automated Linting
To ensure the highest code quality and adherence to WordPress standards, this project utilizes PHP CodeSniffer (PHPCS) for PHP and ESLint for JavaScript. These tools automatically identify syntax errors, formatting issues, and potential security vulnerabilities.
PHP Linting (PHPCS)
This project follows the official WordPress Coding Standards. All PHP code is checked for compatibility, security, and documentation standards.
Running the Linter
To scan your PHP files for issues, run the following command from the project root:
composer run lint:php
Automatic Fixing
For many formatting violations (such as indentation or spacing), you can use the PHP Code Beautifier and Fixer (PHPCBF) to resolve them automatically:
composer run fix:php
Configuration
The project uses a phpcs.xml.dist file to define rules. By default, it excludes third-party libraries (the vendor and node_modules directories) to focus solely on custom logic.
JavaScript Linting (ESLint)
JavaScript and React-based code (for Block Editor enhancements) are linted using the @wordpress/eslint-plugin package. This ensures your code aligns with modern WordPress development patterns.
Running the Linter
To analyze your scripts for errors or stylistic inconsistencies:
npm run lint:js
Automatic Fixing
To automatically fix common formatting issues in your JavaScript files:
npm run lint:js -- --fix
Pre-commit Integration
To prevent code that violates our standards from reaching the repository, we recommend running these checks locally before every commit.
If you are using Husky or a similar git-hook manager (if configured in this repository), these checks will run automatically during the git commit process. If the linter finds errors, the commit will be blocked until the issues are resolved.
Usage in CI/CD
Every Pull Request submitted to the repository triggers an automated workflow that runs both PHPCS and ESLint.
- Success: The build passes, and the PR is eligible for review.
- Failure: The build fails, and you must resolve the linting errors before the PR can be merged. You can view the specific line failures in the Actions tab of the GitHub repository.