VOOZH about

URL: https://deepwiki.com/Automattic/BuddyPress-VIP-Go/6.3-code-quality-and-standards

⇱ Code Quality and Standards | Automattic/BuddyPress-VIP-Go | DeepWiki


Loading...
Menu

Code Quality and Standards

Purpose and Scope

This document details the code quality standards, linting tools, and enforcement mechanisms used in the BuddyPress VIP Go plugin. It covers the coding standards rulesets, configuration files, editor settings, and Composer scripts for running quality checks locally. For information about setting up the local development environment, see Local Development Setup. For details about the automated CI/CD pipeline that enforces these standards, see CI/CD Pipeline.


Coding Standards Overview

The plugin enforces multiple coding standards rulesets through PHP_CodeSniffer (PHPCS). These standards ensure code quality, security, and compatibility with WordPress VIP hosting infrastructure.

Standards Hierarchy


Sources: .phpcs.xml.dist1-39


PHPCS Configuration

The plugin's PHPCS configuration is defined in .phpcs.xml.dist at the repository root. This file configures all code style checks, exclusions, and scanning parameters.

Rulesets Applied

StandardPurposeConfiguration Line
WordPress-VIP-GoVIP-specific security and performance rules.phpcs.xml.dist5
WordPress-ExtraWordPress coding standards including WordPress-Core.phpcs.xml.dist9
WordPress-DocsInline documentation requirements (PHPDoc blocks).phpcs.xml.dist10
PHPCompatibilityWPPHP version compatibility validation.phpcs.xml.dist23

Sources: .phpcs.xml.dist5-24

Key Configuration Parameters

WordPress Version Compatibility


This setting configures PHPCS sniffs to ensure code is compatible with WordPress 6.6+. Sniffs will flag deprecated WordPress functions or APIs not available in this version.

Sources: .phpcs.xml.dist13

PHP Version Compatibility


The PHPCompatibilityWP standard checks that code is compatible with PHP 8.1 and above. The trailing dash means "8.1 and all later versions."

Sources: .phpcs.xml.dist24

Internationalization


All translatable strings must use the buddypress-vip-go text domain. PHPCS validates that __(), _e(), _n(), and other i18n functions use this domain.

Sources: .phpcs.xml.dist15-21

Scan Configuration

ParameterValuePurpose
arg value="sp"Show sniff codes and progressDisplays which sniff triggered each violation
arg name="colors"EnabledColor-coded output for terminal
arg name="basepath".Strip file paths to relative paths
arg name="parallel"8Use 8 parallel processes for faster scanning
arg name="extensions"phpOnly scan PHP files

Sources: .phpcs.xml.dist27-31

Exclusion Patterns

The following directories are excluded from code style checks:


  • node_modules/ - Third-party JavaScript dependencies
  • vendor/ - Third-party PHP dependencies installed via Composer
  • tests/ - Test files (may have intentional violations for testing purposes)

Sources: .phpcs.xml.dist36-38


EditorConfig Settings

The .editorconfig file enforces consistent formatting across different editors and IDEs. This configuration is based on WordPress Core's EditorConfig.

Code Quality Enforcement Flow


Sources: .editorconfig1-26 composer.json47-48 .github/workflows/cs-lint.yml79-97

Universal Settings

All files receive these settings:

SettingValuePurpose
charsetutf-8Consistent character encoding
end_of_linelfUnix-style line endings (except .txt files)
insert_final_newlinetrueEnsures file ends with newline
trim_trailing_whitespacetrueRemoves trailing spaces (except .md files)
indent_styletabUse tabs for indentation (WordPress standard)

Sources: .editorconfig10-15

File-Type Specific Overrides

YAML Files (.yml)

indent_style = space
indent_size = 2

YAML files use 2-space indentation instead of tabs to avoid parsing issues.

Sources: .editorconfig17-19

Markdown Files (.md)

trim_trailing_whitespace = false

Trailing whitespace is preserved in Markdown files as two trailing spaces create line breaks.

Sources: .editorconfig21-22

Text Files (.txt)

end_of_line = crlf

Text files use Windows-style line endings (CRLF) for maximum compatibility.

Sources: .editorconfig24-25


Running Code Quality Checks Locally

The plugin provides Composer scripts for running code quality checks during development. These scripts should be run before committing changes.

Available Composer Scripts


Sources: composer.json44-51

PHP Linting

Check for Parse Errors


Runs parallel-lint to check all PHP files for syntax errors. This is faster than PHPCS and catches basic parse errors.

Command: @php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git

Sources: composer.json50

Generate CI-Friendly Output


Same as composer lint but outputs results in checkstyle format for CI/CD integration.

Command: @php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git --checkstyle

Sources: composer.json51

Code Style Checks

Run PHPCS


Runs PHP_CodeSniffer against all PHP files using the standards defined in .phpcs.xml.dist. The -q flag suppresses progress output, showing only violations.

Command: @php ./vendor/bin/phpcs -q

Sources: composer.json47

Auto-Fix Code Style Issues


Runs PHP Code Beautifier and Fixer (PHPCBF) to automatically fix code style violations where possible. Not all violations can be auto-fixed; some require manual intervention.

Command: @php ./vendor/bin/phpcbf -q

Sources: composer.json48

Typical Development Workflow


Sources: composer.json44-67 .github/workflows/cs-lint.yml1-98


CI/CD Code Quality Enforcement

The cs-lint.yml workflow runs automatically on pull requests and pushes to develop and trunk branches. It enforces code quality across multiple PHP versions.

PHP Version Matrix

The workflow tests against three PHP versions:

PHP VersionPurposeFailure Behavior
8.2Current minimum supported versionBlocking (must pass)
latestCurrent stable PHP releaseBlocking (must pass)
8.5Upcoming PHP version (pre-release)Non-blocking (continue-on-error: true)

Sources: .github/workflows/cs-lint.yml39-44

CI Workflow Steps


Sources: .github/workflows/cs-lint.yml46-97

Validation Steps Detail

1. Setup PHP Environment


Installs the specified PHP version and the cs2pr tool (converts checkstyle XML to GitHub PR comments).

Sources: .github/workflows/cs-lint.yml47-52

2. Register Problem Matchers

Two problem matchers are registered to display violations inline in GitHub's file diff view:

These convert output from linting tools into GitHub annotations.

3. Validate Composer Configuration


Ensures composer.json and composer.lock (if present) are valid and properly formatted.

Sources: .github/workflows/cs-lint.yml71-72

4. Lint PHP Files


Runs parallel-lint to check for PHP syntax errors. Output is piped through cs2pr to display errors as PR annotations.

Sources: .github/workflows/cs-lint.yml80-81

5. Lint XML Configuration


Validates phpunit.xml.dist against PHPUnit's XML schema to catch configuration errors.

Sources: .github/workflows/cs-lint.yml85-89

6. Check Code Style


Runs PHPCS and generates both a full report and a checkstyle XML report. The continue-on-error: true ensures the workflow continues even if violations are found, allowing the next step to display them as PR comments via cs2pr.

Sources: .github/workflows/cs-lint.yml92-97


Code Style Violation Examples

Common Violations and Fixes

WordPress.Security.EscapeOutput

Violation:


Fix:


All output must be escaped using appropriate WordPress functions (esc_html(), esc_attr(), esc_url(), etc.).

WordPress.WP.I18n

Violation:


Fix:


All translatable strings must use the buddypress-vip-go text domain.

WordPress.NamingConventions.ValidVariableName

Violation:


Fix:


Variable names must use snake_case, not camelCase.

WordPress.Files.FileName

Violation:


Fix:


File names should use lowercase with hyphens, not camelCase.


Standards Enforcement Summary

CheckToolTriggerBlocking
PHP Syntaxparallel-lintCI on PR/pushYes
Code StylephpcsCI on PR/pushYes (PHP 8.2, latest)
No (PHP 8.5)
XML ValidationxmllintCI on PR/pushYes
Composer Schemacomposer validateCI on PR/pushYes
PHP CompatibilityPHPCompatibilityWP (via PHPCS)CI on PR/pushYes
WordPress CompatibilityWordPress-VIP-Go, WordPress-ExtraCI on PR/pushYes
DocumentationWordPress-DocsCI on PR/pushYes
Text DomainWordPress.WP.I18nCI on PR/pushYes

Sources: .phpcs.xml.dist1-39 .github/workflows/cs-lint.yml31-97 composer.json44-67

Refresh this wiki

On this page