You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 18:09:53