如何配置Laravel Pint以使用两个空格替代制表符
配置Laravel Pint使用两个空格替代制表符
Laravel Pint基于PHP-CS-Fixer实现代码格式化,所有缩进相关规则必须放在pint.json的rules节点内,你之前的配置把indent_style等项放在顶级是无效的。以下是正确的配置方案:
最简有效配置
{ "preset": "laravel", "exclude": [ "bootstrap/cache", "frontend", "node_modules", "vendor", "storage" ], "rules": { "indentation_type": "space", "indentation_width": 2, "no_tab_indentation": true } }
配置说明
indentation_type: "space" —— 指定用空格替代制表符作为缩进方式indentation_width: 2 —— 设置每个缩进级别使用2个空格no_tab_indentation: true —— 强制禁止代码中出现制表符缩进
验证配置
运行Pint命令测试格式化效果:
./vendor/bin/pint
如果需要保留你原来的其他格式化规则,只需将所有规则统一放在rules节点内即可,示例如下:
{ "preset": "laravel", "exclude": [ "bootstrap/cache", "frontend", "node_modules", "vendor", "storage" ], "rules": { "array_indentation": true, "phpdoc_indent": true, "statement_indentation": true, "method_chaining_indentation": true, "whitespace_after_comma_in_array": { "ensure_single_space": true }, "indentation_type": "space", "indentation_width": 2, "no_tab_indentation": true } }
内容的提问来源于stack exchange,提问作者Vihorian
相关产品推荐
相关产品推荐

