Automattic / Automattic/VIP-Coding-Standards

Make suggestion when autoload resolves to true

未关闭
#497 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
Standard: VIP-Go Type: Enhancement
主要语言
PHP
星标
261
派生
44
平均合并
19 分钟
30 天内合并 PR
1

描述

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

贡献指南

打开贡献指南

调研方向

定位处理 add_option() 和 update_option() 的 PHPCS sniff 及测试;检查省略的参数、字面量 yes/no 值和布尔值是如何分类的。完成标准是:列出的 yes/true/implied 情况会产生警告,no/false 情况不会产生警告,并且该警告可以引用所提供的 autoloading 文档。

由索引模型根据 Issue 内容生成。

评估

技术栈
php
领域
tooling
Issue 类型
功能
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
描述清楚
新手友好度
48/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。