Skip to main content

Overview

Visual Portfolio maintains high code quality standards using automated linting tools and coding standards. All code must pass quality checks before being merged into the main branch.

Automated Quality Checks

The project uses Husky and lint-staged to automatically run quality checks on staged files before commits and pushes:
  • Pre-commit: Lints staged files
  • Pre-push: Runs full test suite
These hooks are automatically installed when you run npm install.

PHP Code Quality

PHP CodeSniffer (PHPCS)

The plugin follows WordPress Coding Standards (WPCS) with additional custom rules.

Configuration

PHP coding standards are defined in phpcs.xml.dist:
  • Standards: WordPress-Core, WordPress-Docs, WordPress.WP.I18n
  • PHP Version: 7.2+ (with PHPCompatibilityWP)
  • WordPress Version: 6.2+ minimum
  • Text Domain: visual-portfolio
  • Namespace Prefixes: Visual_Portfolio_, vpf_

Running PHP Linting

PHP linting runs inside the wp-env Docker container to ensure consistency across different development environments.

Composer Scripts

You can also run PHP CodeSniffer directly with Composer:

PHP Standards Details

Included Rules

  • WordPress-Core: Core WordPress coding standards
  • WordPress-Docs: PHPDoc documentation standards
  • WordPress.WP.I18n: Internationalization standards
  • PHPCompatibilityWP: PHP version compatibility checks (7.2+)
  • VariableAnalysis: Variable usage analysis
  • Generic.CodeAnalysis.EmptyPHPStatement: Empty statement detection

Excluded Patterns

Custom Configuration

JavaScript Code Quality

ESLint

JavaScript code follows WordPress ESLint configuration with custom rules.

Configuration

ESLint settings are defined in .eslintrc.js:

Running JavaScript Linting

Linting Scope

  • assets/**/*.js
  • gutenberg/**/*.js

Custom ESLint Rules

Import Sorting

Imports are automatically sorted using eslint-plugin-simple-import-sort:
  1. Side effect imports
  2. Node.js builtins (prefixed with node:)
  3. External packages
  4. WordPress packages (@wordpress/*)
  5. Absolute imports
  6. Relative imports (starting with .)

CSS/SCSS Code Quality

Stylelint

SCSS code follows WordPress Stylelint configuration.

Configuration

Stylelint settings are defined in .stylelintrc.js:

Running CSS Linting

Linting Scope

  • assets/**/*.scss
  • gutenberg/**/*.scss
  • templates/**/*.scss
All SCSS files use the postcss-scss custom syntax.

Disabled Stylelint Rules

Several strict rules are disabled for flexibility:
  • at-rule-empty-line-before
  • comment-empty-line-before
  • font-weight-notation
  • no-descending-specificity
  • rule-empty-line-before
  • selector-class-pattern
  • selector-id-pattern
  • value-keyword-case
  • Various SCSS-specific rules

Running All Linters

To check all code types at once:

Code Formatting

Auto-fix formatting issues:

Editor Integration

VS Code

Recommended extensions:
  • PHP Sniffer: phpcs integration
  • ESLint: JavaScript linting
  • Stylelint: SCSS linting
Add to your .vscode/settings.json:

PhpStorm

  1. Go to Settings → PHP → Quality Tools → PHP_CodeSniffer
  2. Set configuration path to phpcs.xml.dist
  3. Enable PHP_CodeSniffer validation
  4. Enable ESLint in Languages & Frameworks → JavaScript → Code Quality Tools
  5. Enable Stylelint in Languages & Frameworks → Style Sheets → Stylelint

WordPress Security Standards

All code must follow WordPress security best practices:

Input Sanitization

Output Escaping

Nonce Verification

Capability Checks

Performance Optimization

PHP CodeSniffer Performance

PHPCS is configured for optimal performance:
  • Parallel processing: Up to 20 files simultaneously
  • Caching: Results cached for unchanged files
  • Memory limit: 256M for large codebases

Continuous Integration

All pull requests automatically run quality checks via GitHub Actions:
  1. PHP CodeSniffer (WPCS compliance)
  2. ESLint (JavaScript standards)
  3. Stylelint (SCSS standards)
  4. PHPUnit tests
  5. Playwright E2E tests
Pull requests cannot be merged until all checks pass.

Best Practices

General Guidelines

  • Run linters before committing code
  • Fix all linting errors and warnings
  • Use auto-fix commands when possible
  • Write code that follows WordPress standards
  • Document complex code with clear comments
  • Keep functions small and focused
  • Use meaningful variable and function names

PHP Best Practices

  • Prefix all global functions with vpf_
  • Use Visual_Portfolio_* for class names
  • Always use strict class file naming
  • Add PHPDoc blocks for all functions and classes
  • Use type hints when PHP 7.2+ allows
  • Follow WordPress database query best practices

JavaScript Best Practices

  • Use ES6+ features (const, let, arrow functions)
  • Import WordPress packages as externals
  • Sort imports according to the defined groups
  • Use JSDoc for function documentation
  • Follow React best practices for Gutenberg components

SCSS Best Practices

  • Use variables for colors and spacing
  • Follow BEM naming convention for classes
  • Keep selectors specific but not overly nested
  • Use mixins for repeated patterns
  • Ensure styles work in RTL languages

Troubleshooting

Common Issues

PHPCS not found:
ESLint errors with @wordpress imports: These are expected as WordPress packages are external dependencies. Stylelint parsing errors: Ensure you’re using the postcss-scss syntax for SCSS files. Pre-commit hooks not running:

Additional Resources