英文原文正文为项目原始 README(英文),本站后续会翻译为中文,当前仅剔除图片与无关章节并统一排版。
vscode 刀片格式化器
一个针对 VSCode 的有固定格式偏好的 Blade 文件格式化工具。Marketplace 页面在 这里。
你也可以使用此扩展依赖的 blade-formatter 通过相同语法以编程方式进行格式化。
功能
- 自动缩进指令内部的标记
- 自动为 Blade 模板标记添加空格
- 支持 PHP 8(空安全运算符、命名参数)🐘
- 支持 PSR-2(指令内部格式化)
- 根据
tailwind.config.js自动排序 Tailwind CSS 类
屏幕录制
扩展设置
| 设置 | 描述 | 默认值 |
|---|---|---|
Blade Formatter: format Enabled |
是否启用 | true |
Blade Formatter: format Indent Size |
缩进大小 | 4 |
Blade Formatter: format Wrap Line Length |
换行长度 | 120 |
Blade Formatter: format Wrap Attributes |
换行属性的方式。[auto\|force\|force-aligned\|force-expand-multiline\|aligned-multiple\|preserve\|preserve-aligned] |
auto |
Blade Formatter: format Wrap Attributes Min Attrs |
强制换行属性选项的 HTML 标签属性最少数量。仅当在换行属性中指定了 force-expand-multiline 时才换行第一个属性 |
2 |
Blade Formatter: format Sort Tailwind Css Classes |
自动排序 Tailwind CSS 类 | false |
Blade Formatter: format Sort HTML Attributes |
按指定顺序排序 HTML 属性。[none | alphabetical | code-guide | idiomatic | vuejs] |
none |
Blade Formatter: format Indent Inner Html |
缩进 HTML 中的 <head> 和 <body> 部分 |
false |
Blade Formatter: format use Tabs |
使用制表符作为缩进字符 | false |
Blade Formatter: format Custom Html Attributes Order |
自定义 HTML 属性的逗号分隔顺序。例如 id, data-.+, class, name 。要启用此功能,您必须将排序 HTML 属性选项指定为 custom 。您可以对属性名称使用正则表达式。 |
none |
Blade Formatter: format No Multiple Empty Lines |
将多个空行合并为一个空行。 | false |
Blade Formatter: format No PHP Syntax Check |
禁用 PHP 语法检查。启用此选项将抑制语法错误报告。 | "" |
Blade Formatter: format No Single Quote |
在 PHP 表达式中使用双引号而不是单引号。 | false |
Blade Formatter: format No Trailing Comma Php |
如果设置为 true,则 PHP 表达式不会打印结尾逗号。 | false |
Blade Formatter: format Component Prefix |
指定用逗号分隔的组件名称自定义前缀。例如 x-,livewire。这会更改应用于自定义组件的格式规则,例如保留属性中的样式。 |
x-,livewire |
Blade Formatter: format PHP Version |
一个用于语法兼容性的 PHP 版本。 | 8.4 |
Blade Formatter: Dont Show New Version Message |
如果设置为“true”,则不会再显示新版本消息。 | false |
配置文件:.bladeformatterrc.json 或 .bladeformatterrc
要为每个项目配置设置,将 .bladeformatterrc.json 或 .bladeformatterrc 放到项目根目录,vscode-blade-formatter 会将其视为设置文件。
配置文件如下所示:
{
"indentSize": 4,
"wrapAttributes": "auto",
"wrapAttributesMinAttrs": 2,
"wrapLineLength": 120,
"endWithNewLine": true,
"noMultipleEmptyLines": false,
"useTabs": false,
"sortTailwindcssClasses": true,
"sortHtmlAttributes": "none",
"noPhpSyntaxCheck": false,
"noSingleQuote": false,
"noTrailingCommaPhp": false,
"componentPrefix": ["x-", "livewire:"],
"phpVersion": "8.4"
}
忽略文件:.bladeignore
要从格式化中排除文件,请在项目根目录中创建一个 .bladeignore 文件。.bladeignore 使用 gitignore 语法
# Ignore email templates
resources/views/email/**
在文件中禁用格式化
要在文件中禁用格式,您可以使用如下格式的 Blade 注释:
{{-- blade-formatter-disable --}}
{{ $foo }}
{{ $bar }}
{{-- blade-formatter-enable --}}
要在特定行禁用格式,可以使用以下格式的注释:
{{-- blade-formatter-disable-next-line --}}
{{ $foo }}
要禁用整个文件的格式化,请在文件开头添加 {{-- blade-formatter-disable --}} 注释:
{{-- blade-formatter-disable --}}
{{ $foo }}
待办事项
- 为 HTML 格式规则添加更多选项
- 为 PHP 格式规则添加选项
- 自动化包发布流程
- 集成测试
版本说明
请参阅 CHANGELOG.md
相关项目
- blade-formatter - CLI Blade 格式化工具,该扩展依赖于此工具
- prettier-plugin-blade - Blade 的 Prettier 插件
- coc-blade - 由 @yaegassy 开发的 coc.nvim 扩展
贡献
- 分叉它
- 创建你的功能分支(
git checkout -b my-new-feature) - 提交你的更改(
git commit -am 'Add some feature') - 推送到分支(
git push origin my-new-feature) - 创建新的拉取请求
开发
$ npm install
$ cp .env.example .env # set your app insight key
$ npm run watch # watch changes
测试
$ npm install
$ cp .env.example .env # set your app insight key
$ npm run compile
$ npm run test
$ npm run test:e2e
许可证
麻省理工学院
数据和遥测
此扩展会收集使用数据并将其发送到 Azure Application Insight 以改进扩展。此扩展会遵守 telemetry.enableTelemetry 设置。
要选择退出,请将 telemetry.enableTelemetry 设置为 false。更多信息请参见 常见问题。
本站来源与版权声明
- 本文标题:vscode-blade-formatter - 一个为 VSCode 提供的有主见的 Blade 文
- 本文链接:https://www.cn121.com/edplugin/shufo-vscode-blade-formatter.html
- 原项目:shufo/vscode-blade-formatter 版权归原作者 shufo 及贡献者所有
- 收录信息:本站于 2026-11-06 收录本项目,本页所列协议与仓库指标均为收录当时的状态;该日期之后原项目的版本更新与协议变更,本页不作同步。
- 开源协议:收录时本项目采用 MIT(查看 LICENSE 原文),本站转载其原始文档(未改动文字,仅剔除图片与无关章节);使用、修改、分发请以该仓库 LICENSE 原文为准。
- 站点出处:本文首发于 OneTwoOne,收录自 GitHub 开源项目 shufo/vscode-blade-formatter。
- 内容说明:本页正文为原项目 README 原文(英文),本站后续会翻译为中文(当前尚未译出,仅将二级标题译为中文,便于按栏目定位;标题原文可在下方原仓库中查看),仅剔除了图片与赞助等无关章节、并把相对链接改为绝对地址;页首简介为机器翻译自仓库描述。
- 引用声明:商业转载、第三方聚合或 AI 检索训练引用时,请务必保留以上来源出处、本文永久链接,以及原项目的版权声明与许可信息。
- 下架通道:若原项目此后变更或收紧了许可协议、或作者/权利人认为本站的收录方式(译文、排版适配、简介翻译等)超出其授权范围,请通过 xyd3302001@163.com 发送下架通知,并附上项目地址与本页链接。本站核实后将第一时间删除本页内容,或改为不复制原文的目录性收录;署名更正等其他要求可一并提出。