WordPress Core CSS 编码标准小幅更新提案:为集成 Stylelint 调整规则
Proposal: Minor updates to the WordPress Core CSS Coding Standards
Make WordPress Core 提议小幅更新 CSS 编码标准,为 Core 和 WordPress Continuous Integration pipeline 引入 Stylelint 做检查。拟将章节及区块间空行统一为 1 行,并禁止可能影响可访问性的 order 属性和 *-reverse 值;相关 pull request 已准备就绪。
本提案旨在对 WordPress CSS 编码标准进行一些细微调整,以便将 Stylelint 集成到 Core 中。请将反馈严格聚焦于这些细微调整的范围。
在 Trac 工单 #29792 中,已有人提议引入 CSS linter,用于检查语法错误并强制执行 Core 的 CSS 编码标准。当前标准的版本化版本可在 WordPress Coding Standards Docs 仓库中获取。
虽然 postcss 已能捕获语法错误,但目前尚未强制执行编码标准。如今有一项提议,引入 Stylelint 作为执行这些标准的工具。Stylelint 已在 Gutenberg 编辑器仓库中使用多年,并在科技行业得到广泛应用。它是一款灵活而强大的工具,有助于确保不会引入新的标准错误,从而提高合规性并增强未来的可维护性。
若要在 Core 和 WordPress Continuous Integration 流程中引入 Stylelint,必须先对 CSS 编码标准进行小幅更新。相关仓库中已准备好一份拉取请求,用于实施拟议的更新。
拟议的更改
有两项更改具有相关性,其余更改则属于细微调整或纯粹的视觉性修改。Stylelint 配置的其余部分与当前编码标准一致。
空行
句子 Add two blank lines between sections and one blank line between blocks in a section 改为 Add one blank line between sections and between blocks in a section。
理由:Stylelint 无法区分某个部分中位于各章节和代码块之前的空行。因此,该规则被简化,要求各处均保留一个空行。
order 属性及其反向值
在 Properties 和 Values 两节中,新增两个项目符号,要求避免使用 order 属性及 *-reverse 值。请注意,这与 Gutenberg 仓库中已在使用的规则一致。
理由:已知 order 属性及 *-reverse 值可能对无障碍访问造成危害。出于无障碍考虑,视觉顺序、阅读顺序和 DOM 顺序必须保持一致。仅在不影响阅读顺序、含义和交互的情况下,才使用 order 及其反向值。
引自 W3C CSS Display Module Level 3 和 W3C CSS Flexible Box Layout Module Level 1:
作者只能将 order 用于对内容进行空间重排,而不能用于逻辑重排。使用 order 对内容执行逻辑重排的样式表不符合规范。
作者不得使用 order 或 flex-flow/flex-direction 的 *-reverse 值来代替正确的源顺序,否则可能损害文档的无障碍访问。
细微调整和视觉性修改
为以下小写值添加了明确的例外情况:
currentColoroptimizeLegibility
通过移除句子 Things that are not yet used in core itself, such as CSS3 animations ... 中的以下部分,将该句改为 such as CSS3 animations,因为 Core 现在已使用 CSS3 动画。
完全移除了以下项目符号:
An exception is made for the wp-admin.css file in core, as it is very large and each section essentially represents a stylesheet of its own. Media queries are therefore added at the bottom of sections as applicable.
因为 wp-admin.css 不再按章节拆分。
其他更改均属于纯粹的视觉性修改,例如将较长的句子拆分为项目符号,以提高可读性。
拟定时间表
我建议将本提案保持开放征求意见一周,以收集反馈和任何疑虑。一周后,如果没有重大异议,我建议继续推进此次更新。
欢迎提供任何反馈和意见。
关于未来计划的说明
Stylelint 到位后,WordPress 将为进一步完善 Core CSS 奠定坚实的基础。如果 CSS 编码标准需要进行重大调整,可以根据 Stylelint 提供的实际数据加以考虑。这可以在未来一项范围更广的提案中处理。
感谢 @joedolson 提供审阅和反馈。
#codingstandards、#core-css、#proposal
来源:Make WordPress Core(核心开发) · https://make.wordpress.org/core/2026/10/07/proposal-minor-updates-to-the-wordpress-core-css-coding-standards/
部分链接为推广/关联链接。