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
This commit is contained in:
@@ -51,6 +51,7 @@ This project follows the [WordPress Coding Standards](https://developer.wordpres
|
|||||||
* Validate and sanitize all inputs
|
* Validate and sanitize all inputs
|
||||||
* Escape all outputs
|
* Escape all outputs
|
||||||
* Use asterisks (*) for bullet points in all Markdown files, not hyphens (-)
|
* Use asterisks (*) for bullet points in all Markdown files, not hyphens (-)
|
||||||
|
* Add periods to the end of all inline comments
|
||||||
|
|
||||||
### Code Quality Tools
|
### Code Quality Tools
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
# Code Quality Checks Workflow
|
# 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
|
## Pre-Push Checklist
|
||||||
|
|
||||||
@@ -12,7 +14,7 @@ Before pushing your changes to the repository, run through the following checks:
|
|||||||
composer test
|
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**
|
2. **Run PHP CodeSniffer**
|
||||||
|
|
||||||
@@ -73,7 +75,7 @@ $page = filter_input(INPUT_GET, 'page', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
|
|||||||
|
|
||||||
// For testing environments
|
// For testing environments
|
||||||
if (defined('PHPUNIT_RUNNING') && PHPUNIT_RUNNING) {
|
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']) : '';
|
$page = isset($_GET['page']) ? wp_unslash($_GET['page']) : '';
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -113,9 +115,9 @@ function_name( $param1, $param2 );
|
|||||||
|
|
||||||
Follow WordPress naming conventions:
|
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
|
* Classes: CamelCase
|
||||||
* Constants: UPPERCASE_WITH_UNDERSCORES
|
* Constants: UPPERCASE_WITH_UNDERSCORES with plugin-specific prefix (e.g., `MYPLUGIN_CONSTANT_NAME`)
|
||||||
|
|
||||||
## Automated Checks in CI/CD
|
## 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
|
3. **SonarCloud**: Checks for code smells, bugs, and security vulnerabilities
|
||||||
4. **CodeRabbit**: Provides AI-powered code review
|
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
|
## 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]
|
[Paste error output here]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
For more AI assistance guidelines, see the [AI Assistant Guide](./../.ai-assistant.md).
|
||||||
|
|
||||||
## Conclusion
|
## 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.
|
||||||
|
|||||||
13
phpcs.xml
13
phpcs.xml
@@ -32,12 +32,13 @@
|
|||||||
<exclude name="WordPress.Files.FileName.InvalidClassFileName" />
|
<exclude name="WordPress.Files.FileName.InvalidClassFileName" />
|
||||||
<exclude name="WordPress.DB.DirectDatabaseQuery.NoCaching" />
|
<exclude name="WordPress.DB.DirectDatabaseQuery.NoCaching" />
|
||||||
|
|
||||||
<exclude name="Universal.ControlStructures.DisallowAlternativeSyntax.FoundIfWithInlineHTML" />
|
<!-- Universal sniffs are commented out until the dependencies are properly installed -->
|
||||||
<exclude name="Universal.ControlStructures.DisallowAlternativeSyntax.FoundForeachWithInlineHTML" />
|
<!-- <exclude name="Universal.ControlStructures.DisallowAlternativeSyntax.FoundIfWithInlineHTML" /> -->
|
||||||
<exclude name="Universal.ControlStructures.DisallowAlternativeSyntax.FoundIf" />
|
<!-- <exclude name="Universal.ControlStructures.DisallowAlternativeSyntax.FoundForeachWithInlineHTML" /> -->
|
||||||
<exclude name="Universal.ControlStructures.IfElseDeclaration.NoNewLine" />
|
<!-- <exclude name="Universal.ControlStructures.DisallowAlternativeSyntax.FoundIf" /> -->
|
||||||
<exclude name="Universal.Classes.RequireFinalClass.NonFinalClassFound" />
|
<!-- <exclude name="Universal.ControlStructures.IfElseDeclaration.NoNewLine" /> -->
|
||||||
<exclude name="Universal.Namespaces.EnforceCurlyBraceSyntax.Forbidden" />
|
<!-- <exclude name="Universal.Classes.RequireFinalClass.NonFinalClassFound" /> -->
|
||||||
|
<!-- <exclude name="Universal.Namespaces.EnforceCurlyBraceSyntax.Forbidden" /> -->
|
||||||
|
|
||||||
<exclude name="Generic.Commenting.Todo" />
|
<exclude name="Generic.Commenting.Todo" />
|
||||||
<exclude name="Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition" />
|
<exclude name="Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition" />
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ parameters:
|
|||||||
ignoreErrors:
|
ignoreErrors:
|
||||||
- '#Function apply_filters invoked with [0-9]+ parameters, 2 required.#'
|
- '#Function apply_filters invoked with [0-9]+ parameters, 2 required.#'
|
||||||
- '#Function [a-zA-Z0-9_]+ not found.#'
|
- '#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 do_action invoked with [0-9]+ parameters, 1 required.#'
|
||||||
- '#Function add_action invoked with [0-9]+ parameters, 2 required.#'
|
- '#Function add_action invoked with [0-9]+ parameters, 2 required.#'
|
||||||
- '#Function add_filter invoked with [0-9]+ parameters, 2 required.#'
|
- '#Function add_filter invoked with [0-9]+ parameters, 2 required.#'
|
||||||
|
|||||||
@@ -25,3 +25,6 @@ sonar.php.tests.reportPath=test-report.xml
|
|||||||
|
|
||||||
# Additional parameters
|
# Additional parameters
|
||||||
sonar.verbose=true
|
sonar.verbose=true
|
||||||
|
|
||||||
|
# Disable automatic analysis
|
||||||
|
sonar.projectKey.analysis.mode=manual
|
||||||
|
|||||||
Reference in New Issue
Block a user