Automattic / Automattic/VIP-Coding-Standards

Make suggestion when autoload resolves to true

Offen
#497 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Standard: VIP-Go Type: Enhancement
Vorherrschende Sprache
PHP
Sterne
261
Forks
44
Ø Merge
19 Min.
Gemergte PRs (30 T.)
1

Beschreibung

## 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).

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Den PHPCS-Sniff und die Tests finden, die add_option() und update_option() behandeln; untersuchen, wie ausgelassene Argumente, literale yes/no-Werte und boolesche Werte klassifiziert werden. Als erledigt gilt die Aufgabe, wenn die aufgeführten yes/true/implied-Fälle Warnungen erzeugen, die no/false-Fälle dies nicht tun und die Warnung auf die bereitgestellte Autoloading-Dokumentation verweisen kann.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
php
Bereich
tooling
Issue-Typ
Feature
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
48/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.