-
Notifications
You must be signed in to change notification settings - Fork 136
Add AGENTS.md and AI contribution guidance
#2193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b1634f2
Add AGENTS.md
westonruter f28543d
Update CONTRIBUTING.md and PULL_REQUEST_TEMPLATE.md with AI guidance
westonruter b258b3e
Fix incomplete sentence
westonruter fad453f
Improve project overview
westonruter e6e8e4a
Fix typo
westonruter 794c074
Improve inline documentation example
westonruter 6dd5c7f
Remove needless git clone step and add initial build step
westonruter 385a6be
Improve code samples
westonruter 1fa61f5
Clarify guidance for use of AI tools
westonruter d85f821
Specify that PHP 7.2 is the minimum version
westonruter 248bda7
Fix typo
westonruter 476a1cb
Remove many
westonruter 31648f9
Fix typo
westonruter d66aab0
Improve project structure docs
westonruter 688a21c
Align PULL_REQUEST_TEMPLATE AI guidance with CONTRIBUTING
westonruter File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| # Performance Lab | ||
|
|
||
| This is a monorepo for the WordPress Performance Team, containing a collection of standalone performance feature plugins. Refer to the [Performance Lab handbook](https://make.wordpress.org/performance/handbook/performance-lab/) for more details. | ||
|
|
||
| ## Project Overview | ||
|
|
||
| * **Purpose:** To develop and maintain a suite of plugins that improve the performance of WordPress sites. All should be considered | ||
westonruter marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * **Technologies:** PHP, JavaScript, CSS, a variety of testing and linting tools. | ||
| * **Architecture:** This is a monorepo containing multiple WordPress plugins. The main plugin is `performance-lab`, which acts as a hub for the other feature plugins, most of which are standalone plugins located in the `plugins` directory (although some come from other repos). Each plugin has its own tests located in its respective `tests` subdirectory. | ||
westonruter marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Building and Running | ||
|
|
||
| ### Prerequisites | ||
|
|
||
| * [Node.js and npm](https://nodejs.org/en/) | ||
| * [Docker](https://www.docker.com/) | ||
| * [Git](https://git-scm.com/) | ||
| * [Composer](https://getcomposer.org/) | ||
|
|
||
| ### Installation | ||
|
|
||
| 1. Clone the repository, e.g. `git clone https://github.com/WordPress/performance.git`. | ||
| 2. Run `npm install` to install the Node.js dependencies. | ||
| 3. Run `composer install` to install the PHP dependencies. | ||
westonruter marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### Building | ||
|
|
||
| * To build the JavaScript and CSS assets: `npm run build`` | ||
westonruter marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * To build all plugins and place into the `build` directory: `npm run build-plugins` | ||
| * To build a specific plugin: `npm run build:plugin:<plugin-slug>` (e.g., `npm run build:plugin:performance-lab`) | ||
| * To build ZIP files for distribution: `npm run build-plugins:zip` | ||
|
|
||
| ### Running a Local Environment | ||
|
|
||
| This project uses `@wordpress/env` to create a local development environment. | ||
|
|
||
| * Check if the environment is already running: `npm run wp-env status` | ||
| * Start the environment: `npm run wp-env start` | ||
| * Stop the environment: `npm run wp-env stop` | ||
|
|
||
| The environment will by default be located at `http://localhost:8888` but this can be overridden by `.wp-env.override.json`. | ||
|
|
||
| ## Code Style | ||
westonruter marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| In general, the [coding standards for WordPress](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/) should be followed: | ||
|
|
||
| * [CSS Coding Standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/css/) | ||
| * [HTML Coding Standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/html/) | ||
| * [JavaScript Coding Standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/javascript/) | ||
| * [PHP Coding Standards](https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/) | ||
|
|
||
| Note that for the JavaScript Coding Standards, the code should also be formatted using Prettier, specifically the [wp-prettier](https://www.npmjs.com/package/wp-prettier) fork with the `--paren-spacing` option which inserts many extra spaces inside parentheses. | ||
westonruter marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| For the HTML Coding Standards, disregard the guidance that void/empty tags should be self-closing, such as `IMG`, `BR`, `LINK`, or `META`. This is only relevant for XML (XHTML), not HTML. So instead of `<br />` this should only use `<br>`, for example. | ||
|
|
||
| Additionally, the [inline documentation standards for WordPress](https://developer.wordpress.org/coding-standards/inline-documentation-standards/) should be followed: | ||
|
|
||
| * [PHP Documentation Standards](https://developer.wordpress.org/coding-standards/inline-documentation-standards/php/) | ||
| * [JavaScript Documentation Standards](https://developer.wordpress.org/coding-standards/inline-documentation-standards/javascript/) | ||
|
|
||
| Note that `lint-staged` will be used to automatically run code quality checks with the tooling based on the staged files. | ||
|
|
||
| ### Indentation | ||
|
|
||
| In general, indentation should use tabs. Refer to `.editorconfig` in the project root for specifics. | ||
|
|
||
| ### Inline Documentation | ||
|
|
||
| It is expected for code introduced in pull requests to have `@since` tags with the `n.e.x.t` placeholder version. It will get replaced with the actual version at the time of release. Do not add any code review comments such code. | ||
westonruter marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
westonruter marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Every file, function, class, method constant, and global variable must have an associated docblock with a `@since` tag. | ||
|
|
||
| ### PHP | ||
|
|
||
| Whenever possible, the most specific PHP type hints should be used, when compatible with the minimum version of PHP supported by WordPress, unless the `testVersion` config in `phpcs.xml.dist` is higher. | ||
|
|
||
| When native PHP type cannot be used, PHPStan's [PHPDoc Types](https://phpstan.org/writing-php-code/phpdoc-types) should be used, including not only the basic types but also subtypes like `non-empty-string`, [integer ranges](https://phpstan.org/writing-php-code/phpdoc-types#integer-ranges), [general arrays](https://phpstan.org/writing-php-code/phpdoc-types#general-arrays), and especially [array shapes](https://phpstan.org/writing-php-code/phpdoc-types#array-shapes). The types should comply with PHPStan's level 10. | ||
|
|
||
| The one exception for using PHP types is whenever a function is used as a filter. Since plugins can supply any value at all when filtering, it is important for the filtered value to always be `mixed`. The first statement in the function in this case must always check the type, and if it is not the expected type, override it to be so. For example: | ||
|
|
||
| ```php | ||
| /** | ||
| * Filters foo. | ||
| * | ||
| * @param string|mixed $foo Foo. | ||
| * @return string Foo. | ||
| */ | ||
| function filter_foo( $foo, int $post_id ): string { | ||
| if ( ! is_string( $foo ) ) { | ||
| $foo = ''; | ||
| } | ||
| /** | ||
| * Because plugins do bad things. | ||
| * | ||
| * @var string $foo | ||
| */ | ||
|
|
||
| // Filtering logic goes here. | ||
|
|
||
| return $foo; | ||
| } | ||
| add_filter( 'foo', 'filter_foo', 10, 2 ); | ||
| ``` | ||
|
|
||
| All PHP files should have a namespace which coincides with the `@package` tag in the file's PHPDoc header. | ||
|
|
||
| ### JavaScript | ||
|
|
||
| All JavaScript code should be written with JSDoc comments. All function parameters, return values, and other types should use [TypeScript in JSDoc](https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html). | ||
|
|
||
| JavaScript code is written using ES modules. This JS code must be runnable as-is without having to go through a build step, so it must be plain JavaScript and not TypeScript. The project _may_ also distribute minified versions of these JS files. | ||
|
|
||
| Never render HTML `script` markup directly. Always use the relevant APIs in WordPress for adding scripts, including `wp_enqueue_script()`, `wp_add_inline_script()`, `wp_localize_script()`, `wp_print_script_tag()`, `wp_print_inline_script_tag()`, `wp_enqueue_script_module()` among others. Since script modules are used, new scripts should normally have a `type="module"` when printing via `wp_print_inline_script_tag()` and when an external script is used, then `wp_enqueue_script_module()` is preferred. | ||
|
|
||
| ### Static Analysis Commands | ||
|
|
||
| * **PHPStan**: `npm run phpstan` | ||
| * **TypeScript**: `npm run tsc` | ||
|
|
||
| ### Linting Commands | ||
|
|
||
| * **JavaScript:** `npm run lint-js` | ||
| * **PHP:** `npm run lint-php` | ||
|
|
||
| ### Formatting Commands | ||
|
|
||
| * **JavaScript:** `npm run format-js` | ||
| * **PHP:** `npm run format-php` | ||
|
|
||
| ### Testing Commands | ||
|
|
||
| * **End-to-end (E2E) tests:** `npm run test-e2e` | ||
| * **PHP tests:** `npm run test-php` | ||
| * **PHP tests (multisite):** `npm run test-php-multisite` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you apply https://github.com/WordPress/performance/pull/2193/files#r2389568757, it should probably be put here too :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 1fa61f5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this was a misunderstanding - the copy here is still the old one, it needs to be aligned with what's in
CONTRIBUTING.md.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Humm. I seemed to have missed making the change I imagined myself making! Now addressed in 688a21c