Skip to content

Commit 5d84252

Browse files
committed
second pass of claude doing self-review
1 parent 805d295 commit 5d84252

File tree

1 file changed

+217
-12
lines changed

1 file changed

+217
-12
lines changed

RULES.md

Lines changed: 217 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,42 @@ __( 'Some text' );
333333

334334
## Comment & Documentation Rules
335335

336-
### @since Tag
336+
### PHPDoc Descriptions
337337

338-
**Rule 1:** All functions, classes, interfaces, traits, and constants **must** have `@since` tag.
338+
**Rule 1:** PHPDoc descriptions must end with punctuation (`.`, `!`, `?`).
339+
340+
```php
341+
// ✅ CORRECT
342+
/**
343+
* Process user data.
344+
*
345+
* @since 1.5.0
346+
*/
347+
348+
// ❌ WRONG - Missing punctuation
349+
/**
350+
* Process user data
351+
*
352+
* @since 1.5.0
353+
*/
354+
```
355+
356+
**Rule 2:** PHPDoc description must start on the line after `/**`, not on the same line.
357+
358+
```php
359+
// ✅ CORRECT
360+
/**
361+
* Process user data.
362+
*/
363+
364+
// ❌ WRONG - Description on same line as opening
365+
/** Process user data.
366+
*/
367+
```
368+
369+
### `@since` Tag
370+
371+
**Rule 1:** All functions, classes, interfaces, traits, constants, **class properties**, and `define()` calls **must** have `@since` tag.
339372

340373
```php
341374
// ✅ CORRECT
@@ -405,16 +438,18 @@ public function process( $data ) { }
405438

406439
**Rule 2:** Add empty line after `@deprecated` tag (unless it's the last tag).
407440

408-
### @param Tag Spacing
441+
### @param and @return Tag Spacing
409442

410-
**Rule:** Only one space after `@param` tag.
443+
**Rule:** Only one space after `@param` and `@return` tags.
411444

412445
```php
413446
// ✅ CORRECT
414447
@param string $name The name.
448+
@return bool Success status.
415449

416450
// ❌ WRONG - Multiple spaces
417451
@param string $name The name.
452+
@return bool Success status.
418453
```
419454

420455
### Translator Comments
@@ -450,7 +485,7 @@ printf( __( 'Hello, %s!', 'wpforms' ), $name );
450485

451486
### Hook Documentation
452487

453-
**Rule:** All `do_action()` and `apply_filters()` calls **must** have PHPDoc comment directly above them.
488+
**Rule 1:** All `do_action()` and `apply_filters()` calls **must** have PHPDoc comment directly above them (on the line immediately before).
454489

455490
```php
456491
// ✅ CORRECT
@@ -474,6 +509,147 @@ do_action( 'wpforms_settings_saved', $settings );
474509
do_action( 'wpforms_settings_saved', $settings );
475510
```
476511

512+
**Rule 2:** Hook PHPDoc **must** have a short description ending with punctuation.
513+
514+
```php
515+
// ✅ CORRECT
516+
/**
517+
* Fires after settings are saved.
518+
*
519+
* @since 1.5.0
520+
*/
521+
do_action( 'wpforms_settings_saved' );
522+
523+
// ❌ WRONG - Missing description
524+
/**
525+
* @since 1.5.0
526+
*/
527+
do_action( 'wpforms_settings_saved' );
528+
529+
// ❌ WRONG - Missing punctuation
530+
/**
531+
* Fires after settings are saved
532+
*
533+
* @since 1.5.0
534+
*/
535+
do_action( 'wpforms_settings_saved' );
536+
```
537+
538+
**Rule 3:** Hook PHPDoc **must** have `@since` tag with valid version.
539+
540+
**Rule 4:** Hook PHPDoc **must** have `@param` tags matching the number of arguments passed to the hook (excluding the hook name itself).
541+
542+
```php
543+
// ✅ CORRECT - 2 arguments, 2 @param tags
544+
/**
545+
* Filters the settings data.
546+
*
547+
* @since 1.5.0
548+
*
549+
* @param array $settings The settings data.
550+
* @param int $user_id The user ID.
551+
*/
552+
apply_filters( 'wpforms_settings', $settings, $user_id );
553+
554+
// ❌ WRONG - 2 arguments but only 1 @param tag
555+
/**
556+
* Filters the settings data.
557+
*
558+
* @since 1.5.0
559+
*
560+
* @param array $settings The settings data.
561+
*/
562+
apply_filters( 'wpforms_settings', $settings, $user_id );
563+
```
564+
565+
**Rule 5:** Hook `@param` tags must be aligned (types, variable names, and descriptions should line up).
566+
567+
```php
568+
// ✅ CORRECT - Properly aligned
569+
/**
570+
* @param array $settings The settings data.
571+
* @param int $user_id The user ID.
572+
* @param string $context The context string.
573+
*/
574+
575+
// ❌ WRONG - Not aligned
576+
/**
577+
* @param array $settings The settings data.
578+
* @param int $user_id The user ID.
579+
* @param string $context The context string.
580+
*/
581+
```
582+
583+
**Rule 6:** Hook `@param` descriptions must end with punctuation.
584+
585+
**Rule 7:** For deprecated hooks, use `do_action_deprecated()` or `apply_filters_deprecated()` and include `@deprecated` tag.
586+
587+
```php
588+
// ✅ CORRECT
589+
/**
590+
* Fires when user is processed.
591+
*
592+
* @since 1.0.0
593+
* @deprecated 2.0.0 Use wpforms_user_process_v2 instead.
594+
*
595+
* @param int $user_id User ID.
596+
*/
597+
do_action_deprecated( 'wpforms_user_process', [ $user_id ], '2.0.0', 'wpforms_user_process_v2' );
598+
599+
// ❌ WRONG - Using regular do_action for deprecated hook
600+
/**
601+
* @since 1.0.0
602+
* @deprecated 2.0.0
603+
*/
604+
do_action( 'wpforms_user_process', $user_id );
605+
606+
// ❌ WRONG - Using do_action_deprecated without @deprecated tag
607+
/**
608+
* @since 1.0.0
609+
*/
610+
do_action_deprecated( 'wpforms_user_process', [ $user_id ], '2.0.0' );
611+
```
612+
613+
### Define Constants Documentation
614+
615+
**Rule 1:** All `define()` calls **must** have PHPDoc comment directly above them.
616+
617+
**Rule 2:** `define()` PHPDoc must have a short description ending with punctuation.
618+
619+
**Rule 3:** `define()` PHPDoc must have `@since` tag with valid version.
620+
621+
**Rule 4:** No empty line should appear after `@since` tag in `define()` PHPDoc (different from functions/classes).
622+
623+
```php
624+
// ✅ CORRECT
625+
/**
626+
* The plugin version number.
627+
*
628+
* @since 1.0.0
629+
*/
630+
define( 'WPFORMS_VERSION', '1.8.0' );
631+
632+
// ❌ WRONG - Missing PHPDoc
633+
define( 'WPFORMS_VERSION', '1.8.0' );
634+
635+
// ❌ WRONG - Missing punctuation
636+
/**
637+
* The plugin version number
638+
*
639+
* @since 1.0.0
640+
*/
641+
define( 'WPFORMS_VERSION', '1.8.0' );
642+
643+
// ❌ WRONG - Empty line after @since
644+
/**
645+
* The plugin version number.
646+
*
647+
* @since 1.0.0
648+
*
649+
*/
650+
define( 'WPFORMS_VERSION', '1.8.0' );
651+
```
652+
477653
### Language Injection Comments
478654

479655
**Special comments allowed (won't trigger PHPCS errors):**
@@ -496,27 +672,56 @@ $sql = "SELECT * FROM users";
496672

497673
### Most Important Rules for Daily Coding
498674

675+
#### Formatting
499676
1. **Empty lines:**
500677
- After function opening brace
501678
- Before return statement (unless it's the only statement)
502679
- After assignments (with exceptions)
503680
- Before/after switch statements
504681
- Before case statements after break
682+
- No empty line before break in switch
505683

506684
2. **No Yoda conditions** - Write naturally: `$var === 'value'`
507685

508686
3. **Short array syntax** - Use `[]` not `array()`
509687

510-
4. **@since tag required** on all functions/classes with valid version
688+
#### Documentation
689+
4. **@since tag required** on:
690+
- All functions, classes, interfaces, traits
691+
- Class properties
692+
- Constants and `define()` calls
693+
- All hooks (do_action/apply_filters)
694+
695+
5. **PHPDoc descriptions must:**
696+
- End with punctuation (`.`, `!`, `?`)
697+
- Start on line after `/**` opening
698+
- Not be on same line as `/**`
699+
700+
6. **Hook documentation:**
701+
- PHPDoc required directly above all hooks
702+
- Must have description with punctuation
703+
- Must have `@since` tag
704+
- Must have `@param` tags matching argument count
705+
- `@param` tags must be aligned
706+
- Use `*_deprecated()` functions with `@deprecated` tag for old hooks
707+
708+
7. **Define constants:**
709+
- Must have PHPDoc with description
710+
- Must have `@since` tag
711+
- No empty line after `@since`
712+
713+
#### Code Organization
714+
8. **Hooks in hooks() method** - All `add_action()`/`add_filter()` calls must be inside `hooks()` method in classes
511715

512-
5. **Hooks in hooks() method** - Don't add hooks elsewhere in classes
716+
9. **Text domain required** - Always specify domain in i18n functions
513717

514-
6. **Text domain required** - Always specify domain in i18n functions
718+
10. **Use statements over fully qualified names** - Import classes at top
515719

516-
7. **Use statements over fully qualified names**
720+
11. **Hook names** - Should start with class name in snake_case
517721

518-
8. **Hook documentation required** - PHPDoc directly above all `do_action()`/`apply_filters()`
722+
#### Quality
723+
12. **Translator comments** - Must have colon, description, and punctuation
519724

520-
9. **Translator comments** - Must have colon, description, and punctuation
725+
13. **Complexity limits** - Keep functions under 6 complexity, 3 nesting levels
521726

522-
10. **Complexity limits** - Keep functions under 6 complexity, 3 nesting levels
727+
14. **Tag spacing** - Only one space after `@param` and `@return`

0 commit comments

Comments
 (0)