From baa2a050d32669991f0854855e1ecca1cd5c00bd Mon Sep 17 00:00:00 2001 From: marcusquinn <6428977+marcusquinn@users.noreply.github.com> Date: Mon, 21 Apr 2025 16:35:50 +0100 Subject: [PATCH] Fix code quality tool configurations and improve documentation - Fixed phpstan.neon regex pattern for ignoring errors - Commented out missing Universal sniffs in phpcs.xml - Updated SonarCloud configuration to disable automatic analysis - Improved code-quality-checks.md documentation based on feedback - Added reminder about inline comment periods to .ai-assistant.md --- .ai-assistant.md | 1 + .ai-workflows/code-quality-checks.md | 18 +++++++++++------- phpcs.xml | 13 +++++++------ phpstan.neon | 2 +- sonar-project.properties | 3 +++ 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/.ai-assistant.md b/.ai-assistant.md index 4121396..3e3ed1a 100644 --- a/.ai-assistant.md +++ b/.ai-assistant.md @@ -51,6 +51,7 @@ This project follows the [WordPress Coding Standards](https://developer.wordpres * Validate and sanitize all inputs * Escape all outputs * Use asterisks (*) for bullet points in all Markdown files, not hyphens (-) +* Add periods to the end of all inline comments ### Code Quality Tools diff --git a/.ai-workflows/code-quality-checks.md b/.ai-workflows/code-quality-checks.md index f8cb8d3..e00a45f 100644 --- a/.ai-workflows/code-quality-checks.md +++ b/.ai-workflows/code-quality-checks.md @@ -1,6 +1,8 @@ # Code Quality Checks Workflow -This document outlines the process for ensuring code quality before pushing changes to the repository. Following these steps will help catch issues early and save time in the review process. +## Scope + +This document is intended for plugin developers and code reviewers working on this repository. It outlines the process for ensuring code quality before pushing changes to the repository. Following these steps will help catch issues early and save time in the review process. ## Pre-Push Checklist @@ -12,7 +14,7 @@ Before pushing your changes to the repository, run through the following checks: composer test ``` - Ensure all tests pass. If any tests fail, fix the issues before proceeding. + Ensure all tests pass. If any tests fail, resolve the issues before proceeding. 2. **Run PHP CodeSniffer** @@ -73,7 +75,7 @@ $page = filter_input(INPUT_GET, 'page', FILTER_SANITIZE_FULL_SPECIAL_CHARS); // For testing environments if (defined('PHPUNIT_RUNNING') && PHPUNIT_RUNNING) { - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized + // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- This rule is ignored in tests to allow direct access for testing purposes $page = isset($_GET['page']) ? wp_unslash($_GET['page']) : ''; } ``` @@ -113,9 +115,9 @@ function_name( $param1, $param2 ); Follow WordPress naming conventions: -* Functions and variables: snake_case +* Functions and variables: snake_case with plugin-specific prefix (e.g., `myplugin_function_name`) * Classes: CamelCase -* Constants: UPPERCASE_WITH_UNDERSCORES +* Constants: UPPERCASE_WITH_UNDERSCORES with plugin-specific prefix (e.g., `MYPLUGIN_CONSTANT_NAME`) ## Automated Checks in CI/CD @@ -126,7 +128,7 @@ Our CI/CD pipeline includes the following automated checks: 3. **SonarCloud**: Checks for code smells, bugs, and security vulnerabilities 4. **CodeRabbit**: Provides AI-powered code review -Even though these checks run automatically, it's best to catch issues locally before pushing to save time and reduce the number of commits needed to fix issues. +Although CI runs these checks, catching issues locally helps save time and minimize follow-up commits. ## Using AI to Help with Code Quality @@ -145,6 +147,8 @@ I ran PHPCS and got the following errors. Can you help me fix them? [Paste error output here] ``` +For more AI assistance guidelines, see the [AI Assistant Guide](./../.ai-assistant.md). + ## Conclusion -Following this workflow will help maintain high code quality and reduce the time spent on code reviews and fixing issues after pushing. Remember, it's always faster to fix issues locally than to go through multiple rounds of CI/CD and code review. +This workflow helps maintain high code quality and speeds up the review process. Remember, it's always more efficient to resolve issues locally than to go through multiple rounds of CI/CD and code review. diff --git a/phpcs.xml b/phpcs.xml index f04ad33..0c15529 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -32,12 +32,13 @@ - - - - - - + + + + + + + diff --git a/phpstan.neon b/phpstan.neon index 07a5cbe..6159714 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -15,7 +15,7 @@ parameters: ignoreErrors: - '#Function apply_filters invoked with [0-9]+ parameters, 2 required.#' - '#Function [a-zA-Z0-9_]+ not found.#' - - '#Call to static method [a-zA-Z0-9_:()]+ on an unknown class [a-zA-Z0-9_]+.#' + - '#Call to static method [a-zA-Z0-9_:\\(\\)]+ on an unknown class [a-zA-Z0-9_]+.#' - '#Function do_action invoked with [0-9]+ parameters, 1 required.#' - '#Function add_action invoked with [0-9]+ parameters, 2 required.#' - '#Function add_filter invoked with [0-9]+ parameters, 2 required.#' diff --git a/sonar-project.properties b/sonar-project.properties index 83d64f8..b721ba7 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -25,3 +25,6 @@ sonar.php.tests.reportPath=test-report.xml # Additional parameters sonar.verbose=true + +# Disable automatic analysis +sonar.projectKey.analysis.mode=manual