Skip to content

Commit 599e7ad

Browse files
Merge pull request #4365 from woocommerce/dev/PCP-6288-cc-code-review-skill
CC Integration: New skill for code reviews
2 parents 26b1650 + e081de4 commit 599e7ad

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
name: code-review
3+
description: Reviews code changes for quality, security, and adherence to project standards. Use when reviewing PRs, commits, or staged changes.
4+
---
5+
6+
# Code Review
7+
8+
## Instructions
9+
10+
When invoked, perform a thorough code review following these steps:
11+
12+
### 1. Identify Changes to Review
13+
14+
- If a PR number is provided as argument (e.g., `/code-review 123`), fetch the PR diff using `gh pr diff <number>`
15+
- If no argument provided, review staged changes with `git diff --cached`, or if nothing staged, review uncommitted changes with `git diff`
16+
- If a branch name is provided, compare against the main branch with `git diff develop...<branch>`
17+
18+
### 2. Analyze PR
19+
20+
- Read the PR description and comments for context
21+
- For each file with changes, evaluate:
22+
- Code Quality: see [code-quality.md](code-quality.md)
23+
- Check if there is any bug in the changes of the PR
24+
- Testing Considerations
25+
26+
### 3. Output Format
27+
28+
Create a Markdown file report with the results and add it to ./temp/code-reviews including the PR id and title in the file name
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Code Quality
2+
3+
## Table of Contents
4+
5+
- [Design Principles](#design-principles)
6+
- [Code Smells](#code-smells)
7+
- [Best Practices](#best-practices)
8+
9+
## Design Principles
10+
11+
### Single Responsible Principle
12+
13+
Classes and methods should handle one single concept or responsibility.
14+
15+
### Open Close Principle
16+
17+
The Software should be open to extension and closed to modification.
18+
19+
### Command Query Separation principle
20+
21+
A method should either return a value or perform a task but not both.
22+
23+
## Code Smells
24+
25+
### Long classes and methods
26+
27+
Long classes and methods that handles multiple concepts and responsibilities.
28+
29+
### Primitive Obsession
30+
31+
Instead of relying on primitive types (strings, arrays…) use dedicated objects that encapsulates the
32+
primitives and allows adding validation like Value Objects which allows:
33+
34+
- Object integrity restrictions and validations that are not spread across the code base but in the
35+
object itself.
36+
- Attracts related logic to the object
37+
- Adds semantics
38+
39+
## Best Practices
40+
41+
### Modularity
42+
43+
Code inside `ExecutableModule::run` method should be added into WordPress hooks callbacks:
44+
45+
Good:
46+
47+
```php
48+
public function run( ContainerInterface $container ): bool {
49+
add_action( 'admin_init', function () {
50+
wp_enqueue_script( 'wc-store-ai' );
51+
```
52+
53+
Bad:
54+
55+
```php
56+
public function run( ContainerInterface $container ): bool {
57+
wp_enqueue_script( 'wc-store-ai' );
58+
```

0 commit comments

Comments
 (0)