VS Code 使用 php cs fixer 扩展根据 psr 规范修复/格式化代码
参考
环境
软件/系统 | 版本 | 说明 |
---|---|---|
Windows | Windows 10 专业版 22H2 19045.4046 | |
php | php-8.2.5-nts-Win32-vs16-x64 | |
vs code | 1.86.2 | |
php cs fixer | v0.3.11 | vs code 扩展 |
正文
介绍
PHP Coding Standards Fixer
介绍原文:
The PHP Coding Standards Fixer (PHP CS Fixer) tool fixes your code to follow standards; whether you want to follow PHP coding standards as defined in the PSR-1, PSR-2, etc., or other community driven ones like the Symfony one. You can also define your (team's) style through configuration.
It can modernize your code (like converting the pow function to the ** operator on PHP 5.6) and (micro) optimize it.
If you are already using a linter to identify coding standards problems in your code, you know that fixing them by hand is tedious, especially on large projects. This tool does not only detect them, but also fixes them for you.
介绍翻译:
PHP Coding Standards Fixer (PHP CS Fixer) 工具可以修复你的代码,使其符合规范。你可以选择遵循 PHP 编码标准,如 PSR-1、PSR-2 等,也可以选择遵循其他社区驱动的标准,如 Symfony。你还可以通过配置定义自己(团队)的编码风格。
该工具可以使你的代码现代化(例如,在 PHP 5.6 上将 pow 函数转换为 ** 运算符),并对其进行(微)优化。
如果你已经在使用代码检查工具来识别你的代码中存在的编码规范问题,你就知道手动修复这些问题是非常繁琐的,特别是在大型项目中。这个工具不仅可以检测它们,而且还可以为你修复它们。
配置
使用插件默认配置,未修改任何配置。
使用
F1
-> php-cs-fixer: fix this file
或键盘快捷键 alt+shift+f
(VS Code 默认格式化程序快捷键)
或右键上下文菜单 Format Document
或右键上下文菜单 Format Selection
或右键上下文菜单(在资源管理器中) php-cs-fixer: fix
地 址 :https://www.cnblogs.com/xiaqiuchu/p/18016909
如果对你有帮助,可以点一下 推荐 或者 关注 吗?会让我的分享变得更有动力~
转载时请带上原文链接,谢谢。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 我与微信审核的“相爱相杀”看个人小程序副业
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
2021-02-16 Springboot2.x 统一json返回格式,并设置http响应码
2021-02-16 Springboot2.x 统一json返回结构