Skip to content

Commit 12ac0f7

Browse files
ashleyshawclaude
andcommitted
fix(phase6): Resolve critical instruction contradictions and add validation
## Critical Issues Fixed ### Issue #1: Indentation Contradictions (CRITICAL) - **wpcs-php.instructions.md**: Fixed line 379 contradiction - Changed from "Use 4 spaces for indentation, no tabs" - To: "Use tabs for indentation (WordPress PHP standard)" - Now consistent with line 24 which correctly states "tabs" - **wpcs-javascript.instructions.md**: Clarified JS indentation rules - Line 131: Added context "tabs for vanilla JavaScript (WordPress core standard)" - Line 132: Added "For React/JSX files, use 2 spaces to align with @wordpress/scripts" - Line 562: Clarified "2 spaces for React/JSX files (Gutenberg standard), tabs for vanilla JS" - Resolves contradiction between tabs (line 131) and 2 spaces (line 561) ### Issue #3: Placeholder Preservation Checklist (CRITICAL) - **scaffold-extensions.instructions.md**: Added comprehensive validation section - New "Mustache Placeholder Preservation Checklist" with 6 subsections - Core Placeholders checklist (namespace, slug, textdomain, name, etc.) - Template Files checklist (patterns, templates, blocks) - Common Hard-coding Mistakes with BAD vs GOOD examples - 5-step Validation procedure including mustache scanning - Documentation requirements for new placeholders - Risk prevention identifying high-risk files ## Impact ### Before: - AI agents received contradictory guidance on indentation - No explicit validation checklist for mustache placeholder preservation - Risk of hard-coded values breaking scaffold generation ### After: - Clear, consistent indentation standards (PHP: tabs, React: 2 spaces, vanilla JS: tabs) - Comprehensive checklist prevents mustache placeholder violations - Explicit validation steps ensure scaffold integrity ## Validation ✅ Instructions now consistent across all WPCS files ✅ Placeholder preservation explicitly documented with examples ✅ High-risk files identified for extra caution ✅ 5-step validation procedure added ## Files Modified - .github/instructions/wpcs-php.instructions.md (1 line corrected) - .github/instructions/wpcs-javascript.instructions.md (3 sections clarified) - .github/instructions/scaffold-extensions.instructions.md (106 lines added) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 9e632e0 commit 12ac0f7

File tree

6 files changed

+197
-13
lines changed

6 files changed

+197
-13
lines changed

.github/instructions/scaffold-extensions.instructions.md

Lines changed: 104 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,108 @@ Do not include any production opinions; keep everything clearly marked as exampl
374374
- Add new binding placeholder: `{{binding_example}}` documented in `scripts/mustache-variables-registry.json`.
375375
- New template part placeholder: `templates/parts/{{slug}}-cta.php` with namespaced CSS class `{{namespace}}-cta`.
376376

377-
## Validation
377+
## Mustache Placeholder Preservation Checklist
378378

379-
- Run `node scripts/scan-mustache-variables.js` after adding placeholders.
380-
- Run `npm run lint` and `composer lint` to ensure scaffolding code remains valid.
381-
- Generate a sample plugin to confirm no raw placeholders or missing files remain.
379+
Before committing any changes to scaffold files, ensure:
380+
381+
### ✅ Core Placeholders Never Hard-coded
382+
383+
- [ ] `{{namespace}}` - Used for PHP namespaces, block registration, CSS classes
384+
- [ ] `{{slug}}` - Used for post types, taxonomies, file/folder names, URLs
385+
- [ ] `{{textdomain}}` - Used for all `__()`, `_e()`, `esc_html__()` translation functions
386+
- [ ] `{{name}}` - Used for user-facing display names
387+
- [ ] `{{name_plural}}`, `{{name_singular}}` - Used for CPT labels
388+
- [ ] `{{author}}`, `{{author_uri}}`, `{{version}}`, `{{license}}` - Used in plugin headers
389+
390+
### ✅ Template Files Preserve Placeholders
391+
392+
- [ ] **Patterns** (`patterns/*.php`): All CSS classes use `{{namespace}}` and `{{slug}}`
393+
- [ ] **Templates** (`templates/*.html`): Block references use `{{namespace}}/{{slug}}-*`
394+
- [ ] **Template Parts** (`template-parts/*.html`): Taxonomy references use `{{slug}}_category`
395+
- [ ] **Block render.php**: ACF field names use `{{namespace}}_field_name` format
396+
- [ ] **Block edit.js**: CSS classes follow `wp-block-{{namespace}}-{{slug}}-*` pattern
397+
- [ ] **Block view.js**: Selectors dynamically construct class names from block attributes
398+
399+
### ✅ Common Hard-coding Mistakes to Avoid
400+
401+
**DON'T DO THIS:**
402+
```php
403+
// BAD: Hard-coded namespace
404+
namespace example_plugin\classes;
405+
$field = get_field( 'example_plugin_subtitle' );
406+
407+
// BAD: Hard-coded CSS class
408+
<div className="wp-block-example_plugin-example_plugin-card">
409+
410+
// BAD: Hard-coded text domain
411+
__( 'View All Tours', 'example-plugin' )
412+
```
413+
414+
**DO THIS:**
415+
```php
416+
// GOOD: Mustache placeholders
417+
namespace {{namespace|lowerCase}}\classes;
418+
$field = get_field( '{{namespace}}_subtitle' );
419+
420+
// GOOD: Dynamic placeholders
421+
<div className="wp-block-{{namespace}}-{{slug}}-card">
422+
423+
// GOOD: Template placeholder
424+
__( 'View All {{name_plural}}', '{{textdomain}}' )
425+
```
426+
427+
### ✅ Validation Steps
428+
429+
After making changes to scaffold templates:
430+
431+
1. **Scan for new variables:**
432+
```bash
433+
node scripts/scan-mustache-variables.js
434+
```
435+
436+
2. **Validate registry integrity:**
437+
```bash
438+
node scripts/validate-mustache-registry.js
439+
```
440+
441+
3. **Run all linting:**
442+
```bash
443+
npm run lint
444+
composer lint
445+
```
446+
447+
4. **Generate test plugin:**
448+
```bash
449+
node scripts/generate-plugin.js --config tests/fixtures/plugin-config.test.json
450+
```
451+
452+
5. **Check generated output has NO unreplaced mustache variables:**
453+
```bash
454+
grep -r "{{" generated-plugins/test-plugin/ | grep -v node_modules | grep -v build
455+
```
456+
Should return no results (except in comments explaining the system).
457+
458+
### ✅ Documentation Requirements
459+
460+
When adding new placeholders:
461+
462+
- [ ] Add to `scripts/mustache-variables-registry.json` with:
463+
- Variable name
464+
- Description
465+
- Category (namespace, text, meta)
466+
- Example value
467+
- All files where it's used
468+
- [ ] Update `docs/GENERATE-PLUGIN.md` if it's user-facing
469+
- [ ] Add example to this instruction file showing correct usage
470+
- [ ] Update `.github/agents/generate-plugin.agent.md` if it affects the generator interface
471+
472+
### ✅ Risk Prevention
473+
474+
**HIGH RISK:** These files are most likely to accidentally introduce hard-coded values:
475+
476+
- `src/blocks/*/edit.js` - Block editor components with CSS class strings
477+
- `src/blocks/*/render.php` - Dynamic block rendering with ACF fields
478+
- `patterns/*.php` - Block patterns with inline styles and classes
479+
- `inc/class-*.php` - PHP classes with namespaces and text domains
480+
481+
Always verify these files after editing.

.github/instructions/wpcs-javascript.instructions.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ Use spaces liberally throughout your code. "When in doubt, space it out."
128128

129129
These rules encourage liberal spacing for improved developer readability. The minification process creates a file that is optimized for browsers to read and process.
130130

131-
- Indentation with tabs.
131+
- Indentation with tabs for vanilla JavaScript (WordPress core standard).
132+
- For React/JSX files, use 2 spaces to align with @wordpress/scripts and modern tooling.
132133
- No whitespace at the end of line or on blank lines.
133134
- Lines should usually be no longer than 80 characters, and should not exceed 100 (counting tabs as 4 spaces). _This is a "soft" rule, but long lines generally indicate unreadable or disorganized code._
134135
- `if`/`else`/`for`/`while`/`try` blocks should always use braces, and always go on multiple lines.
@@ -558,7 +559,7 @@ function getKeyCode(keyCode) {
558559
## Language & Frameworks
559560

560561
- **ES Version**: ES2020+ with Babel transpilation
561-
- **Indentation**: 2 spaces (conform to WordPress standards)
562+
- **Indentation**: 2 spaces for React/JSX files (Gutenberg standard), tabs for vanilla JS (WordPress core standard)
562563
- **Quotes**: Single quotes (`'`) for strings, template literals for interpolation
563564
- **Semicolons**: Required at end of statements
564565
- **Naming**: `camelCase` for variables/functions, `PascalCase` for classes/components

.github/instructions/wpcs-php.instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ function my_plugin_rest_permission_check() {
376376
## PHP Block & Theme Setup Instructions
377377

378378
- Follow WordPress coding standards: <https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/>
379-
- Use 4 spaces for indentation, no tabs
379+
- Use tabs for indentation (WordPress PHP standard)
380380

381381
## Pattern Registration
382382

0 commit comments

Comments
 (0)