Automattic / Automattic/VIP-Coding-Standards
Make suggestion when autoload resolves to true
- Dominant language
- PHP
- Stars
- 261
- Forks
- 44
- Avg merge
- 19m
- Merged PRs (30d)
- 1
Description
## What problem would the enhancement address for VIP?
Options get marked as autoload=yes when being added, unless there is an explicit setting to no.
For VIP clients, we should flag when it is yes, to remind and encourage developers to consider whether it should be autoload=no, which can help with performance.
## Describe the solution you'd like
PHPCS Warning when `'yes'` or `true` is supplied or implied when calling `add_option()` or `update_option()`.
## What code should be reported as a violation?
```
add_option( 'my_option', 'my_value', '', 'yes' );
add_option( 'my_option', 'my_value', '', true ); // Can be 'yes' string or boolean.
add_option( 'my_option', 'my_value', '' );
add_option( 'my_option', 'my_value' );
add_option( 'my_option' );
update_option( 'my_option', 'my_value', 'yes' );
update_option( 'my_option', 'my_value', true ); // Can be 'yes' string or boolean.
```
## What code should *not* be reported as a violation?
```
add_option( 'my_option', 'my_value', '', 'no' );
add_option( 'my_option', 'my_value', '', false );
update_option( 'my_option', 'my_value', 'no' );
update_option( 'my_option', 'my_value', false );
```
## Additional context
Some items may indeed be valid to be autoloaded, so it's not an Error in all cases.
This may seem like a bit of noise for some cases, but I think it counts as a good reminder. We can link the error message to [our public docs about autoloading](https://wpvip.com/documentation/vip-go/working-with-wp_options/#autoloading).
Contributor guide
Research direction
Locate the PHPCS sniff and tests that handle add_option() and update_option(); inspect how omitted arguments, literal yes/no values, and booleans are classified. Done means the listed yes/true/implied cases produce warnings, the no/false cases do not, and the warning can reference the supplied autoloading documentation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100